Killing an enemy— for good

A level is completed when all enemies have been killed. When you kill an enemy, the game must continue rather than stop like it does now. We must flag enemies killed by the spaceship so they won't harm anymore, and let the game continue.

First, when we create a new enemy, let's set a new property called killed. It will be true if the enemy has been killed, so it starts with false.

private function placeEnemy(enemy_level:uint):void {
enemy=new enemy_mc();
enemy.killed=false;
...
}

Then we have to heavily recode killEnemy function. We won't remove listeners as we don't want the game to stop, but we'll set killed property to true and remove the bullet as if it had flown out of the stage.

private function killEnemy(theEnemy:enemy_mc):void ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.