HTML and CSS Reference
In-Depth Information
Finally, it sets the game state to
GAME_STATE_ANIMATE_ENEMY
.
GAME_STATE_ANIMATE_ENEMY
Like
GAME_STATE_ANIMATE_PLAYER
, this state moves and animates the tank to its new loc-
ation represented by its
destinationX
and
destinationY
values. It must do this for each
of the enemy tanks, so it uses the
enemyMoveCompleteCount
variable to keep count of how
many of the enemy tanks have finished their moves.
When all the enemy tanks have completed their moves, the game state is changed to the
GAME_STATE_EVALUATE_ENEMY_MOVE
state.
GAME_STATE_EVALUATE_ENEMY_MOVE
Like
GAME_STATE_EVALUATE_PLAYER_MOVE
,thisstatelooksatthelocationofeachtanktode-
termine which ones need to be destroyed.
If a tank occupies the same tile as the player, a wall, or another tank, the tank is “to be des-
troyed.” If the player and enemy tank occupy the same tile, the player is also “to be des-
troyed.” This “to be destroyed” state is set by placing
true
in the
hit
attribute of the enemy
tank or the player.
The game is then moved to the
GAME_STATE_EVALUATE_OUTCOME
state.
GAME_STATE_EVALUATE_OUTCOME
This function looks at each of the enemy tanks and the player tank to determine which have a
hit
attribute set to
true
. If any do, that tank's
dead
attribute is set to
true
, and an explosion
is created by calling
createExplode()
and passing in the object instance (player or enemy
tank). In the case of the enemy, a
dead
enemy is also removed from the enemy array.
The
GAME_STATE_ANIMATE_EXPLODE
state is called next.
GAME_STATE_ANIMATE_EXPLODE
Ifthe
explosions
arraylengthisgreaterthan
0
,thisfunctionloopsthrougheachinstanceand
animates it, using the
explodeTiles
array. Each explosion instance is removed from the
ex-
plosions
arrayafteritfinishesitsanimation.Whentheexplosionsarraylengthis
0
,thegame
moves to the
GAME_STATE_CHECK_FOR_GAME_OVER
state.
GAME_STATE_CHECK_FOR_GAME_OVER
This state first checks whether the player is dead and then checks to see whether she has won.
The player cannot win if an enemy tank makes it to the goal on the same try as the player.