Firing Bullets

The ability to fire bullets is one of the most important aspects of our game and will involve quite a bit of code. As stated earlier, we have a cartridge of 100 bullets, and we want the player to have to reload when he runs out of bullets. We’ll also need to create collisions so that when a bullet strikes a target, the target disappears and the score goes up by one. We’ll take care of that in a bit; for now, we’ll just create the code that fires the bullets.

MoveEntity dolphin(a), 0,-0.2,-0.3
Next
;Firing bullets
If KeyHit (SPACE_BAR)
PositionEntity bullet(t)
,EntityX(gun,1),EntityY(gun,1),EntityZ(gun,1)
      RotateEntity bullet(t),EntityPitch#(gun,1)-
35,EntityYaw#(gun,1),EntityRoll#(gun,1)
      EntityColor bullet(t),0,0,255
      EndIf
For q = 0 To maxbull
      MoveEntity bullet(q), 0,0.8,3
Next

If you ran the program now, you could fire by pressing the space bar—the only problem being that you are still falling through the ground because the gravity isn’t offset by a collision. In a moment, we’ll create our collisions, but before that, let’s cover pausing the game.

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

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