HTML and CSS Reference
In-Depth Information
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:
function
function checkForExtraShip () {
iif ( Math . floor ( score / extraShipAtEach ) > extraShipsEarned ) {
playerShips ++
extraShipsEarned ++ ;
}
}
We call this function on each frame tick. The player earns an extra ship if the score/
extraShipAtEach variable (with the decimals stripped off) is greater than the number of
ships earned. In our game, we have set the extraShipAtEach value to 10000 . When the
game starts, extraShipsEarned is 0 . When the player's score is 10000 or more, score/ex-
traShipAtEach will equal 1 , which is greater than the extraShipsEarned value of 0 . An
extra ship is given to the player, and the extraShipsEarned value is increased by 1 .
Search WWH ::




Custom Search