Game Development Reference
In-Depth Information
The CustomeEventLevelScreenUpdate class allows the passing of a text String instance with the
event. The String is used in the Game class to pass the level number (or any text) back to the
Main.as class. The Main.as class updates the levelInString variable with the passed in text. We
will see this listener function shortly.
The CustomEventScoreBoardUpdate class is used to update the ScoreBoard (another class we will
discuss later in this chapter). This event passes data back to the scoreBoadUpdateListener
indicating which field on the ScoreBoard to update and what the new value will be. For example: If
we wanted to update the player's score, we would pass back the name of the score field (probably
“score”) and the value of the player's score (example, 5000).
We also create two simple event constants called GAME_OVER and NEW_LEVEL . These will not pass
any data back to the listening functions so they will be fired by passing the GAME_OVER or
NEW_LEVEL constant into the dispatchEvent function. We do not need custom classes for these
types of events.
The systemNewLevel function definition
The systemNewLevel function is associated with the STATE_SYSTEM_NEW_LEVEL state. Its purpose is
to call the game.newLevel function and allow the game to start its own internal new level
processing.
The systemNewLevel function doesn't do much inside Main . It is merely there to call the Game
classes' newLevel function. This function will be demonstrated when we get to the simple stub
game example. It is used to initialize variables and difficulty for the new level. When it is
complete, it switches the system state to STATE_SYSTEM_LEVEL_IN .
The systemLevelIn function definition
The systemLevelIn() function is associated with the STATE_SYSTEM_LEVEL_IN state. It displays a
new level message for 30 frame ticks and then moves processing on to the
STATE_SYSTEM_GAME_PLAY state.
Using systemLevelIn is by no means the only method of forcing the state machine to wait. There
are a number of third party custom classes and tools such as TweenMax that can be used for the
synchronization of clips and tweens between screens and states. We have added this simple wait
state to the state machine for it to be complete framework. The state machine is designed to be
easily updated with new states and system functions. Feel free to implement any custom or third-
party library or tools that will make your job easier.
The systemLevelIn function is used to allow the developer to display some sort of special text or
animation as a precursor to each game level. It employs the use of the STATE_SYSTEM_WAIT state.
It is set right after the levelInScreen is added to the display list. The levelInScreen is a
BasicScreen instance that does not use the OK button. Instead, it simply waits for the specified
waitTime (30 frame ticks in this example) and then fires off the WAIT_COMPLETE simple custom
event. The Main class listens for this event and calls the associated listener function. The text on
this screen is a combination of the levelInText variable we created in the variable definition
section and text passed through the CustomeEventLevelScreenUpdate event. The levelIntext
can be set in the init function override of the Main.as ( GameFrameWork.as child class). It will be
combined with the text passed from the event to create the text on the levelInScreen . We will
examine the listener function that does this shortly.
Search WWH ::




Custom Search