Giving Trees a Little Wiggle
The goal of this game will be to find fruit in the trees. The fruit will be our game’s treasure. At any given time, only one tree will have treasure. To show which tree it is, we’ll give it a little shake. But first we need a list of trees.
In Chapter 10, Project: Collisions, we added a list of notAllowed boundaries above the makeTreeAt() function. Now, we add a list of treeTops in the same place.
| var notAllowed = []; |
» | var treeTops = []; |
Next, inside the body of the makeTreeAt() function, let’s push treetops onto this treeTops list.
| notAllowed.push(boundary); |
» | treeTops.push(top); |
Now that we have a list of treetops, we can hide treasure in one and shake it. After the four calls to the makeTreeAt function, ...
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.