3D Game Programming

(C. Jardin) #1

}),


0.1,


0.01


)


);


mesh.rotation.x = -Math.PI/2;
mesh.castShadow = true;

scene.add(mesh);
mesh.setAngularFactor(newTHREE.Vector3(0, 0, 0));

varrudder =newTHREE.Mesh(
newTHREE.SphereGeometry(0.5),
newTHREE.MeshBasicMaterial({color: 0x000099})
);
rudder.position.set(3, 0, 0);
mesh.add(rudder);

returnmesh;
}

We know this code by now. We build the raft using two shapes: a torus and
a sphere. The sphere is a tiny dot that we add to the front of the raft so we
know which direction the raft is pointing.

The raft has been added to the scene at this point, but is not at the start of
the river. We’ll change that in the next part of our code.

Resetting the Game


So far in our code outline, we have three variables that hold the scoreboard, the
river, and the raft. All three have already been added to the scene, so there’s
not much left to do with them—except make each one ready for the beginning
of the game.

Starting a game is not always exactly the same as resetting a game, but in
this case it is. So let’s add another function, startGame(), to the code outline:

addSunlight(scene);
varscoreboard = addScoreboard();
varriver = addRiver(scene);
varraft = addRaft(scene);
startGame(raft, river, scoreboard);

Below addRaft(), let’s add the following:


functionstartGame(raft, river, scoreboard) {
varstart = river.river_points[100];
raft.__dirtyPosition = true;

Chapter 20. Project: River Rafting • 196


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf