3D Game Programming

(C. Jardin) #1
"Click blue ramps and press S to spin. "+
"Left and right arrows to move player. "+
"Be quick!"
);
scoreboard.onTimeExpired(function() {
scoreboard.setMessage("Game Over!");
gameOver();
});

varpause = false;
functiongameOver() {
if(scoreboard.getTimeRemaining() > 0) scoreboard.setMessage('Win!');
scoreboard.stopCountdown();
scoreboard.stopTimer();
pause = true;
}

// 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.19Code: Multilevel Game


This is the final version of the game code from Chapter 19, Project: Multilevel
Game, on page 177.

<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 src="http://gamingJS.com/Mouse.js"></script>
<script src="http://gamingJS.com/Sounds.js"></script>
<script>
// Physics settings
Physijs.scripts.ammo ='http://gamingJS.com/ammo.js';
Physijs.scripts.worker ='http://gamingJS.com/physijs_worker.js';

report erratum • discuss

Code: Multilevel Game • 259


Prepared exclusively for Michael Powell

Free download pdf