moveGoal();
levels.levelUp();
});
avatar.addEventListener('collision',function(object) {
if(object.isGoal) Sounds.guitar.play();
elseSounds.click.play();
});
functionmoveGoal() {
scene.remove(goal);
setTimeout(placeGoal, 2*1000);
}
// Animate motion in the game
functionanimate() {
if(pause)return;
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
// Run physics
functiongameStep() {
if(pause)return;
scene.simulate();
// Update physics 60 times a second so that motion is smooth
setTimeout(gameStep, 1000/60);
}
gameStep();
</script>
A1.20Code: River Rafting
This is the final version of the game code from Chapter 20, Project: River
Rafting, on page 185. It is very long. There are a few extras to play around with,
as well.
<body></body>
<script src="http://gamingJS.com/Three.js"></script>
<script src="http://gamingJS.com/physi.js"></script>
<script src="http://gamingJS.com/ChromeFixes.js"></script>
<script src="http://gamingJS.com/Scoreboard.js"></script>
<script>
// Physics settings
Physijs.scripts.ammo = 'http://gamingJS.com/ammo.js';
Physijs.scripts.worker = 'http://gamingJS.com/physijs_worker.js';
// This is where stuff in our game will happen:
report erratum • discuss
Code: River Rafting • 265
Prepared exclusively for Michael Powell