3D Game Programming

(C. Jardin) #1

15.1 Getting Started


We’ll do something a little different in this chapter. Instead of starting anew,
let’s make a copy of our Mars project. From the menu in the ICE Code Editor,
choose Make a Copy.

In the usual project dialog that comes up, call this project Moon Phases.


14.2 Change Mars into the Moon


The first thing we need to do is rename every instance of mars to moon. Do this
before anything else and be sure that no mars variables remain (there should
be six changes).

Once you’ve done this, you’ll still have a red planet revolving around the sun.
Naming it differently doesn’t change how it looks or behaves—we’ll need to
change our code for that.

This is an important first step. We didn’t try to change everything, just the
name of one thing in our code. Once everything is behaving as before, we’re
ready for the next step. Never try to change everything at once—you’ll almost
always end up breaking everything. The worst thing that we could have done
with our first step is make the animation disappear because we missed a mars
somewhere, which is an easy thing to find and correct. Small steps always
win.

With that, let’s change how the moon looks. Change the color property of the
moon to all white: 0xffffff. We should also make the moon a little smaller than
Earth and, while we’re at it, let’s make it less chunky. The size should be 15
and it should have 30 up-and-down chunks and 25 chunks going around.

varsurface =newTHREE.MeshPhongMaterial({ambient: 0x1a1a1a, color: 0xffffff});
varplanet =newTHREE.SphereGeometry(15, 30, 25);
varmoon =newTHREE.Mesh(planet, surface);

Chapter 14. Project: Phases of the Moon • 126


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf