Game Development Reference
In-Depth Information
The systemWait function definition
The levelInscreen is very similar to the instructionsScreen , but instead of using the
STATE_SYSTEM_WAIT_FOR_CLOSE state, it uses the STATE_SYSTEM_WAIT state. What's the difference?
The STATE_SYSTEM_WAIT state calls a function that counts for a specified number of frame ticks
before moving on to the nextSystemFunction rather than waiting for the click of the OK button.
When the systemState is switched to the STATE_SYSTEM_WAIT state, it calls the systemWait
function repeatedly (on each frame tick) until the waitCount is greater than the waitTime set in the
systemLevelIn function. When the waitCount is reached, we dispatch a WAIT_COMPLETE event that
calls the waitCompleteListener (see the next section). Currently, there is only one systemState
that uses the systemWait function, so there is only one item in the case statement. We could add
many states that use this systemWait function though, so we have it set up for later expansion.
The waitCompleteListener function definition
The waitCompleteListener function is triggered when the WAIT_COMPLETE event is fired off from
the levelInScreen . It can be used for more screens by updating the switch:case statement.
Once the waitCompleteListener fires off, it switches on the lastSystemState because the
currentSystemState is now the STATE_SYSTEM_WAIT . This allows us to share a single listener
function for all uses of the WAIT_COMPLETE event. It then switches state to the nextSystemState
when it calls switchSystemState(nextSystemState) . In this example, the nextSystemState is
systemGameplay .
The systemGameplay() function definition
The systemGameplay function is the heart of the gameTimer . It is associated with the
STATE_SYSTEM_GAME_PLAY state. The game.runGame function is called on each frame tick when
systemGamePlay is the systemFunction reference. The Game class instance ( game ) will handle all of
the game's processing within the game.runGame function.
private function systemGameplay():void {
game.runGame();
}
The custom event listener functions
The last four functions inside GameFrameWork.as are listener functions for simple and complex
custom events that are needed by the Game instance class to communicate with Main class, as
well as the levelInScreen and scoreBoard class instances. We'll briefly explain each here so you
have a complete version of all the Main.as code in one place. Their use inside those classes will
be examined later as we go through the Game , ScoreBoard , and CustomEvent classes.
The scoreBoardUpdateListener function definition for
Main.as
The scoreBoardUpdateListener receives updates from the Game class instance that are passed to
the ScoreBoard through a CustomEventScoreBoardUpdate instance.
The scoreBoardUpdateListener passes data, represented by a simple key/value pair of String
object class instances to the ScoreBoard class instance. The element variable will contain a string
Search WWH ::




Custom Search