3D Game Programming

(C. Jardin) #1
functionaddScoreboard() {
varscoreboard =newScoreboard();
scoreboard.score(0);
scoreboard.timer();
scoreboard.help(
'left / right arrow keys to turn. '+
'space bar to move forward.'
);

returnscoreboard;
}

We’ve seen this Scoreboard code before. We construct a new scoreboard object
with a timer, include some help text, and start the score at zero.

We should keep our code outline in mind as we do this. We now have an
outline with addSunlight() followed by addScoreboard(). Below the code outline, we
added the addSunlight() function, followed by the addScoreboard() function. We’ll
keep adding to the outline and the function definitions like this so things stay
easy to find.

With these two functions out of the way, we’re ready to jump into some seri-
ously cool 3D-programming coding next.

20.3 Warping Shapes to Make Unique Things


So far in this book we’ve managed to build interesting games by combining
basic shapes. Often that’s enough to make unique and challenging games.
But sometimes we need to push 3D programming just a bit further to build
truly interesting shapes and landscapes. We’ll do that for the river in this
game.

We’ll build our river out of just two pieces: land and water. Our land will be
a flat plane. Our water will also be a flat plane that lies just a little bit beneath
land. To make the river, we’ll pull pieces of land below the water. This is a
very powerful technique in 3D animation made even more powerful thanks
to the laws of physics. Let’s get started.

Add the addRiver() function to the bottom of our code outline so that the outline
now looks like this:

addSunlight(scene);
varscoreboard = addScoreboard();
varriver = addRiver(scene);

Inside the addRiver() function (that we’re coding below the addScoreboard() func-
tion), we’ll add another code outline. This code outline will describe how to
build the river:

report erratum • discuss

Warping Shapes to Make Unique Things • 189


Prepared exclusively for Michael Powell

Free download pdf