Adding enemies

We want a battle with more and more enemies as the player progresses through levels, so we have to define a variable to tell us which level is currently being played and a variable to manage the enemy DisplayObject. Add these two class level variables:

private const BULLET_SPEED:uint=5;
private var spaceship:spaceship_mc;
private var isFiring:Boolean=false;
private var bullet:bullet_mc;
private var enemy=enemy_mc;
private var level:uint=1;

level is the current level, that starts from 1.

As the game starts, we have to place enemies on the screen according to level number. Add these lines to Main function:

public function Main() { Astro-PANIC!enemies, addingplaceSpaceship(); for (var i:uint=1; i<level+3; i++) { placeEnemy(i); } addEventListener(Event.ENTER_FRAME,onEnterFrm); ...

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.