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

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 ...

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