Killing an enemy

Knowing the bullet has a perfect circular shape, there's nothing easier at this time than letting the spaceship kill an enemy. We have to check if the distance between the bullet (if any) and the enemy is less than the sum of their radius, just as we made it with the spaceship.

At the end of manageEnemy function, add these lines:

private function manageEnemy(c:enemy_mc,index:int,v:Vector.<enemy_mc>):void {
...
if (isFiring) {
if (distance(bullet,currentEnemy)<841) {
killEnemy(currentEnemy);
}
}
}

First we check if there's a bullet flying around the game just looking at isFiring value. If it's true, then we see if the distance between the current spaceship and the bullet is less than 841, which is 25 (enemy radius) + 4 (bullet ...

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.