Starting a Scoreboard at Zero

The rest of the code in this chapter will go below the START CODING ON THE NEXT LINE line.

To add a scoreboard to our game, we create a new one using the new keyword. Then we tell the scoreboard to start a countdown timer, show the score, and add a help message. To do all of that, we first enter the following code after the line that introduces the not_allowed variable:

 
var​ scoreboard = ​new​ Scoreboard();
 
scoreboard.countdown(45);
 
scoreboard.score();
 
scoreboard.help(
 
'Arrow keys to move. '​ +
 
'Space bar to jump for fruit. '​ +
 
'Watch for shaking trees with fruit.'​ +
 
'Get near the tree and jump before the fruit is gone!'
 
);

These lines add a nifty-looking scoreboard to our screen, complete with ...

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.