Game Development Reference
In-Depth Information
p.currentEnemyAttackCount = null;
p.currentEnemyAttackIndex = null;
p.attackSelected = null;
p.levelComplete = null;
p.gridPos = {x:40, y:60};
p.grid = [
{x:10, y:10},
{x:200, y:10},
{x:400, y:10},
{x:10, y:300},
{x:200, y:300},
{x:400, y:300},
{x:10, y:600},
{x:200, y:600},
{x:400, y:600}
]
p.bossPos = {x:35, y:60};
//game logic here
p.run = function (tickerEvent) {
if (!this.levelComplete) {
this.checkBattlePanel();
this.checkEnemyAttack(tickerEvent.time);
this.checkHeroHealth();
}
}
window.game.Game = Game;
}());
The level data is passed into the constructor function, and it will be used heavily in the game logic. The current
time of the ticker when the game was created is also passed into the game so the
lastEnemyAttack
property can be set
to the time at which the level began. This value is what determines when the enemies should start attacking the hero.
The
ENEMY_ATTACK_DURATION
is the approximate time it takes any given enemy to complete its actions during an
attack. This is used along with
lastEnemyAttack
to properly determine when to attack the hero. This will be discussed
in more detail in the “Creating the Check Level Functions” section.
The next two properties are for the two main display objects in the game container. The
enemyHolder
property is
a container that will hold all enemy instances, and
battlePanel
will be an instance of the
BattlePanel
class that will
hold all action buttons and hero stats. This class will be built and covered in the “Building the Battle Panel” section.
The
levelData
property is then declared, followed by
hero
for the
Hero
instance. The next series of properties
pertain to the enemies. The
enemies
array will hold all enemy instances. These objects will be pushed to this array
when building the enemy grid. The
lastEnemyAttack
property holds the timestamp when the last enemy attack
began, and the
enemiesAreAttacking
will be set to true during the actual enemy attacks. The last two enemy-related
values are important for handling the enemy attack sequences. Depending on the level, an enemy attack will consist
of one or more sequential enemy attacks. The current streak count is stored in
currentEnemyAttackCount
, and the
current attacking enemy, referenced by index from the
enem
ies array, is stored in
currentEnemyAttackIndex
. This
approach will become clearer during the “Attacking the Hero” section.