Game Development Reference
In-Depth Information
Here is the complete code for the newLevel function:
override public function newLevel():void {
trace("new level");
percent = 0;
clicked = 0;
circles = [];
scoreTexts = [];
level++;
numCircles = level * 25;
circleGrowSpeed = .01*level;
circleMaxSize = (level < 5) ? 5-level : 1;
percentNeeded = 10 + (5 * level);
if (percentNeeded > 90) {
percentNeeded = 90;
}
maxCirclesOnscreen = 10 * level;
numCreated = 0;
percentBadCircles = (level < 25) ? level + 9 : 40;
dispatchEvent(new CustomEventScoreBoardUpdate
(CustomEventScoreBoardUpdate.UPDATE_TEXT,
Main.SCORE_BOARD_PERCENT_NEEDED, String(percentNeeded)));
dispatchEvent(new CustomEventScoreBoardUpdate
(CustomEventScoreBoardUpdate.UPDATE_TEXT,
Main.SCORE_BOARD_CLICKED,String(clicked + "/" +numCircles)));
dispatchEvent(new CustomEventLevelScreenUpdate
(CustomEventLevelScreenUpdate.UPDATE_TEXT, String(level)));
}
The newLevel function begins by resetting the variables needed for the level to begin properly.
The percent variable holds the current percentage of total blue circles clicked by the user. The
clicked variable holds the actual number of blue circles clicked by the user on the level. The
circles array holds all Circle instances (the blue and evil red ones). We increase the level
variable by one ( level++ ) and then jump into calculating the knobs values for the new level. The
calculations behind these knobs were discussed in earlier in the game design specification
portion of the chapter.
The circleMaxSize variable is used to control the game's difficulty. On the earlier levels, a Circle
object can grow to be bigger than 100 percent of its size to make the game easier to play. When
the player is on levels 1-4, we set the maximum size for the Circle objects to be 5 minus the
level. So on level 1, the maximum size is 4 (or 400 percent). This keeps the Circle on the screen
longer and makes it easier to click. When we get to the scoring though, you will see that the
quicker the player clicks on a Circle (the smaller it is), the greater the score will be for clicking
that Circle .
One interesting construct you may or may not have seen before is the ? operator (formally called
the ternary operator ). It is used in place of a simple if statement, for example:
circleMaxSize = (level < 5) ? 5-level : 1;
Search WWH ::




Custom Search