Scoreboard

We’ll want to keep score in this game so, in the code outline at the top of our code, add a call to the addScoreboard() function.

​ ​var​ ground = addGround();
​ ​var​ water = addWater();
»​var​ scoreboard = addScoreboard();

But there’s no addScoreboard() function yet, so this temporarily breaks things. To quickly get everything back, add the function after the last curly brace in the addRiver() function.

​ ​function​ addScoreboard() {
​  ​var​ scoreboard = ​new​ Scoreboard();
​  scoreboard.score(0);
​  scoreboard.timer();
​  scoreboard.help(
​  ​'left / right arrow keys to turn. '​ +
​  ​'space bar to move forward. '​ +
​  ​'R to restart.'​
​  );
​  ​return​ scoreboard; ...

Get 3D Game Programming for Kids, 2nd Edition 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.