Graphics Programs Reference
In-Depth Information
The play of the game is carried out with an onEnterFrame handler. The target cursor is
set to have the same coordinates as the mouse. When the lasers have been fired, they
incrementally move toward the target position. When they reach the target location,
they are reset to their initial coordinates. The variable hit is set to 1 to indicate the
lasers reached their destination, and shoot is reset to false.
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
this.onEnterFrame = function()
{
// set the cursor position to the mouse location
target_mc._x = _xmouse;
target_mc._y = _ymouse;
// check if the lasers have been fired
if ( shoot )
{
// move the lasers toward the target position
laserL_mc._x += dxL; laserL_mc._y += dyL;
laserR_mc._x += dxR; laserR_mc._y += dyR;
// reset the lasers when they reach the target
if ( Math.abs(laserL_mc._x - xloc) < 2)
{
laserL_mc._x = laserLx; laserL_mc._y = laserLy;
laserR_mc._x = laserRx; laserR_mc._y = laserRy;
hit = 1;
shoot = false;
}
}
After the test for shooting, a determination is made about the amount of time elapsed.
The position of the asteroids is updated and then checked to see whether any have
been hit before displaying them.
There are three ways in which the game can end. The player can shoot down enough
asteroids, time can run out, or the player can run out of lives. When any of these
happen, the onEnterFrame handler is deleted, and some necessary cleanup occurs.
Depending on which way the game ends, the player will go either to a “win” frame or
a “lose” frame.
Search WWH ::




Custom Search