Game Development Reference
In-Depth Information
Updating the init, newGame, and newLevel functions
The changes to these functions for iteration 5 are all about structure and modifying the game
code so it better resembles the code in the final version integrated with the Main class and the
game framework. Please copy over these functions entirely:
private function newGame():void {
//** changed in iteration #5
setRegions();
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpListener);\
addChild(canvasBitmap);
newLevel();
//** end changed in iteration #5
}
private function init():void {
this.focusRect = true;
initTileSheetData();
newGame();
}
private function newLevel():void {
//** changed in iteration #5
enemyList = [];
player = new TileByTileBlitSprite(tileSheet, playerFrames, 0);
readBackGroundData();
readSpriteData();
drawLevelBackGround();
restartPlayer();
addChild(player);
//** end changed in iteration #5
}
One change of note is the setRegions function call in the newGame function. We will examine that
function next. It breaks up the game screen into four logical regions used for enemy AI chase
logic. You have seen the rest of the code in these functions before. We have only reordered it to
make it more compatible with the framework. We have also added a new line that resets the
enemyList array back to the default empty [] setting. We will do this at the start of each level to
ensure we have a clean, new array to store the enemy for the level.
Adding the setRegions function
We have broken up the tiles for the game level screen into the following four logical regions:
The top-left region starts at column 0, row 0 and ends at column 9, row 7.
The top-right region starts at column 10, row 0 and ends at column 19, row 7.
The bottom-left region starts at column 0, row 8 and ends at column 9, row 14.
The bottom-right region starts at column 10, row 8 and ends at column 19, row 14.
See Figure 7-4 for a closer view of the regions.
Search WWH ::




Custom Search