Game Development Reference
In-Depth Information
We will add more to this code later as indicated by the comments. Run the code
in the debugger. Start and stop the simulation and note the frame rate. Aside
from rounding and the occasional glitch, it should stay near six frames per
second. Change the frame rate to something very high, such as 60, and run
again. The animation should be much smoother, but note that it does not run at
60 frames per second. If you run the executable outside of the debugger, the
maximum frame rate will improve. Although the most demanding modern
games strive for 60 frames per second, numbers in the 9 to 12 range are good
enough for our purposes. The original Quake had a design goal of staying above
10 frames per second. When running the code in the debugger, six frames per
second gives the system enough time to output any debugging data that you
might need. If need be, reduce the number of vehicles to the five core vehicles
mentioned in the code and retest. In any case, do not place extreme concern on
the frame rate.
Let us switch from the ground view to a vehicle-relative view. When we do this,
we will need a ground feature to indicate how fast we are going, so we will
implement a sign at the edge of the road. Add the following code to the Road class.
'Who are we tracking?
Private refVehicle As Vehicle
'Let's have a mile marker go by.
Dim FloatingMarker As New Vehicle(2, 0, Me, 0, 0, "Floating Marker")
Now we can draw relative to the reference vehicle. We will set the reference
vehicle later, but we can change the animation timer code to its final form now.
Find the following line in the animation timer event handler:
Toy.Draw(-offset)
Change that line to read as follows:
Toy.Draw(refVehicle.X - offset)
Just below that code is a comment about the floating marker. Add the following
code below the comment.
'Move the floating marker and draw.
FloatingMarker.MoveFloatingMarker(refVehicle, FrameRate, offset)
FloatingMarker.Draw(refVehicle.X - offset)
We will update the Vehicle class to implement the code needed to move the
floating marker later. For now, we will stay with the Road.vb file.
Search Nedrilad ::




Custom Search