Game Development Reference
In-Depth Information
The state variables
The state variables are constants that the game loop state machine will use to move between
game states. We have set up the most common basic states in this sample file, but you will be
able to create as many as you need. As we progress through the chapters, more will be added as
necessary.
STATE_SYSTEM_TITLE : This state is used to display a basic title screen with an OK button
for the user to click to move on. Once the instructions are on the screen, the state will
change to the next state.
STATE_SYSTEM_WAIT_FOR_CLOSE : This one waits until the OK button is clicked for any
instance of the BasicScreen class.
STATE_SYSTEM_INSTRUCTIONS : This state is used to display basic instructions with the
same OK button as in the SYSTEM_TITLE state. It also changes to the
STATE_SYSTEM_WAIT_FOR_CLOSE state until the OK button is clicked.
STATE_SYSTEM_NEW_GAME : This state will call the game logic class and fire off its
game.newGame() function. It does not wait but moves on to the NEW_LEVEL state right
away.
STATE_SYSTEM_NEW_LEVEL : With this state, we can call the game.newLevel() function to
set up a new level for the given game.
STATE_SYSTEM_LEVEL_IN : This state is used to display some basic information, if needed,
for the beginning of a level. In this basic game, we simply display the level screen and
wait a few seconds before moving on. The wait is accomplished by changing state to the
STATE_SYSTEM_WAIT state for the specified number of frame ticks.
STATE_SYSTEM_GAME_PLAY : This one simply calls the game logic class's runGame function
repeatedly and lets the game take care of its own logic and states.
STATE_SYSTEM_GAME_OVER : The game over state displays the basic game over screen and
waits for the OK button to be clicked before moving back to the instructions screen. It
quickly changes state to the STATE_SYSTEM_WAIT_FOR_CLOSE until the OK button is clicked.
STATE_SYSTEM_WAIT : This state waits for a specified number of frames and then fires off a
simple custom event constant called WAIT_COMPLETE .
The GameFrameWork.as class file
The GameFrameWork.as will be that parent of our game's document class. Main.as (the game's
document class) for our games will extend this class and call functions to modify the framework
for each unique game. The entire code listing is provided at the end of this section. We will
explore it in detail once your have had a chance to type in the code. The location for this file in the
package structure is
/source/classes/com/efg/framework/GameFrameWork.as
The GameFrameWork.as will be the parent class to the Main.as class we will use for our games,
and it's shown in the following listing. In later chapters, we will add some functions to this file and
even create one that uses a completely different timer. The Main.as will subclass this class with
the extends syntax and override the blank stub init function we are about to create. This class
Search WWH ::




Custom Search