Baskets and Goals
We can launch game balls, but there’s no way to score yet. In this section, we’ll build a Basket object that will add to the score when struck by a launched ball. We’ll start with a little more code in Basket than we did with Launcher, but try to keep the steps smallish.
We’ll add the Basket prototype code below the Launcher prototype code. So add a few spaces below the closing curly brace of Launcher.prototype.launch, then add the Basket constructor.
| function Basket(size, points) { |
| this.size = size; |
| this.points = points; |
| this.height = 100/Math.log10(size); |
| |
| var r = Math.random; |
| this.color = new THREE.Color(r(), r(), r()); |
| |
| this.draw(); |
| } |
This constructor takes two arguments: the size of the ...
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.