Setting the Finish Line

Eventually the raft reaches the finish line. And then it keeps right on going. And going. Instead, let’s pause the game so that players can take a moment to admire their score before trying again. We need to make changes in four places: in our code outline and in startGame, animate, and gameStep.

Let’s start with the code outline. Before the call to the startGame function, we need to add a line for the paused variable:

 
var​ paused;
 
startGame(raft, river, scoreboard);

Other functions will use that variable to decide if they need to animate or update the game. JavaScript is pretty uptight about when variables are declared. The rule of thumb is that variables need to be declared before they’re used. The paused variable ...

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.