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 Then TurnEntity camera,0,1,0
If KeyDown(DOWN_KEY)=True Then MoveEntity camera,0,0,-1
If KeyDown(UP_KEY)=True Then MoveEntity camera,0,0,1
If KeyDown(V_KEY)=True Then TranslateEntity camera,0,3,0
MoveEntity camera, 0,-0.8,0

If you run the program now, you may be in for a little shock. Because we created gravity, the camera will move downward and fall right through the ground because we have yet to set up collisions. If you hold down the letter V, you can hover above the plane to get a good look at your playing field, as in Figure 14.13.

Figure 14.13. If you hold down the letter V and press the arrow keys, you can get a good view of your playing field.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.110.113