Game Development Reference
You can change any of the variables shown on the main window and press the Fire
button to see the resulting flight path of the shell. A message box will appear when you
hit the target or when the shell hits the ground. The program is set up so you can
repeatedly change the variables and press Fire to see the result without erasing the
previous trial. This allows you to gauge how much you need to adjust each variable in
order to hit the target. Press the Refresh button to redraw the views when they get too
Figure 2-6 shows a few trial shots that we made before finally hitting the target.
Figure 2-6. Trial shots (profile view)
The code for this example is really quite simple. Aside from the overhead of the window,
controls, and illustrations setup, all of the action takes place when the Fire button is
pressed. In pseudocode, the Fire button's pressed event handler looks something like
FIRE BUTTON PRESSED EVENT:
Fetch and store user input values for global variables,
Vm, Alpha, Gamma, L, Yb, X, Y, Z, Length, Width, Height...
Initialize the time and status variables...
status = 0;
time = 0;
Start stepping through time for the simulation
until the target is hit, the shell hits
the ground, or the simulation times out...
while(status == 0)
// do the next time step
status = DoSimulation();