Well, here's all the code. I removed the code that was
completely irrelevent and replaced it with comments. I also added comments to explain some stuff to you guys. Here goes:
Code:
//All #include statements and - using namespace std - go here
Application Game;
CollisionManager Collision;
GraphicsManager Graphics;
//Functions
void Load();
void Update();
void Draw();
//Timing Data
volatile int SpeedCounter = 0;
void IncrementSpeedCounter();
////////////////////////////////////////////////////////////////////
Sprite Buffer;
Sprite BackGround;
///////////////////////////////////////////////////////////////////
//BOX2D DECLARATIONS
b2Vec2 body_position;
float32 body_rotation;
b2Vec2 ground_position;
float32 ground_rotation;
b2AABB worldAABB;
b2Vec2 gravity(0.0f, 10.0f);
bool doSleep = true;
b2World world(worldAABB, gravity, doSleep);
b2BoxDef groundBoxDef;
b2BodyDef groundBodyDef;
b2Body* ground;
b2BoxDef boxDef;
b2BodyDef bodyDef;
b2Body* body;
float32 timeStep = 1.0f / 60.0f;
int32 iterations = 10;
int main(void)
{
Graphics.ColorDepth(32);
//Set graphics to 1024 by 768 in a window
Graphics.GfxMode(GFX_AUTODETECT_WINDOWED,1024,768);
Game.InstallMouse();
Game.InstallKeyboard();
Game.InstallTimer();
Game.InstallJoystick();
Game.InstallSound();
//Load game components
Load();
bool DRAW = false;
while(! key[KEY_ESC])
{
while(SpeedCounter > 0)
{
Update();
SpeedCounter--;
DRAW = true;
}
if(DRAW)
{
Draw();
DRAW = false;
}
}
return 0;
}
// Some Allegro magic to deal with WinMain().
END_OF_MAIN();
void Load()
{
//Set Interupt Handler for Timing data (run logic at 240 loops per second)
install_int_ex(IncrementSpeedCounter,BPS_TO_TIMER(240));
//create the buffer and background objects
//BOX2D LOAD
worldAABB.minVertex.Set(-0.0f, -0.0f);
worldAABB.maxVertex.Set(1024.0f, 768.0f);
groundBoxDef.extents.Set(25.0f, 25.0f);
groundBoxDef.density = 0.0f;
groundBodyDef.position.Set(500.0f, 500.0f);
groundBodyDef.AddShape(&groundBoxDef);
ground = world.CreateBody(&groundBodyDef);
boxDef.extents.Set(25.0f, 25.0f);
boxDef.density = 1.0f;
boxDef.friction = 0.0f;
bodyDef.position.Set(250.0f, 26.0f);
bodyDef.AddShape(&boxDef);
body = world.CreateBody(&bodyDef);
}
void Update()
{
world.Step(timeStep, iterations);
body_position = body->GetOriginPosition();
body_rotation = body->GetRotation();
}
void Draw()
{
//draw the background to the buffer
//text output the dynamic box position and rotation here using:
//body_position
//body_rotation
//draw the worldAABB rectangle here
//draw the dynamic box here
//draw the grounded (static) box here
//draw the buffer to the screen
}