Game Development Reference
In-Depth Information
dispatchEvent(new CustomEventScoreBoardUpdate(CustomEventScoreBoardUpdate.
UPDATE_TEXT,Main.SCORE_BOARD_AMMO,"0"));
dispatchEvent(new CustomEventScoreBoardUpdate(CustomEventScoreBoardUpdate.
UPDATE_TEXT,Main.SCORE_BOARD_TANKS,"0"));
dispatchEvent(new CustomEventScoreBoardUpdate(CustomEventScoreBoardUpdate.
UPDATE_TEXT,Main.SCORE_BOARD_HEALTH,"0"));
}
Creating the newLevel function
The newLevel function must make sure to reset all values for a new level. It also must make sure
that if we are starting a new game ( level==0 ) that we call restartPlayer with the right value
( true ) to ensure the player starts with the same ammo and healthPoints that a new tank would.
We have added and changed quite a few lines, so it is best to rewrite the entire function just to be
sure you have all of the new code.
override public function newLevel():void {
stage.focus = this;
var newGameStart:Boolean;
//if new game then reset ammo and health
if (level == 0) {
newGameStart = true;
}else {
newGameStart = false;
}
if (level==levels.length-1) level = 0;
level++;
player = new TileByTileBlitSprite(tileSheet, playerFrames, 0);
player.missileTime = 0;
player.missileDelay = 2;
enemyList = [];
playerMissileList = [];
explosionList = [];
enemyMissileList = [];
ammoPickupList = [];
lifePickupList = [];
goalReached = false;
readBackGroundData();
readSpriteData();
drawLevelBackGround();
goalReached = false;
dispatchEvent(new CustomEventLevelScreenUpdate(CustomEventLevelScreenUpdate.
UPDATE_TEXT, String(level)));
restartPlayer(newGameStart);
addChild(player);
}
Search WWH ::




Custom Search