3D Game Programming

(C. Jardin) #1
Now that we’ve added the addBall() function definition to the game, we can
uncomment the addBall() call in the code outline. Our code outline should now
look like this:

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

//addControls();
//addGoal();
//addBackground();

//animate();
//gameStep();

Add the Game Board


We should now have a ball hovering in midair. Let’s add the game board to
give the ball something to do. Add the addBoard() function as follows (warning:
there is a lot of typing for this one).

functionaddBoard() {
varmaterial =newTHREE.MeshPhongMaterial({
color: 0x333333,
shininess: 40,
ambient: 0xffd700,
emissive: 0x111111,
specular: 0xeeeeee
});

varbeam =newPhysijs.BoxMesh(
newTHREE.CubeGeometry(50, 2, 200),
material,
0
);
beam.position.set(-37, 0, 0);
beam.receiveShadow = true;

varbeam2 =newPhysijs.BoxMesh(
newTHREE.CubeGeometry(50, 2, 200),
material
);
beam2.position.set(75, 0, 0);
beam2.receiveShadow = true;
beam.add(beam2);

varbeam3 =newPhysijs.BoxMesh(
newTHREE.CubeGeometry(200, 2, 50),
material
);

Chapter 16. Project: Tilt-a-Board • 150


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf