Jump to content
IGNORED

The Most Perfect Piece Of Videogame Code.


Blue
 Share

Recommended Posts

#include <ddraw.h>

#define B(x,y,r,p) (p&1<<(((x^(r+1&2?3:0))<<(r*2&2))+((y^(r&2?3:0))*(r&1?1:4))))

#define F(x,y,w,h,c) {RECT R={x,y,x+w,y+h};b.dwFillColor=c;_->Blt(&R,0,0,k,&b);}

char *m="TetrisBy Pouya LarjaniScore:Next:GAME OVER",z[9]; unsigned L=16

,k=16778240,Q=9,I,x=9,n,y,r,p,i,a,t,u,v,e,s[30][20],P[]={1632,75328,83488,74274,

222272,221728,206368};DDBLTFX b={100};LPDIRECTDRAW d;LPDIRECTDRAWSURFACE V,_;HDC

q;HWND W;LOGFONT l={96,48};MSG g;DDSURFACEDESC S={108,33,0,0,0,1,0,0,0,0,0,0,0,0

,0,0,0,0,0,0,0,0,0,0,0,0,{536}};HFONT f=CreateFontIndirect(&l);DDSCAPS c={4};X()

{for(i=1;i<30;i++){a=1;for(I=0;I<20&&a;a=s[i++]);if(a){for(I=i*20+19;I>=20;s[

I/20][i%20]=s[i/20-1][i--%20]);e++;return 1;}}return 0;}M(int p){return(++p<<21&

1<<23|p<<14&1<<15|p<<7&1<<7)+8355711;}K(int v){return GetAsyncKeyState(v)&32768;

}O(int x,int y,int r,int p){for(I=0;I<L;I++)if(B(I%4,I/4,r,P[p])&&(x+I%4<0||x+I%

4>19||y+I/4<0||y+I/4>29||s[y+I/4][x+I%4]))return 0;return 1;}void G(){v=r;t=x;u=

y;TranslateMessage(&g);DispatchMessage(&g);(g.message==275&&Q)?SetTimer(W,1,1050

-50*((e<100)?e/5:20),0),u++:K(38)?v=r?v-1:P[p]>>16&3:K(37)?t--:K(39)?t++:K(40)?u

++:K(27)?PostQuitMessage(0):0;if(O(t,u,v,p))x=t,y=u,r=v;else if(u-y){for(I=0;I<L

;I++)if(B(I%4,I/4,r,P[p]))s[y+I/4][x+I%4]=1<<23;y?p=n,y=0,n=rand()%7,x=9,r=0:Q=0

;while(X());}}void R(){F(0,0,640,480,1<<15);for(I=0;I<600;I++)F(I%20*L,I/20*L,L,

L,s[i/20][i%20]);for(I=0;I<L;I++){if(B(I%4,I/4,r,P[p]))F((x+I%4)*L,(y+I/4)*L,L,L

,M(p));F(336+I%4*L,400+I/4*L,L,L,B(I%4,I/4,0,P[n])?M(n):0);}_->GetDC(&q);itoa(e,

z,10);SelectObject(q,GetStockObject(13));SetTextColor(q,M(6));SetBkMode(q,0);V->

Restore();TextOut(q,336,120,m+7,L);TextOut(q,336,340,m+24,6);TextOut(q,408,340,z

,strlen(z));TextOut(q,336,380,m+31,5);TextOut(q,444,300,m+37,9-Q);SelectObject(q

,f);TextOut(q,336,20,m,6);_->ReleaseDC(q);V->Flip(0,1);}WINAPI WinMain(HINSTANCE

h,HINSTANCE,char*,int){srand(timeGetTime());WNDCLASS w={0,DefWindowProc,0,0,h,0,

0,0,0,m};RegisterClass(&w);W=CreateWindow(m,m,2432696320,0,0,640,480,0,0,h,0);p=

rand()%7;ShowCursor(0);DirectDrawCreate(0,&d,0);d->SetCooperativeLevel(W,83);d->

SetDisplayMode(640,480,32);d->CreateSurface(&S,&V,0);V->GetAttachedSurface(&c,&_

);n=rand()%7;SetTimer(W,1,0,0);while(g.message!=18)PeekMessage(&g,0,0,0,1)?G():R

();int U=0;V->Release();d->Release();DestroyWindow(W);DeleteObject(f);return U;}

