HTML and CSS Reference
In-Depth Information
Game end
We do not need to check for the end of the game on each frame tick. We only need to
check when the player loses a ship. We do this inside the gameStatePlayerDie()
function:
function gameStatePlayerDie(){
if (particles.length >0 || playerMissiles.length>0) {
fillBackground();
renderScoreBoard();
updateRocks();
updateSaucers();
updateParticles();
updateSaucerMissiles();
updatePlayerMissiles();
renderRocks();
renderSaucers();
renderParticles();
renderSaucerMissiles();
renderPlayerMissiles();
frameRateCounter.countFrames();
}else{
playerShips--;
if (playerShips<1) {
switchGameState(GAME_STATE_GAME_OVER);
}else{
resetPlayer();
switchGameState(GAME_STATE_PLAYER_START);
}
}
}
This is the state function that is called on each frame tick during the
GAME_STATE_PLAYER_DIE state. First, it checks to see that there are no longer any particles
on the screen. This ensures that the game will not end until the player ship has finished
exploding. We also check to make sure that all the player's missiles have finished their
lives. We do this so we can check for collisions between the playerMissiles , and for
rocks against saucers . This way the player might earn an extra ship before player
Ships-- is called.
Once the particles and missiles have all left the game screen, we subtract 1 from the
playerShips variable and then switch to GAME_STATE_GAME_OVER if the playerShips num-
ber is less than 1 .
Awarding the Player Extra Ships
We want to award the player extra ships at regular intervals based on her score. We do
this by setting an amount of points that the game player must achieve to earn a new
ship—this also helps us keep a count of the number of ships earned:
Search WWH ::




Custom Search