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

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

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