Game Development Reference
In-Depth Information
When the player selects an attack button, attackSelected is set to true. This will prevent an enemy from
attacking in the middle of a hero attack. The levelComplete Boolean is used to determine if game loop should
continue or stop completely to let the level finish. Finally, values are set to determine where enemies are placed on the
screen when they are created.
This covers all properties in the game. Their purposes will become much clearer as the class is written, and the
declared run method will be examined in the “Creating the Check Level Functions” section.
Initializing the Game Level
The initialize method calls a series of methods to build up the level. Listing 14-22 shows the initialize method
and the first four functions it calls.
Listing 14-22. Game.js - The Game Class Initializing Methods
p.initialize = function () {
this.Container_initialize();
this.lastEnemyAttack = this.currentEnemyAttackCount =
this.currentEnemyAttackIndex = 0;
this.enemiesAreAttacking = this.attackSelected = this.levelComplete = false;
this.setListeners();
this.createHero();
this.addBG();
this.addEnemies();
this.addBattlePanel();
}
p.setListeners = function () {
this.on(events.ENEMY_ATTACKED_COMPLETE, this.onEnemyAttackedComplete,
this);
this.on(events.ENEMY_DESTROYED, this.onEnemyDestroyed, this);
}
p.createHero = function () {
this.hero = new game.Hero();
}
p.addBG = function () {
var bg = new
createjs.Bitmap(game.assets.getAsset(game.assets.BATTLE_BG));
this.addChild(bg);
}
p.addEnemies = function () {
if (this.levelData.type == 'field') {
this.populateGrid();
}
else {
this.addBoss();
}
this.addChild(this.enemyHolder);
}
 
Search WWH ::




Custom Search