Graphics Programs Reference
In-Depth Information
Figure 11.15 Test Drive game
Now that you have seen how the game is set up graphically, let's take a look at the
code “driving” the action.
As in the first game, we begin by initializing variables that we will need for game play.
They are similar to what we saw in the first game. In this case, we want both the dash-
board and the roof to be on top of everything else and set them to a sufficiently high
depth value.
Setting up the viewer (camera) information is straightforward with nothing new. Since
we will be using the arrow keys to do our driving, we must make provision for camera
moves in the x- and z-directions. Note that the vertical origin yo has been moved up
from the center of the Stage to be consistent with the horizon line of our imagery.
To create the objects, a movie clip with instance name object_mc was made that had
the cone in the first frame and the cactus in the second frame. The game objects were
made by duplicating this movie clip. Since we wanted a mixture of cones and cacti, we
randomly chose one of the two frames for each duplicate (line 63). The placeObj()
function distributes the objects randomly in the x-direction, a constant value in the
y-direction, and in equal increments in the z-direction. We saw this type of arrangement
Search WWH ::




Custom Search