Graphics Programs Reference
In-Depth Information
96
97
98
99
// check if the object is too close to the viewer
var done:Number = numberOfObjects - 1;
// if it's the finish line, game is over
if ( thisObj.z <= -d + tooClose && thisObj.id == done )
{over = true;}
// if too close but not finish
if ( thisObj.z <= -d + tooClose && thisObj.id < done )
{
// move it back in space
placeObj(thisObj,i)
// if object has been run over
if ( Math.abs( viewer.x - thisObj.x) < 300 )
{ score++;
100
101
102
103
104
105
106
107
108
109
110
111
112
113
roof_mc.score_txt.text = score;
camdz += camspeed;
dash_mc.needle_mc._rotation = - camdz;
}
}
The game is played within an onEnterFrame handler. A call to the getTime() function
is made to update the elapsed time, as in the last game. Since the game is played with
the arrow keys, they must be checked.
If the Left Arrow key is pressed, the camera is panned in the direction of the arrow,
which moves the player right and changes the view. In addition, since we are turn-
ing, we also use a call to the parallax function to move the hills and sky in the proper
direction for additional visual feedback. Within the car, the steering wheel is turned in
the direction of turning. The Right Arrow key is handled similarly.
142
143
144
145
146
147
148
149
150
151
// check the arrow keys
if (Key.isDown(Key.LEFT))
{
camdx += 2 * camspeed; // adjust camera
parallax(hills_mc, 2);
parallax(sky_mc, 1);
if(dash_mc.wheel_mc._rotation >= -30)
{ dash_mc.wheel_mc._rotation -= 5; }
}
Search WWH ::




Custom Search