Graphics Programs Reference
In-Depth Information
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
getTime(); // update the amount of time elapsed
// loop over the objects
for (var i:Number=0; i<numObjects; i++)
{
thisObj = _root["object"+i];
// update the current position of each object
thisObj.x += thisObj.dx;
thisObj.y += thisObj.dy;
thisObj.z += thisObj.dz;
hitCheck(); // check if the object has been hit
displayObj(); // display the object
}
// check for game over
if ( score > winScore || time == 0 || lives < 1 )
{
delete this.onEnterFrame;
cleanUp(); // get rid of stuff
if ( score > winScore ) { gotoAndStop("win"); }
if ( time == 0 ) { gotoAndStop("lose"); }
if ( lives < 1 ) { gotoAndStop("lose"); }
}
}
The getTime() function extracts the current seconds using the Date() object. A test is
made to see whether the second hand has passed 12 and a new minute has begun. If
so, an adjustment to startTime is made, and then the elapsed time and time remain-
ing are calculated.
The hitCheck() function checks to see whether an asteroid has been hit. To pass the
test, an asteroid must be hit by both lasers. When hit, the asteroid plays its explosion
sequence, and the score is incremented by 1. The asteroid goes to the placeObj()
function, where it is placed back in deep space. A break command breaks out of the
for loop.
Search WWH ::




Custom Search