Game Development Reference
In-Depth Information
public function destroy() {
_alive = false;
gotoAndStop(FRAME_DESTROY);
}
public function get speed():Number {
return _speed;
}
public function set speed(value:Number):void {
_speed = value;
}
public function get alive():Boolean {
return _alive;
}
}
Like the Projectile class, Enemy objects have a speed parameter
assigned to them on creation. They also have a Boolean value,
specifying whether they are alive or dead. Finally, they have a
destroy method, which toggles the alive value and plays a destruc-
tion animation. In the FLA file, you can see an item in the library
named Enemy that is linked to this class. It is a MovieClip with two
frames: the static flying position and the destruction animation.
Next, we
ll look at the additional methods that are now a part of
the main game class.
'
The SimpleShooterCollisions Class Additions
In the code below, the sections in bold are new to this iteration of
the game. Refer to Chapter 7 for explanations on the other
methods.
<
>
protected var _enemyList:Vector.
Enemy
;
protected var _enemySpeed:Number =
10;
protected var _enemyGenerator:Timer;
protected var _enemyFrequency:int = 2000;
public function SimpleShooterCollisions() {
addEventListener(Event.ADDED_TO_STAGE, addedToStage,
false, 0, true);
addEventListener(Event.ENTER_FRAME, frameScript, false, 0,
true);
_projectileList = new Vector. < Projectile > ();
_enemyList = new Vector. < Enemy > ();
_enemyGenerator = new Timer(_enemyFrequency);
Search Nedrilad ::




Custom Search