Game Development Reference
In-Depth Information
framework class. Each of these state functions will control elements in the framework such as
instances of the BasicScreen and Game classes. We will use a switch:case statement to move
between states. Unlike the afore mentioned very simple switch/case state machine structures that
call this switch/state control structure on each frame tick, we only need to call it when we are
switching states. The switch:case we call will simply change the function reference we call on each
frame tick. The GameFrameWork.as will contain the state machine that controls overall game flow.
This will move our game system between states defined in the FrameWorkStates.as file.
Each individual game package we create will contain a Main.as (in the game's own package
structure) that will extend GameFrameWork.as . We will also create a unique Game.as child class for
each game. The Game class children that we create can also employ their own internal state
machines based on the function reference pattern when needed.
Richard (Squize) Myles of www.gamingyourway.com was one of the first to offer the idea of a
function reference state machine for ActionScript 3 on his well-respected blog.
The FrameWorkStates.as class file
This class file is a simple collection of constants that will define the states for the game
framework. They will be consumed by the GameFrameWork.as class file. The following code listing
shows the entire code for this file; you will want to create this file according to the package
structure in the previous section:
package com.efg.framework
{
/**
* ...
* @author Jeff and Steve Fulton
*
*/
public class FrameWorkStates {
public static const STATE_SYSTEM_WAIT_FOR_CLOSE:int = 0;
public static const STATE_SYSTEM_TITLE:int = 1;
public static const STATE_SYSTEM_INSTRUCTIONS:int = 2;
public static const STATE_SYSTEM_NEW_GAME:int = 3;
public static const STATE_SYSTEM_GAME_OVER:int = 4;
public static const STATE_SYSTEM_NEW_LEVEL:int = 5;
public static const STATE_SYSTEM_LEVEL_IN:int = 6;
public static const STATE_SYSTEM_GAME_PLAY:int = 7;
public static const STATE_SYSTEM_LEVEL_OUT:int = 8;
public static const STATE_SYSTEM_WAIT:int = 9;
}
}
The first thing you should notice about this class is the package name in the first line. It conforms
to the file system structure we created earlier. No matter if you are using a version of Flash, Flex
Builder, Flash Builder, Flash Develop, TextMate, or even plain old Notepad, this package name
will be the same. The package name is not depended on the code development environment but
the chosen file structure for organizing the code. Save this file in the location we created
previously.
/source/classes/com/efg/framework/FrameWorkStates.as
Search WWH ::




Custom Search