Game Development Reference
In-Depth Information
protected var _enemyCreator:Timer;
protected var _enemyList:Dictionary;
The class starts out with some static variables; think of these as
game settings. We use variables instead of constants because we
might want to be able to change these values gradually at runtime.
ll probably recognize the first three as components of the
Tunnel class, which the Game will have to create. The next two
relate to the creation of enemies. The enemyFrequency is the rate
in seconds at which enemies are created, and the enemyTime is
the amount of time (also in seconds) it takes for an enemy to
move from the bottom of the tunnel to the top. We also declare
some protected variables we will use later on, such as references to
the Tunnel, Player, and list of enemies. You
ll notice we also dupli-
cate two of the static variables as protected instance variables. This
protects these values from changing in the middle of the game by
an outside source. These values will be assigned in the constructor
and then are only adjustable from inside the class. We
ll look at the
constructor next.
public function Game(){
_tunnel = new Tunnel(tunnelSize, tunnelDepth,
_player = new Player();
_angleIncrement = 2 * Math.PI / tunnelSides;
_enemyFrequency = enemyFrequency;
_enemyTime = enemyTime;
_enemyCreator = new Timer(_enemyFrequency*1000);
addEnemy, false, 0, true);
_enemyList = new Dictionary(true);
The constructor sets up a new Tunnel object, a Player object,
and the Timer that will release new enemies using the addEnemy
method. Now we
ll look at the methods that start the game and
control player movement.
public function startGame():void {
addEventListener(Event.ENTER_FRAME, frameScript, false,
0, true);
protected function frameScript(e:Event):void {
Search Nedrilad ::

Custom Search