A Complete Reset

The last bug is in our reset() function. We’re only resetting player #1’s scoreboard.

​ ​function​ reset() {
​  ​if​ (scoreboard.getTimeRemaining() > 0) ​return​;
» scoreboard.score(0);
» scoreboard.countdown(60);
​ 
​  ​var​ balls = allBalls();
​  ​for​ (​var​ i=0; i<balls.length; i++) {
​  scene.remove(balls[i]);
​  }
​ 
​  animate();
​  gameStep();
​ }

We want to reset the score to 0 and the countdown to 60 seconds for both players, not one. So let’s cut those two lines with Ctrl+X or ⌘+X.

Paste them below the last method for Launcher, which should be keepScore(), and above the Basket() function constructor. Then make a reset() method for Launcher by adding the highlighted ...

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.