Game Development Reference
In-Depth Information
GameStates.STATE_FALL_BLOCKS_WAIT is a state set when blocks are falling on or off the screen,
which happens when the level starts, after blocks are clicked, and when the game ends. The
function continually calls checkForFallingblocks , so it can set the state to the value of
nextGameState when all the blocks have stopped falling.
case GameStates.STATE_FALL_BLOCKS_WAIT:
if (!checkForFallingBlocks()) {
gameState = nextGameState;
}
break;
GameStates.STATE_END_LEVEL is set when ColorDrop has concluded that the player's levelScore
is equal to or greater than currentLevel.scoreThreshhold . endLevel is called and then we put the
gameState into GameStates.STATE_INTIALIZING so we can wait for Main to call nextLevel .
case GameStates.STATE_END_LEVEL:
endLevel();
gameState = GameStates.STATE_INITIALIZING;
break;
GameStates.STATE_END_GAME is set when ColorDrop has concluded that plays are equal to 0 but
levelScore is not equal to or greater than currentLevel.scoreThreshold . We call endGame , which
takes care of the rest for us.
case GameStates.STATE_END_GAME:
endGame();
break;
GameStates.STATE_WAIT is a special state we have created that allows us to pause the game for a
designated number of frames before continuing. This might sound useless at first, but for certain
dramatic effects, it can be very useful. We will discuss what we use it for a bit later, but for now,
we will just talk about how it works. The framesWaited variable is set to 0 before the gameState is
set to GameStates.STATE_WAIT . Conversely, waitFrames is set to the maximum number of frames
to pause the game. Also, nextGameState is set to the value of the STATE_XXX state that will go into
effect after the GameStates.STATE_WAIT is finished. Every time that runGame gets called,
framesWaited is incremented. When it is greater than or equal to waitFrames , we set gameState to
nextGameState and then ColorDrop acts like this little waiting period never happened.
case GameStates.STATE_WAIT:
framesWaited++;
if (framesWaited >= framesToWait) {
gameState = nextGameState;
}
break;
}
Finally, outside of our switch statement, we call both render and update . If we did not do this, we
would have to make multiple calls to update and render inside of the states that needed those
functions to be called. To be more efficient, we will make some changes to update and render to
make sure they are only operating on objects that require their services.
update();
render();
}
Search WWH ::




Custom Search