Game Development Reference
In-Depth Information
if (tempExplosion.currentFrame >= tempExplosion.totalFrames{}
Here's the complete object-tracking code:
public function moveEnemies() {
var tempEnemy:MovieClip;
for (var i:int = enemies.length-1;i>=0;i--) {
tempEnemy = enemies[i];
tempEnemy.y+=tempEnemy.speed;
if (tempEnemy.y > 435) {
removeEnemy(i);
}
}
var tempMissile:MovieClip;
for (i=missiles.length-1;i>=0;i--) {
tempMissile = missiles[i];
tempMissile.y-=tempMissile.speed;
if (tempMissile.y < -35) {
removeMissile(i);
}
}
var tempExplosion:MovieClip;
for (i=explosions.length-1;i>=0;i--) {
tempExplosion = explosions[i];
if (tempExplosion.currentFrame >= tempExplosion.totalFrames) {
removeExplosion(i);
}
}
}
Firing missiles
Firing missiles is the one entirely new function of Pixel Shooter that we did not evolve from
Balloon Saw. Since the player will fire missiles with the mouse button, we need to add an
EventListener to the Game class so that it will receive mouse event messages. We do this in the
initGame() function. When the mouse is clicked, we call a function named onMouseDownEvent() .
public function initGame() {
stage.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDownEvent);
}
The onMouseDownEvent() function is where we will create missiles that are fired by the player.
The first thing we do is check to see if the gameState is STATE_PLAY_GAME. That is the only
state in which missiles can be fired. If the gameState is STATE_PLAY_GAME, we create a
missile object in much the same way we created objects and pushed them into the enemies
array, except this time, they go into the missiles array. We also play the Shoot() sound, to give
the player feedback that their button press worked and a missile will appear very soon.
public function onMouseDownEvent(e:MouseEvent) {
if (gameState == STATE_PLAY_GAME) {
var tempMissile:MovieClip = new MissileImage();
tempMissile.x = player.x + (player.width/2);
Search WWH ::




Custom Search