(it's tetris)

Tetris in BBC basic:

0d=d:IFdVDUd:a=POINT(32*POS,31-VPOS<<5):RETURNELSEMODE9:GCOL-9:CLG:O

FF:d=9:REPEATVDU30:REPEATGOSUBFALSE:IFPOS=28VDUPOS,15,VPOS,24;11,26:IF0E

LSEIFa=0PRINT:UNTIL0ELSEUNTILVPOS=25:v=ABSRNDMOD7:i=0:VDU4895;3:REPEATm=

9-INKEY6MOD3:FORr=TRUETO1:t=rANDSGNt:IFt=rCOLOURv-15:VDUrEORm:i+=m=7AND9

-6*r:IF0ELSEFORn=0TO11:d=n/3OR2EORd:GOSUBFALSE:IF1<<(n+i)MOD12AND975AND&

C2590EC/8^vVDU2080*ABSr;:t+=a:IF0ELSENEXT,:VDU20:UNTILt*LOGm:UNTILVPOS=3

Explanation here http://www.survex.com/~olly/dsm_rheolism/explanation.html

Link to comment
Share on other sites

I like the Acorn Electron version. Can't fit the code in memory, eh? Ack, the screen will do fine, stick it in there as a fancy border.

That was pretty common on electron games though, plus dealing with a smaller view area helped compensate for the lack of hardware scrolling (that's why Repton & co. used smaller sprites on the electron and gave you a score display and stuff on the spare screen space).

Link to comment
Share on other sites

The way the Gamecube logo upon appearing whenever you turn the console on organically changes shape as you press [hold] and release the A button.

It's only a tiny thing, but I am always ridiculously impressed by it everytime. It's amazing!

And the very faint dazed effect that appears after you do a sword spin in Wind Waker, though that's probably appropiate for another thread.

Link to comment
Share on other sites

The Windwakers overworld.

Being able to jump in your boat and sail to a tiny dot on the horizon and watch it get bigger and bigger and then jump off onto it.

The Lighthouse with its light running looked amazing from distance. :)

With it's what?? How did you do that?

Link to comment
Share on other sites

That was pretty common on electron games though, plus dealing with a smaller view area helped compensate for the lack of hardware scrolling (that's why Repton & co. used smaller sprites on the electron and gave you a score display and stuff on the spare screen space).

On a similar theme, but possibly the worst bit of coding ever rather than the best, I was at studio where we had to convert a C64 fighting game to one of those later Commodore machines - the C16 or +4 (can't remember which was which) - the one which was basically a cut-down C64 with far less RAM.

Of course, the game was expected to be exactly the same as the C64 version, so the conversion was all about reducing the RAM required in one way or another.

By the end the programmer had completely run out of RAM, but still had to squeeze a bit more code in there. He noticed that the background graphics consisted of a plain blue sky with plain white clouds dotted about in them, so he decided to use the top half of the screen RAM as a place to put his remaining code. He used the attributes to set the ink / paper colours of the empty sky to both blue, so that the bytes of code wouldn't be visible, and made the empty clouds solid white for the same reason. Where the cloud edge graphics were (ie the bytes of screen RAM that contained actual graphics) he just put jumps in his code to jump past them. Absolute insanity, but it worked.

Link to comment
Share on other sites

tetris.jpg

I've never played anything so addictive since. Well, apart from WoW I suppose - and in fact that's another one for the list, flying for the first time in Wow - you realise quite how huge the world is, and fly over areas that you're probably not going to be able to go into for another six months (well, if you level as slowly as I do), and it's very pretty.

Link to comment
Share on other sites

Not exactly my most favourite, but the control configuration in SSX Blur that enables you to adjust the amount of carving controlled by either tilting the NunChuk or using the Nunchuk stick. I only found this out last night and since I moved it to 100% control stick it's so much easier.

General little bits like that are the best, when the developer has actually put some thought into it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Use of this website is subject to our Privacy Policy, Terms of Use, and Guidelines.