Game Development Reference
In-Depth Information
override public function newGame():void {
level = 0;
score = 0;
plays = 0;
}
Unlike newGame , newLevel has some very interesting code in the Color Drop game. We start
newLevel by updating level and plays so that the game can start. For level , we increment the
variable and then test it to see if it is larger than the final level we have stored in
difficultyLevelArray ( difficultyLevelArray.length-1 ). If so, we get the level values from the
last available level in the difficultyLevels array. We use a variable named tempLevel to store
the level locally, because while we want to retain the level value for the ScoreBoard , we need to
read the level data from the last available level.
Next, we add the value of startPlays from tempLevel to the plays variable. Remember, the
player gets to keep the plays left over from the last level for the current level. We then set
levelScore to 0 . levelScore is the calculation of the points the player has amassed for this level
only. We use this variable to see if the player has equaled or passed the scoreThreshold for the
current level and can advance to the next. Next, we dispatch events to report the new values for
plays , level , and threshold .
override public function newLevel():void {
level++;
var tempLevel:int = level;
if (tempLevel > (difficultyLevelArray.length-1)) {
tempLevel = difficultyLevelArray.length-1
}
currentLevel = difficultyLevelArray[tempLevel-1];
plays += currentLevel.startPlays;
levelScore = 0;
dispatchEvent(new CustomEventLevelScreenUpdate(
CustomEventLevelScreenUpdate.UPDATE_TEXT, String(level)));
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_PLAYS,String(plays)));
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_LEVEL,String(level)));
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_THRESHOLD,
String(currentLevel.scoreThreshold)));
Now, we need to initialize the blocks on the screen. We will store references to all the blocks on
the screen in a 2D array named board. First, we initialize the array. Next, we create two nested
for loops. The first for loop creates a new array for each row of blocks. The next for loop creates a
null value in each spot in each row-column combination in each array (board[r][c] = null;). We will
use these null values to determine if we need to create a Block to put in its place. We then
initialize clickedBlocksArray. As we said before, we will use this array to hold the list of blocks that
match the color of the Block the player has clicked on. Finally, we set the gameState to
GameStates.STATE_START_REPLACING, which will actually put blocks on the screen.
board = new Array();
for (var r:int = 0; r < BLOCK_ROWS; r++) {
board[r] = new Array();
for (var c:int = 0; c <BLOCK_COLS; c++) {
board[r][c] = null;
}
Search WWH ::




Custom Search