Game Development Reference
In-Depth Information
Figure 11-5.
The 32
32 Mine graphic blown up in design mode
Updating the game loop and internal state machine
While the game loop and internal state machine for Blaster Mines are similar to ones in previous
chapters, we have updated this one to make use of the time-based step timer. You must override
the
runGameTimeBased
function in the
Game.as
class with one specific to your game. Add this
function to the
BlasterMines.as
file:
The
runGameTimeBased
function was added to the
Game.as
base class to be used in place of the
runGame
function for games that make use of the time-based step timer.
override public function runGameTimeBased(paused:Boolean=false,timeDifference:Number=1):void {
if (!paused) {
systemFunction(timeDifference);
}
}
The heart of both the pause functionality and the time-based step timer is in this function. The
paused Boolean and the timeDifference value are both passed into the function from Main. The
current systemFunction is run and will make use of the timeDifference if necessary.
The
switchSystemState
function is used to switch between the two basic game states:
GAMEPLAY
and
PLAYEREXPLODE
.
private function switchSystemState(stateval:int):void {
lastSystemState = currentSystemState;
currentSystemState = stateval;
switch(stateval) {