Benny,
I hacked around your code a little. I have to say the game logic is well cool. So is the idea of controlling both bats. Anyway, I got it down to 928 bytes by hook and crook. Note the /QIfist flag to avoid writing your own fabs. Got rid of translates. Got rid of quit variable and test in loop. Re-arranged some tests to reduce the ifs. Used glRect instead of quads. Used a static pfd instead of two lines of code (yes that thing is smaller!).
I think there is still mileage in the game logic to go, but my brain hurts :-)
// New crinkler optimised OpenGL 1k framework.
// /CRINKLER /COMPMODE:SLOW /HASHSIZE:200 /HASHTRIES:50 /ORDERTRIES:6000
// must use /QIfist in Project->Properties->c/C++->command line for "abs" function
// this version is 928 bytes with crinkler 1.0a (haven't tried 1.1 yet).
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#define NULLNULL 0.0000000000f
#define NULLNULLONETRHEE 0.0130000000f
#define NULLNINE 0.8984375000f
#define NULLTWO 0.2001953125f
#define NULLNULLFIVE 0.0500488281f
#define NULLEIGHTSIX 0.8593750000f
#define NULLNULLEIGHT 0.0800781250f
#define NULLFIVE 0.5000000000f
static GLfloat batY, ballX, ballY;
static PIXELFORMATDESCRIPTOR pfd={
0, // Size Of This Pixel Format Descriptor... BAD coding, nothing new, saves 6 bytes
1, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, 32, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0
};
static void drawRect(float x, float y, float s) {
glLoadIdentity();
glRectf(x, y, x+NULLNULLFIVE, y+s);
}
void WINAPI WinMainCRTStartup()
{
DWORD cur;
GLfloat veloX, veloY, check, check2;
veloX=veloY=NULLNULLONETRHEE;
HDC hDC = GetDC( CreateWindow("edit", 0, WS_POPUP|WS_VISIBLE|WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, 0) );
SetPixelFormat ( hDC, ChoosePixelFormat ( hDC, &pfd) , &pfd );
wglMakeCurrent ( hDC, wglCreateContext(hDC) );
ShowCursor(FALSE);
DWORD start = GetTickCount();
for (;;)
{
cur = GetTickCount();
if ( (cur - start ) < 10 ) continue;
start = cur;
ballX+=veloX;
ballY+=veloY;
if ( ballY > NULLNINE || ballY < -NULLNINE ) veloY = -veloY;
check = abs(batY - ballY);
check2= abs(-batY - ballY);
if ( ballX > NULLEIGHTSIX) if (check<NULLTWO) veloX = -(0.005f + (check/5)); else break;
if ( ballX < -NULLEIGHTSIX) if (check2<NULLTWO) veloX = 0.005f + (check2/5); else break;
if ( GetAsyncKeyState(VK_RIGHT) && batY < NULLNINE ) batY += NULLNULLFIVE;
if ( GetAsyncKeyState(VK_LEFT) && batY > -NULLNINE) batY -= NULLNULLFIVE;
glClear( GL_COLOR_BUFFER_BIT );
drawRect( NULLNINE, -NULLNULLEIGHT + batY, NULLTWO );
drawRect( -NULLNINE, -NULLNULLEIGHT - batY, NULLTWO );
drawRect( ballX, ballY, NULLNULLFIVE );
SwapBuffers(hDC);
}
ExitProcess(0);
}
Taj.