Game Development Reference
In-Depth Information
override public function runGame():void {
switch(gameState) {
case GameStates.STATE_INITIALIZING:
break;
The
GameStates.STATE_START_REPLACING
is set when blocks need to be put on the screen—at the
beginning of every level and after the player has clicked to remove blocks from the grid. We have
standardized this state so that it can work in both instances. The
replaceBlocks
function only
gets the blocks on the screen, but they still need to fall into place. This is what the state
GameStates.STATE_FALL_BLOCKS_WAIT
is for. We set the nextGameState variable so that it is
GameStates.STATE_WAITING_FOR_INPUT
.
GameStates.STATE_FALL_BLOCKS_WAIT
will set
gameState
to
nextGameState
when it has calculated that all the blocks have stopped falling on the screen.
case GameStates.STATE_START_REPLACING:
replaceBlocks();
nextGameState = GameStates.STATE_WAITING_FOR_INPUT;
gameState = GameStates.STATE_FALL_BLOCKS_WAIT;
break;
GameStates.STATE_WAITING_INPUT
is the general state called when the player is thinking about
what choice to make. If this was a timed game, you might update the clock here. We make a call
to
checkForEndLevel
, because this is a convenient place to do it. This call could have gone right
after the player clicked a
Block
, but we put it here because it's easier to understand the game
flow when most of the calls are in game loop.
case GameStates.STATE_WAITING_FOR_INPUT:
checkforEndLevel();
break;
GameStates.STATE_REMOVE_CLICKED_BLOCKS
has a very descriptive name. This state is set when
blocks are being removed from the screen. This state is used in conjunction with
GameStates.STATE_WAIT
(described in this section a bit later). We created this state so that we
could have a slight pause between when the player clicked a block and when the blocks are
removed from the screen. This lends each click a dramatic effect, as the player gets to see all the
connecting blocks light up before they are removed from the screen. We call
removeClickedBlock
(described in “Adding blocks to the screen” section) to get rid of the current set of clicked blocks
and then set the
gameState
to
GameStates.STATE_START_REPLACING
to put more blocks back on
the screen.
case GameStates.STATE_REMOVE_CLICKED_BLOCKS:
removeClickedBlocks();
gameState = GameStates.STATE_START_REPLACING;
break;
GameStates.STATE_FADE_BLOCKS_WAIT
is set when the entire group of blocks is clearing off the
screen by fading them out using their
alpha
property. The state keeps calling
checkForFadingBlocks
, so it can set the state to
nextGameState
when all the blocks have faded
off the screen.
case GameStates.STATE_FADE_BLOCKS_WAIT:
if (!checkForFadingBlocks()) {
gameState = nextGameState;
}
break;