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 { var glow:GlowFilter=new GlowFilter(0xFF00FF,1,10,10,6,6); theEnemy.filters=new Array(glow); // don't remove listeners theEnemy.killed=true; removeChild(bullet); bullet=null; isFiring=false; }
Last but not least, we...