Game Development Reference
In-Depth Information
Craft.SetThrusters(false, false);
if (IsKeyDown(VK_UP))
Craft.ModulateThrust(true);
if (IsKeyDown(VK_DOWN))
Craft.ModulateThrust(false);
if (IsKeyDown(VK_RIGHT))
Craft.SetThrusters(true, false);
if (IsKeyDown(VK_LEFT))
Craft.SetThrusters(false, true);
// update the simulation
Craft.UpdateBodyEuler(dt);
if(FrameCounter >= _RENDER_FRAME_COUNT)
{
// update the display
ClearBackBuffer();
DrawCraft(Craft, RGB(0,0,255));
CopyBackBufferToWindow();
FrameCounter = 0;
} else
FrameCounter++;
if(Craft.vPosition.x > _WINWIDTH) Craft.vPosition.x = 0;
if(Craft.vPosition.x < 0) Craft.vPosition.x = _WINWIDTH;
if(Craft.vPosition.y > _WINHEIGHT) Craft.vPosition.y = 0;
if(Craft.vPosition.y < 0) Craft.vPosition.y = _WINHEIGHT;
}
The local variable dt represents the small yet finite amount of time, in seconds, over
which each integration step is taken. The global define _TIMESTEP stores the time step,
which we have set to 0.001 seconds. This value is subject to tuning.
The first action UpdateSimulation takes is to reset the states of the bow thrusters to
inactive by calling the SetThrusters method as follows:
Craft.SetThrusters(false, false);
Next, the keyboard is polled using the function IsKeyDown . This is a wrapper function
we created to encapsulate the necessary Windows API calls used to check key states. If
the up arrow key is pressed, then the RigidBody2D method ModulateThrust is called,
as shown here:
Craft.ModulateThrust(true);
Search Nedrilad ::




Custom Search