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:
functioncheckForExtraShip(){if(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/extraShipAtEach 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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access