HTML and CSS Reference
In-Depth Information
This function moves the player to its destinationX and destinationY locations. Because
this is a turn-based game, we don't have to do any other processing while this movement is
On each iteration, the player.currentTile is incremented by 1 . This changes the tile that
is rendered to be the next tile in the playerTiles array. When destinationX and destin-
ationY are equal to the x and y values for the player, the movement and animation stop, and
the game state is changed to the GAME_STATE_EVALUATE_PLAYER_MOVE state.
Now that the player has moved to the next tile, the player.row and player.col attributes
are set to player.nextRow and player.nextCol , respectively.
Next, if the player is on a goal tile, the attribute is set to true . If the player is on
a wall tile, the player.hit is set to true .
We then loop though all the enemy objects and see whether any occupy the same tile as the
player. If they do, both the player and the enemy hit attributes are set to true .
Next, we move the game to the GAME_STATE_ENEMY_MOVE state.
This state uses the homegrown chase AI—discussed in “Simple Homegrown AI Over-
view”—to choose a direction in which to move each enemy tank. It does this by looping
through all the tanks and applying the logic to them individually.
enemy tank. It then creates an array of directions to test based on these calculations. It stores
these as string values in a directionsToTest variable.
Next, it uses the chanceRandomMovement value ( 25% ) to determine whether it will use the list
In either case, it must check all the available directions (either in the list of direction-
sToMove or in all four directions for random movement) to see which is the first that will not
move the tank off the side of the screen.
When it has the direction to move in, it sets the destinationX and destinationY values of
theenemytank,usingthesame tile size * x and tile size * y trickusedfortheplayer.
Search WWH ::

Custom Search