3D Game Programming

(C. Jardin) #1
If you click and drag the ramps with your mouse, you’ll see that you can move
them all over the game area. If you click and press the S key, you can make
them spin. It’s even possible to win the game:

We have a game with some fairly sophisticated elements. The one thing
lacking is the end. So let’s finish the chapter by creating the gameOver() function.

18.5 Winning the Game


At the beginning of this chapter we added two <script> tags. We’ve made good
use of the Mouse.js library to enable our ramps to move and rotate. We haven’t
done anything with the Scoreboard.js library. We use that here to put a time
limit on the game and to set the Game Over message.

Let’s add a scoreboard that includes a timer, a countdown from 40, some
help text, and something to do when the game is over:

varscoreboard =newScoreboard();
scoreboard.timer();
scoreboard.countdown(40);
scoreboard.help(
"Get the green ring. "+
"Click and drag blue ramps. "+
"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();
});

Chapter 18. Project: Cave Puzzle • 174


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf