Killing an enemy— with style

To make something happen to the enemy when it's about to die, we could make it grow and fade out. It's a good and simple way to animate its death.

Moreover, we have to remove dead enemies from enemyVector Vector because there's no point in managing them as they should be removed from stage.

We know there is only one bullet at a time, so there can be only one enemy hit by a bullet in a single frame. This is precious information because it allows us to manage all deaths with a single class level variable, which we'll call enemyToRemove, indicating the index in enemyVector Vector of the enemy to remove. It starts at -1 which means there's no enemy to remove.

private const BULLET_SPEED:uint=5; private var spaceship:spaceship_mc; ...

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.