3D Game Programming

(C. Jardin) #1

Challenge: Game Reset


Right now, the only way to restart a game is to show the code, press the Update
button, and then hide the code again. Try adding a keyboard handler so that
when the R key (computer code 82 ), is pressed, the game resets.

Some things to keep in mind:



  • The avatar should go back to the starting position.

  • The score should reset.

  • The game is no longer over.

  • Both animate() and gameStep() need to restart.


Good luck! This may prove quite a challenge—you may even want to give it
a try now, and then return after a few more chapters of experience with
physics.

19.4 The Code So Far


If you would like to double-check the code in this chapter, turn to Section
A1.15, Code: The Purple Fruit Monster Game, on page 245.

16.5 What’s Next


This was an impressive game to make. In the upcoming chapters we’ll practice
the physics skills that we developed here. We’ll also build on the concept of
a gameStep() function, which was fairly simple in this game.

report erratum • discuss

20.6 The Code So Far


Prepared exclusively for Michael Powell

Free download pdf