Jump to content
IGNORED

The Most Perfect Piece Of Videogame Code.


Blue
 Share

Recommended Posts

There was a lovely bit of code we used in speccy games to convert an x,y coordinate to a screen address. I remember working it out on paper (I was just learning assembler\machine code) and being really chuffed that it worked and it was more or less identical to the code my mentor (Mike Webb) had written.

I know that feeling. When I was at uni, I programmed bi-linear filtering into my rasterisation engine in about 30 minutes. I'd planned out the whole program on paper beforehand, with the dependencies and what have you, and then I just decided I'd skip the pseudocode and connect together all the hooks I'd left for bilinear filtering right off the bat. I just spooled code from the back of my head. After half an hour, I compiled it and it ran first time, giving me lovely filtered textures. It was ace.

Link to comment
Share on other sites

// My fave looks like a cube when formatted properly.

// Any one work out what it does. Prize of being the best C code reviewer on RLL for the first guy. Dont google any snippets though.

#include <stdio.h>

#include <unistd.h>

#include <string.h>

#include <GL/glx.h>

#include <GL/glu.h>

#define E(x) { printf("%i\n",x); goto l; }

#define G fgetc(F)

#define H glEnable(

#define I glMaterialfv(GL_FRONT,

#define J glMatrixMode(

#define L (y

#define N NULL

#define O GL_DIFFUSE , i

#define P glCallList(u);

#define T glTexCoord2i

#define U glLightfv(GL_LIGHT0,

#define V R(); glVertex3i(c,m,n);

#define X GL_TEXTURE_2D

void Y()

{ { { { { { { { { { { { { { { {

{ { { { { { { { { { {

{ { { { { {

{ { { { { { { {

{ { { { { {

{ { { { { ; { } } } } }

} } } } } } }

} } } } } }

} } } } } }

} } } } } }

} } } } } } }

} } } } } } } } } } } } } } } }

void Q()

{ { ; { { { { { { { {

{ { { { { {

{ { { { { {

; { { } } } } } } } }

} ; } } } } } } } } }

} } } } } }

FILE* F; void Z (int* x) { G; *x=G; *x=*x<50- (*x==59); }

int u,t,l,m,n,x=0, a=0,b[]={ GLX_DOUBLEBUFFER, GLX_RGBA ,

GLX_DEPTH_SIZE,16, None},o,n,c; void R() { Z(&c); Z(&m );

Z(&n ) ; } int main( int _, char **A) { char f [bUFSIZ ] ;

GLXContext r; XVisualInfo* v ; Display *y; GLfloat g=0 ,h=

10, i[]= { 1,1, 1,1, 5,5, 100, 0, .6,.6,.6,1 } ; XEvent e ;

XSetWindowAttributes s; GLubyte j[ 1<<10] ; Window w,u; if(

! L

=XOpenDisplay ( N ) ) ) E( 1 ) ; if ( ! glXQueryExtension L,N

,N ) ) E( 2 ) ; v = glXChooseVisual L , DefaultScreen (y ),b

); s. colormap = XCreateColormap L , u = RootWindow ( y , v->

screen),v->visual, AllocNone ); if ( !(r=glXCreateContext L,v

,N , 1 ) ) ) E ( 3 ) ; strcpy (f , * A) ; strcat (f, ".c" ) ;

F = fopen ( f , "r" ) ; s . event_mask = KeyPressMask ; w =

XCreateWindow L,u, 0,0,640, 480,0,v -> depth, InputOutput , v

-> visual , CWBorderPixel | CWColormap | CWEventMask ,& s);

glXMakeCurrent L , w , r ) ; H GL_DEPTH_TEST ) ; if ( ! F )E(

4 ) ; glShadeModel ( GL_SMOOTH ) ; while ( a != 89 ) a = G ;

G; G ; glGenTextures( 1, & t ) ; while ( x< 1024 ) { G; a =G;

j[ x++ ] = 128; j[ x++ ] = 128 & - ( a<33 ); j [ x ]= j [ x-1

]; x++; j[x++] = -1;} glBindTexture(X,t); glTexParameteri (X,

GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexImage2D ( X ,0,

GL_RGBA, 16 , 16 , 0 , GL_RGBA, GL_UNSIGNED_BYTE , j ) ; J

GL_PROJECTION ) ; gluPerspective ( 60 , 1.333 , 1 , 100) ; J

GL_MODELVIEW); u=glGenLists(1); glNewList (u,GL_COMPILE); H X

); while(a!=81)a=G; G;G;for(x=0;x<6;x++){glBegin(GL_QUADS ) ;

R(); glNormal3f(c,m,n); T(1,1); V T(1,0); V T(0,0); V T(0 ,1)

; V glEnd(); } glEndList(); XMapWindow L, w) ; c=0; for(; ; )

{ if (XPending L)){ XNextEvent L, &e); if ((XLookupKeysym ( (

XKeyEvent *)&e,0))&1<<5){ h=10; i[c] =!i[c]; c++; c&=3; } else

E(0) } glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;

glLoadIdentity (); gluLookAt ( -2 ,0 ,5 ,0,0 ,0,0 ,0 ,1 ) ; H

GL_LIGHTING); H GL_LIGHT0 ); U GL_POSITION, i + 4 ); U O) ; U

GL_SPECULAR, i); glLightModelfv( GL_LIGHT_MODEL_AMBIENT,i +:(

; I GL_AMBIENT, i+8 ); I O + 8 ) ; glRotatef( g, 1, 1, 1) ; P

glTranslatef (-h,0,0); P usleep (4000); g+=.07*x; if (g > 360)

g-=360.0; h-=x / 100.0; glFlush () ; glXSwapBuffers L, w); }

l:

return 0;

}

It's so obfusticated, it's hard to tell. You're initialising a GLU window and looking at something you're creating procedurally; it's textured too and has goraud shading. Precisely what it is though, I'd have to guess, without actually running the thing.

Link to comment
Share on other sites

It's so obfusticated, it's hard to tell. You're initialising a GLU window and looking at something you're creating procedurally; it's textured too and has goraud shading. Precisely what it is though, I'd have to guess, without actually running the thing.

Sorry guys stop trying to make out what this is, as it some code I copied from the obfuscated programming awards.

The code snippets are superb and I like working out what they do from the code.

I have no idea what that one i listed above does either.

Heres a little one to wet your appetitie.

main(O){int I,Q,l=O;if(I=l*4){l=6;if(l>5)l+=Q-8?l-(Q=getchar()-2)%2:l;if(Q*=2)O+="has dirtiest IF"[(I/-Q&12)-l/Q%4];}printf("%d\n",8+O%4);}

Here are many other greats

http://www.ioccc.org/years.html#2004_anonymous

Link to comment
Share on other sites

#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)

Link to comment
Share on other sites

The sheer size of the universe in Frontier : Elite II does it for me.

the Map was huuuge :(

Yeah, but the original Elite trumped it for cramming a lot into a small space; all that trading, combat, escape pod capture, fuel-skimming - plus a set of galaxies with named planets, races, etc., etc. In what - 32K?

Fantastic stuff.

Although kudos to Frontier; it still fitted onto a single floppy disk (may have been a high-density 1.44MB one), so still pretty neat and tidy.

Link to comment
Share on other sites

I changed a uni flatmate's screensaver to say "THIS COMPUTER HAS CRASHED", went out, and came back to find him on the phone to PC World tech support.

A friend did a very similar thing, only his jape involved removing all his victim's desktop shortcuts and replacing them with a screen grab of his prior arrangement.

I think the end result was the same.

Link to comment
Share on other sites

The mention of the best things actually being bugs reminds me of Disgaea. I don't know if the move cancelling and ganging up mechanics were meant to work that way originally. It's always felt like somebody forgot to flag contributing to an attack as an action that should stop you from cancelling that character's move, and then realised that the bug made for a much more interesting play mechanic.

Link to comment
Share on other sites

The code in Micro Machines (specifically V3 on the N64) that worked out when you should blow up from being off the track for too long. Was incredibly random and added to the multiplayer carnage in incredibly funny, and slightly abusive, way.

Link to comment
Share on other sites

One of my faves is the moment you're introduced to Dog, in Half-Life 2.

I find the bit where the big lummox is just about to heave a car at you (and Alyx rushes off to him, shouting 'No dog, NO!' incredibly well done.

I also love the interaction between Alyx and Eli very touching too.

What can I say, the game's had a hold on me since 2004, and has never let go...

Link to comment
Share on other sites

Another shout here for the control mechanics and physics of Mario in Super Mario World. Absolutely sublime. Even with all the precision jumping, it never feels like it's the controls' fault if you die. David Heath's jaw-dropping run-throughs of those insane Super Mario World mod levels is a testament to this.

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.