Code: Fruit Hunt

This is the avatar code after we added it to the fruit-hunt game in Chapter 11, Project: Fruit Hunt. This code uses WebGLRenderer to make the trees a little prettier, but the CanvasRenderer should work nearly as well.

 <body></body>
 <script src=​"/three.js"​></script>
 <script src=​"/tween.js"​></script>
 <script src=​"/scoreboard.js"​></script>
 <script src=​"/sounds.js"​></script>
 <script>
 // The "scene" is where stuff in our game will happen:
 var​ scene = ​new​ THREE.Scene();
 var​ flat = {flatShading: ​true​};
 var​ light = ​new​ THREE.AmbientLight(​'white'​, 0.8);
  scene.add(light);
 
 // The "camera" is what sees the stuff:
 var​ aspectRatio = window.innerWidth / window.innerHeight;
 var​ camera ...

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.