3D Game Programming

(C. Jardin) #1

The following will move the goal (after a 2-second delay):


functionmoveGoal() {
scene.remove(goal);
setTimeout(placeGoal, 2*1000);
}

That should do it. Now if you reach the goal on the first level, you should be
greeted not with a Win! message on the scoreboard, but with a new level that
has a single obstacle in the way. If you’re very skilled, you can win after the
second level:

19.3 Adding Finishing Touches to the Game


This is already a pretty cool game, but we’ve positioned ourselves nicely for
adding touches that can make it more unique and fun. The most obvious
thing to do is add new levels. You can try the following (and possibly add a
few of your own) after the first level and before the avatar.addEventListener():

levels.addLevel([
buildObstacle('platform', 0, 0.5 * height/2 * Math.random()),
buildObstacle('platform', 0, -0.5 * height/2 * Math.random())
]);
levels.addLevel([
buildObstacle('platform', 0, 0.5 * height/2 * Math.random()),
buildObstacle('platform', 0, -0.5 * height/2 * Math.random()),
buildObstacle('stalactite', -0.33 * width, height/2),
buildObstacle('stalactite', 0.33 * width, height/2)
]);

We can also add some of the sounds from Chapter 11, Project: Fruit Hunt, on
page 99. We can make the avatar click when it hits something that is not the

report erratum • discuss

Adding Finishing Touches to the Game • 183


Prepared exclusively for Michael Powell

Free download pdf