Jump to content
IGNORED

The Most Perfect Piece Of Videogame Code.


Blue
 Share

Recommended Posts

Let's be clear. This is not "what is your favourite videogame of all time?"

It's what is the most perfect piece of videogame code you've ever seen?

Perhaps for you it's one particular level from Halo:CE, or the inventory system from Resi 4 (Ya weirdo! :().

For me, it's the skateboarding game from GBA game Wario Ware inc. As I'm sure you'll know, this is merely a little mini game within the game as a whole...a little reward for finishing the first few levels of the game proper, but what a reward!

For those who haven't played it, you control a little guy travelling left to right on a skateboard and the entire game consists of:

1. Press "A" to jump over low or high obstacles.

2. Press down on the D-pad to duck under low ceilings

3. After your score reaches 100, in addition to the above, birds flying in a wave pattern have to be jumped over or allowed to fly over, without jumping, depending on which phase of the wave they are in

4. One point for each obstacle successfully negotiated and the speed of the skateboard increases every 20 points.

And that's it! Beautiful in it's simplicity, but what makes it "perfect", apart from being great fun and insanely addictive, is that it is absolutely fair. When you crash, it is never the fault of the game, and you are stuck with the knowledge that you could have done better...so you head straight back to the start and try for a higher score.

My high score is a paltry 212, but I'm determined to beat it.

Anywhy, what is the most perfect piece of videogame code you have ever seen, and why?

Link to comment
Share on other sites

int APIENTRY WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow)

{

// Work out the exe app path

// THANK YOU VERY MUCH WIN32

// WHATEVER WAS WRONG WITH ARGV[0] YOU FUCKING IDIOTS

char *apppath = new char [256];

strcpy ( apppath, GetCommandLine () );

Not perfect. You've got redundant comments in there. :(

Link to comment
Share on other sites

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.

Ha! I've been a little bit silly in my title and question haven't I? What I mean of course, is that people say no game is perfect, but maybe they have found one aspect of a game perfect in its execution.

I like yours though. :(

Link to comment
Share on other sites

Elite on the BBC Model B. I know one of the people who play tested it and it was so carefully crafted to fit into memory that even some of the keys were chosen to minimise the number of instructions needed to get to the right part of the code. There were also apparently a couple of bugs that needed an extra instruction to fix, so they had to find somewhere else in the code they could remove an instruction so they'd still be space.

Link to comment
Share on other sites

In need of a fast copy...

switch (count % :( /* count > 0 assumed */

{

case 0: do { *to = *from++;

case 7: *to = *from++;

case 6: *to = *from++;

case 5: *to = *from++;

case 4: *to = *from++;

case 3: *to = *from++;

case 2: *to = *from++;

case 1: *to = *from++;

} while ((count -= :lol: > 0);

}

...of course if anyone I worked with implemented that I would beat them to within an inch of their life.

Seeing as its all about Halo at the moment, one of my favourite touches in a game is from the first one. The sun through the trees, a wonderful little effect.

Link to comment
Share on other sites

Some of the best "code" is probably sloppy code, or an unintentional bug.

Natch you mean best gameplay, or balancing, or core mechanics, or whatever else we choose to dance around calling these things.

Link to comment
Share on other sites

The idle animation and it's random-ish timer in Boulderdash (on the C64).

Also in Boulderdash, the way that the any tile that was empty (i.e you had "dug" through it or was just naturally empty) sparkled when you got an extra life.

Cool stuff.

I also second the sunlight-through-the-treetops shader in Halo:Combat Evolved, too.

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;

}

Link to comment
Share on other sites

Bit of DirectX stuff here:

oD3DDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE);
oD3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);

oD3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILCAPS_REPLACE);
oD3DDevice->SetRenderState(D3DRS_STENCILWRITEMASK, -1);

oD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
oD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
oD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
oD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

//Draw water into stencil buffer
oWater->transform(D3DXVECTOR3(0.0,1.0,-0.9), 18.0, 18.0, 18.0);
oWater->render();

oD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
oD3DDevice->SetRenderState(D3DRS_STENCILREF, 0x1);
oD3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL);
oD3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILCAPS_KEEP);

//Draw landscape here, as we want it to be reflected by the water
oLandscape->transform(D3DXVECTOR3(0.0,0.0,0.0));
oLandscape->render();

oD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
oD3DDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);

//Do the rest of the unrelated rendering here

Originally I wanted this to reflect the landscape in the water, but instead caused the water to become semi-transparent which looked even better. :( I still don't know what went wrong with this, but I was happy all the same...

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 +:lol:

; 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;

}

Wastes people's time?

..just joshing :(

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.