Game Development Reference
In-Depth Information
This function also sends the level value as a string back to Main to be used in the levelInScreen by
dispatching an instance of the CustomEventLevelScreenUpdate class. Also notice that we set the
stage.focus=this to ensure that all key events will be captured from the game when it is in play.
Creating the restartPlayer function
The restartPlayer function just needs a few additions and changes. We are adding in the call to
only reset the player.healthPoints value if the game is new or the player has just died. That
way, on a new level, the player will not receive extra health and ammunition (you can change this
in your version of the game if you wish). We also need to get rid of the ENTER_FRAME event listener
creation. It will be replaced with the framework's timer. Be sure to copy over the entire function.
private function restartPlayer(afterDeath:Boolean=false):void {
trace("restart player");
player.visible = true;
player.currCol = playerStartCol;
player.currRow = playerStartRow;
player.x=(playerStartCol * tileWidth)+(.5*tileWidth);
player.y = (playerStartRow * tileHeight) + (.5 * tileHeight);
player.nextX = player.x;
player.nextY = player.y;
player.currentDirection = MOVE_UP;
playerStarted = true;
playerInvincible = true;
playerInvincibleCountDown = true;
playerInvincibleCount = 0;
//** added iteration 6
setCurrentRegion(player);
//** end added iteration 6
//** added in Game.as final ***
player.healthPoints = playerStartHealthpoints;
if (afterDeath) {
ammo = playerStartAmmo;
player.healthPoints = playerStartHealthpoints;
}
//** end added in Game.as final **
}
Overwriting the runGame function
These three functions are brand new and should just be copied exactly as they are in this section
and placed into the NoTanks.as file, overwriting the current runGame function.
The updateScoreBoard function simply refreshes the scoreBoard on each frame tick, while the
checkInvincible function is used to count up the time the player tank cannot be harmed when a
new level starts or a new tank starts. The effect we have in place (part of the update and render
loop) is to blink the player tank when it is invincible.
The new runGame function has now has been fully fleshed out with calls to all of the necessary
game loop functions. It also checks for the end of a level and the end of the game, and updates
the scoreBoard . It does not accept keyboard input until the playerStarted Boolean is set to true .
Search WWH ::




Custom Search