Reloading Bullets

We only want our players to have 100 bullets before they reload. In order to accomplish this, we will need to add another condition to our If statement that controls the firing of the bullets. We’ll then use the R key (19) to reload the bullets. We created code similar to this in Chapter 13 so if any of the following code doesn’t make sense, then go back and review that chapter.

;Firing bullets
   If KeyHit (SPACE_BAR) And reload = 0
      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
      t=t+1
   EndIf
   For q = 0 To maxbull
      MoveEntity bullet(q), 0,0.8,3
      If CountCollisions (bullet(q))
         crash=CollisionEntity (bullet(q),1)
         HideEntity crash
      EndIf
   Next
bulletcount=100-t
If t=100 Then
   reload=1
EndIf
If KeyDown (R_KEY) = True Then
   t=0
   reload=0
EndIf
;Firing bullets
   If KeyHit (SPACE_BAR) And reload = 0
      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
      t=t+1
   EndIf
   For q = 0 To maxbull
      MoveEntity bullet(q), 0,0.8,3
      If CountCollisions (bullet(q))
         crash=CollisionEntity (bullet(q),1)
         HideEntity crash
      EndIf
    Next
bulletcount=100-t
If t=100 Then
    reload=1
EndIf
If KeyDown (R_KEY) = True Then
    t=0
    reload=0
EndIf

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

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