3D Game Programming

(C. Jardin) #1

❶Load the physics library.


❷Tell the physics library where it can find additional help to detect colli-
sions.

❸Set up a worker to perform all of the physics calculations.


❹Create a physics-enabled Physijs.scene.


❺Enable gravity.


❻Move the camera up a little to better see the action.


❼Tilt the camera to better see the action.


❽Use the WebGL renderer.


❾Enable shadows in the renderer for added realism.


The only differences between this opening and the one that we used in
Chapter 15, Project: The Purple Fruit Monster Game, on page 133, are the
camera rotation and the ability to cast shadows. Now that we’re ready for
physics, let’s get started with the code that goes after START CODING ON THE NEXT
LINE.

18.5 Winning the Game


We’ll need the following in our game: a ball, a game board, a goal, lights, and
a space background. As usual, we’ll also need to animate the game and we’ll
have a separate function for game logic that doesn’t need to happen as often
as animation. Type in the following code outline, including the double slashes.

//addLights();
//var ball = addBall();
//var board = addBoard();

//addControls();
//addGoal();
//addBackground();
//animate();
//gameStep();

Just as we did in Chapter 15, Project: The Purple Fruit Monster Game, on page
133 , we’ll uncomment these function calls as we define the functions.

Add Lights


Before doing anything else, let’s add some lights to the scene. Without lights,
the rest of the stuff in our game will be hard to see.

report erratum • discuss

Outline the Game • 147


Prepared exclusively for Michael Powell

Free download pdf