Gameplay

At this point, we’re done with the code outline and we have the basics for a solid 2D game. We have the playing area, the avatar (including controls), and a way to keep score. To make the game interesting, we still need to do a bit more work. Next, we’ll add gameplay. We’re going to roll out some fruit and challenge the player to make the avatar eat as much as possible without touching the ground.

Launching Fruit

First, to create fruit, add a function below the reset() function.

​ ​function​ makeFruit() {
​  ​var​ shape = ​new​ THREE.SphereGeometry(40, 16, 24);
​  ​var​ cover = ​new​ THREE.MeshBasicMaterial({visible: ​false​});
​  ​var​ fruit = ​new​ Physijs.SphereMesh(shape, cover);
​ ...

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.