O'Reilly logo

3D Game Programming for Teens, Second Edition by Eric Grebler, Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Game Control and Gravity

The controls for the game are actually quite simple. The arrow keys will move the player back and forth or rotate the view from side to side. In this section, we’ll also create the illusion of gravity by constantly moving the player downward, and we’ll allow the player to jump by moving the camera upward every time the letter V is pressed. I chose the letter V because it is close to the space bar (which is what will be used for firing bullets later) so that the player can jump and fire using the same hand. Add the following code in bold to add controls and gravity for the game:

; The following code makes our program run
      While Not KeyDown(ESC_KEY)
If KeyDown(RIGHT_KEY)=True Then TurnEntity camera,0,-1,0 If KeyDown(LEFT_KEY)=True ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required