Game Development Reference
In-Depth Information
tunnel, you cannot turn around until you have made it to the other side of the tunnel. It
happens very fast, and the player will not notice this trick, but using it lets us detect
when the player enters and leaves the tunnel and allows for the smooth animation into
the tunnel and out on the other side.
Whether or not the player is in a tunnel, we always set the player.currRow and
player.currCol to the updated values based on the nextX and nextY attributes.
The last thing we do is to call the player.updateCurrentTile function. Recall this
function from the discussion of the BlitSprite class? If not, take a look at it again. If the
player.animationLoop Boolean is set to true , the code looks to update the currentTile
attribute if the animationDelay (three frames) has been reached. If it the tile is to be
changed, the doCopyPixels Boolean variable is set to true . If not, it remains false .
Adding the render function
The render function takes care of three very important tasks, the most important of which is
calling the renderCurrentTile function of the player object. Here is the full text of the render
function for this iteration:
private function render():void {
player.x = player.nextX;
player.y = player.nextY;
if (checkCenterTile(player)) {
if (!player.inTunnel) {
switchMovement(MOVE_STOP, player);
//setCurrentRegion(player);
}
}
player.renderCurrentTile();
}
These are the major points you need to know about the render function:
The function will eventually be called after the checkCollisions function (not
implemented yet). After collisions are checked against the nextX and nextY values, the
actual x and y values of the BlitSprite object are updated and reflected directly on the
game screen.
The next task the render function undertakes is to check to see if the player is in the
center of the current tile. This will only work for 32
32 tiles if the moveSpeed attribute of
the tile is set to 1, 2, 4, 8, 16, or 32.
If the tank character is in the center of the current tile but not in a tunnel, it is stopped. If
the character is not in the center of the current tile, it does not stop. If the player holds
down a key to move in a valid direction and the center of the tile is reached, the stop will
not be noticeable, and the player tank will continue to move on the next frame.
Search WWH ::




Custom Search