Game Development Reference
In-Depth Information
gameOverScreen.createOkButton("OK", new Point(170, 250),
40, 20,screenButtonFormat, 0x000000, 0xff0000,2);
gameOverScreen.createDisplayText("Game Over",100,new
Point(140,150),screenTextFormat);
levelInScreen = new BasicScreen(FrameWorkStates.
STATE_SYSTEM_LEVEL_IN, 400, 400, true, 0xaaff0000);
levelInText = "Level ";
levelInScreen.createDisplayText(levelInText,100,new
Point(150,150),screenTextFormat);
//Set standard wait time between levels
waitTime= 30;
//set initial game state
switchSystemState(FrameWorkStates.STATE_SYSTEM_TITLE);
//create timer and run it one time
frameRate = 30;
startTimer();
}
}
}
Class import and variable definitions for the Main class
Along with the Flash library classes we need for text and formatting, we also import in the
Point
class, so we can pass
Point
instances that contain the location values for the
BasicScreen
and
SimpleBlitButton
instances we will instantiate in the
init
function. The only variables we need
to define are the constants for the
ScoreBoard
. We have only a single element on the
ScoreBoard
for our stub game, so we only create a single constant:
public static const SCORE_BOARD_CLICKS:String = "clicked";
Notice that
Main.as
extends the
GameFramework
class. This gives it access to all of the public
methods and properties of
GameFrameWork
to use as if they were its own. We will need to override
the
init
function of
GameFrameWork.as
to instantiate customize the screens and score board for
each unique game.
Applying the constructor and init function definitions
The constructor of our
Main.as
class simply calls the init function. In Chapter 12, we will create
preloaders for both the Flash IDE and the Flex SDK. The preloaders will require us to add code to
our game that waits for the
Stage
object to be available. We do not need that code for this game,
so we simply call the
init
function.
The heart of this
Main.as
class is the init function override of the
GameFrameWork.as
file's
init
function. Here, we will modify the framework for each particular game. It is very important that you
completely understand what is going on in this function, as it will be modified and used in every
game we will create throughout this topic.