Teaching Baskets to Update the Correct Scoreboard

In the last chapter, we defined what a basket does when a score happens, as follows:

​ Basket.prototype.score = ​function​(ball){
​  ​if​ (scoreboard.getTimeRemaining() == 0) ​return​;
​  scoreboard.addPoints(​this​.points);
​  scene.remove(ball);
​ };

The score() method knows about the ball that fell into it and the scoreboard that keeps the score. The ball is an argument to the method. The scoreboard is the one that used to be defined after the launcher (which became launcher1 and launcher2).

We can’t use that scoreboard anymore. The basket needs to know which scoreboard gets points added for the ball that just landed. But how can the basket know which 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.