HTML and CSS Reference
In-Depth Information
Level and Game End
We need to check for game and level end so we can transition to either a new game or to the
next level.
Level end
We will check for level end on each frame tick. The function to do so will look like this:
function
function checkForEndOfLevel (){
iif ( rocks . length == 0 ) {
switchGameState ( GAME_STATE_NEW_LEVEL );
}
}
When the rocks array length is 0 , we switch the state to GAME_STATE_NEW_LEVEL .
Game end
We do not need to check for the end of the game on each frame tick. We need to check only
when the player loses a ship. We do this inside the gameStatePlayerDie() function:
function
function gameStatePlayerDie (){
iif ( particles . length > 0 || playerMissiles . length > 0 ) {
fillBackground ();
renderScoreBoard ();
updateRocks ();
updateSaucers ();
updateParticles ();
updateSaucerMissiles ();
updatePlayerMissiles ();
renderRocks ();
renderSaucers ();
renderParticles ();
renderSaucerMissiles ();
renderPlayerMissiles ();
frameRateCounter . countFrames ();
} else
else {
playerShips -- ;
iif ( playerShips < 1 ) {
switchGameState ( GAME_STATE_GAME_OVER );
} else
else {
resetPlayer ();
switchGameState ( GAME_STATE_PLAYER_START );
}
Search WWH ::




Custom Search