Game Development Reference
In-Depth Information
If the down arrow key is pressed, then ModulateThrust is called, passing false instead
of true .
ModulateThrust looks like this:
void RigidBody2D::ModulateThrust(bool up)
double dT = up ? _DTHRUST:-_DTHRUST;
ThrustForce += dT;
if(ThrustForce > _MAXTHRUST) ThrustForce = _MAXTHRUST;
if(ThrustForce < _MINTHRUST) ThrustForce = _MINTHRUST;
All it does is increment the propeller thrust force by a small amount, either increasing
it or decreasing it, depending on the value of the up parameter.
Getting back to UpdateSimulation , we make a couple more calls to IsKeyDown , checking
the states of the left and right arrow keys. If the left arrow key is down, then the Rigid
Body2D method SetThrusters is called, passing false as the first parameter and true
as the second parameter. If the right arrow key is down, these parameter values are
reversed. SetThrusters looks like this:
void RigidBody2D::SetThrusters(bool p, bool s)
PThrust.x = 0;
PThrust.y = 0;
SThrust.x = 0;
SThrust.y = 0;
It resets the port and starboard bow thruster thrust vectors and then sets them according
to the parameters passed in SetThrusters . If p is true , then a right turn is desired and
a port thrust force, PThrust , is created, pointing toward the starboard side. This seems
opposite of what you'd expect, but it is the port bow thruster that is fired, pushing the
bow of the hovercraft toward the right (starboard) side. Similarly, if s is true , a thrust
force is created that will push the bow of the hovercraft to the left (port) side.
Now with the thrust forces managed, UpdateSimulation makes the call:
UpdateBodyEuler integrates the equations of motion as discussed earlier.
The next segment of code checks the value of the frame counter. If the frame counter
has reached the defined number of frames (stored in _RENDER_FRAME_COUNT ), then the
Search Nedrilad ::

Custom Search