3D Game Programming

(C. Jardin) #1
As you might guess, this template includes much of the physics-engine work
we manually added back in Chapter 15, Project: The Purple Fruit Monster
Game, on page 133.

We still need to make a couple of changes before the START CODING line. First,
we need to include two more JavaScript libraries—one for keeping score and
one for working with the mouse. Start a new line after line 4, just before the
plain <script> tag, and add the following two <script> tags:

<scriptsrc="http://gamingJS.com/Scoreboard.js"></script>
<scriptsrc="http://gamingJS.com/Mouse.js"></script>

It’s important that the Mouse.js <script> tag go after the physi.js <script> tag so
that it can add mouse functionality to physics-ready objects.

The other thing we need to do is pick a better background color to set the game’s
mood. We don’t want it to be completely dark, but something a little grayer and
darker will make the screen feel more like the inside of a cave. So, just above the
START CODING line, set the background color to the following:

document.body.style.backgroundColor ='#9999aa';

Computers Like Hexadecimal Numbers
I think we can all agree that 99 is a number. But how can aa be a
number? Because computers like binary numbers (1s and 0s), they
like to work with numbers in hexadecimal. Instead of counting to
nine and then using two digits (1 and 0) to make ten, computers
like to count all the way to fifteen before adding another digit. Since
humans only have ten single-digit numbers (0, 1, 2, 3, 4, 5, 6, 7,
8, and 9), we use letters for hexadecimal numbers, starting with a.

The digits 0 through 9 in the regular number system and hexadec-
imal are the same. The regular number 10 is a in hexadecimal,
number 11 is b in hexadecimal, and so on until we reach 15, which
is f in hexadecimal. The next number, 16, is 10 in hexadecimal.

Computer colors are often two-digit hexadecimal numbers—especially
on web pages. Two-digit hexadecimal numbers are given a special name
in computers: one byte. With two digits of hexadecimal numbers, we
can count from zero ( 00 ) to 255 (ff).

So the hexadecimal 99 tells a computer to turn on a color about 60
percent of its full brightness. The hexadecimal aa is a little
brighter—around 66 percent of its full brightness. ff would turn the
color up to its full brightness and 00 would turn it off completely.

Chapter 18. Project: Cave Puzzle • 166


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf