Graphics Programs Reference
In-Depth Information
We begin by initializing variables that will be needed by the game and can easily be
modified to suit different tastes. For example, setting winScore to 29 means that the
player must successfully shoot down 30 or more asteroids to win. The player is also
given three lives. Each time an asteroid collides with the spaceship, the player loses
a life. The player must reach the designated winScore without either running out of
lives or out of time, which is set to 30 seconds. The variable shoot is used to tell the
code whether the player has fired the lasers or not. Time is kept by making calls to the
newDate object. The beginning of game play is stored in the variable startTime .
4
5
6
7
8
9
10
11
12
13
14
// initialize game variables
var winScore:Number = 29;
var score:Number = 0;
var lives:Number = 3;
var shoot:Boolean = false;
var hit:Number = 0;
var time:Number = 30;
var newDate:Date = new Date();
var mySecond:Number = newDate.getSeconds();
var startTime:Number = mySecond;
The target is a movie clip that has the cursor for aiming the lasers. It is important that
it be on top of everything, so after storing its initial depth in tdepth , it is set to a depth
of 1000. We make sure that the target cursor is visible and hide the mouse cursor.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//set the target to be on top
var tdepth:Number = target_mc.getDepth();
target_mc.swapDepths(1000);
target_mc._visible = true;
Mouse.hide();
// record the initial laser locations
laserLx = laserL_mc._x;
laserLy = laserL_mc._y;
laserRx = laserR_mc._x;
laserRy = laserR_mc._y;
// create a new Sound Object for laser firing
shootLaser = new Sound();
shootLaser.attachSound("laser");
Search WWH ::




Custom Search