HTML and CSS Reference
In-Depth Information
tempEnemy.col = randCol;
tempEnemy.nextRow = 0;
tempEnemy.nextCol = 0;
tempEnemy.currentTile = 0;
tempEnemy.rotation = 0;
tempEnemy.x = tempEnemy.col*32;
tempEnemy.y = tempEnemy.row*32;
tempEnemy.speed = 2;
tempEnemy.destinationX = 0;
tempEnemy.destinationY = 0;
tempEnemy.dx = 0;
tempEnemy.dy = 0;
tempEnemy.hit = false;
tempEnemy.dead = false;
tempEnemy.moveComplete = false;
enemy.push(tempEnemy);
items[randRow][randCol] = 1;
There are a couple extra things worth pointing out in this code. The first is that each
enemy object needs an attribute called moveComplete . This is used in the animate
Enemy() game state function. When the entire enemy battalion has moved to its new
location, the game will transition to the next game state. This is discussed in detail in
the next section “Turn-Based Game Flow and the State Machine” .
Also, notice that the new enemy objects are added to the enemy array, as well as to the
items multidimensional array. This ensures that the player and the goal cannot be
placed on to an enemy location. Once the enemy moves from its initial location, the
playField array will still have a road tile to show in its place. We call the player and the
enemy “moving object” tiles because they can move about the game board. When they
move, they must “uncover” the road tile in the spot they were in before moving.
Now let's take a quick look at the goal tile to solidify your understanding of the dif-
ference between the playField and the moving object tiles.
The Goal
The tile id of the goal tile will be stored in the playField array along with the road and
wall tiles. It is not considered a separate item because, unlike the player and enemy
objects, it does not need to move. As we have described previously, since the enemy
and player tiles move on top of the playfield, they are considered moving items and not
part of the playfield.
The Explosions
The explosion tiles are unique. They will be rendered on top of the playfield when an
enemy tank or the player's hit attribute has been set to true . The explosion tiles will
animate through a list of five tiles and then be removed from the game screen. Again,
tiles for the explosion are set in the explodeTiles array:
var explodeTiles = [17,18,19,18,17];
Search WWH ::




Custom Search