Game Development Reference
In-Depth Information
In the example, it works like this:
1.
If level is greater than 5 , circleMaxSize equals 5 minus the level value.
2. Otherwise, circleMaxSize equals 1.
The numCircles variable is calculated as 25 multiplied by the current level value. On higher
levels, there will be many circles that need to be clicked. The game right now is pretty
impossible to complete once you pass the third level, but conceivably, there could be hundreds
of circles per level.
The circleGrowthSpeed is . 01*level , so on level 1 (on each frame tick), the circles grow pretty
slowly. You will see in the custom class Circle that the game circles start out at 50 percent of
their size and grow from there. So, on level 1, it takes 5 frames for a circle to grow to its original
size, and because the level 1 circleMaxSize is 4 (5 minus the level), it will have 45 frame ticks to
complete its growth and leave the screen.
The percentNeeded starts at 10. Then the value (5 multiplied by the level) is added to it. This
represents the percentage of the good (blue) circles that the player must click to move on to the
next level. This calculation could go over 100, so we check see if it is greater than 90 (to be safe),
and if it is, we set it back to 90.
The maxCirclesOnScreen variable is used to keep the game levels flowing and running a little
longer than if all the circles just appeared on the screen one after another, or all at the same time.
The percentBadCircles variable uses another ? operator. We max out at 40 percent chance of a
bad circle appearing instead of a good one on any frame where a circle needs to be created (if
circles 's length is less than maxCirclesOnScreen ).
The final thing we do is to dispatch our custom events. First, we update the ScoreBoard by
dispatching one event to update the newly calculated pecentNeeded value on the ScoreBoard and
the other to reset the clicked value. The final dispatch is one you have not seen before. It makes
use of the CuctomeEventLevelScreenUpdate.UPDATE_TEXT custom Event , which tells the
levelInScreen instance of the BasicScreen class (a child of Main ) to update its display of the
level number to the current level value. The next time the levelInScreen is shown, the new level
value will be displayed.
Calling the runGame function definition
The runGame function is repeatedly called by Main in the game loop during the
STATE_SYSTEM_GAMEPLAY state.
override public function runGame():void {
trace("run game");
update();
checkCollisions();
render();
checkforEndLevel();
checkforEndGame();
}
On each game frame tick, each of these functions will be called in order. The update function will
modify the values of the Circle and ScoreTextField instances on the game screen. The
checkCollisions function will check to see which circles have been clicked by the player. The
render function will update the display with a new scale value for all circles that have not been
clicked by the user. The checkForEndLevel and checkForEndGame will evaluate the current game
Search WWH ::




Custom Search