Bonus #1: Add a Background
We can give this mini-game a space-age feel with the starry background from Chapter 13, âProject: Phases of the Moonâ. Below the win function definition and the collision event listener, add the following code:
â | âfunctionâ addBackground() { |
â | âvarâ cover = ânewâ THREE.PointsMaterial({color: â'white'â, size: 2}); |
â | âvarâ shape = ânewâ THREE.Geometry(); |
â | |
â | âvarâ distance = 500; |
â | âforâ (âvarâ i = 0; i < 2000; i++) { |
â | âvarâ ra = 2 * Math.PI * Math.random(); |
â | âvarâ dec = 2 * Math.PI * Math.random(); |
â | |
â | âvarâ point = ânewâ THREE.Vector3(); |
â | point.x = distance * Math.cos(dec) * Math.cos(ra); |
â | point.y = distance * Math.sin(dec); ... |
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.