Creating the Guns and Bullets

The gun for our game will simply be a cylinder that we will “attach” to the camera so that wherever we move the camera, the gun will follow. The bullets will be copies of the missile that we created in 3ds Max earlier in the book. If you happened to skip Chapter 10, “3D Modeling,” you have these options: you can go back and create the missile or grab the file from the CD or download it from our website. Let’s start by creating the code in bold for the gun:

EntityType snake(x), type_gallery
         EntityRadius snake(x), 5
      Next
;Creating the gun
gun=CreateCylinder(12)
      ScaleEntity gun,0.2,0.6,0.4
      RotateEntity gun,45,0,0
      PositionEntity gun, EntityX(camera),EntityY(camera)-2,
EntityZ(camera)+3
      EntityOrder gun, -1
      EntityParent gun,camera
EntityColor gun, 100,100,100

The code that we’ve used to create the gun simply creates a cylinder, colors it, positions it at the bottom of our screen, and then assigns the camera as its parent so that wherever the camera goes, it goes. The code we’ll use for the bullets is very similar to that which we used in Chapter 13, “Other 3D Game Components.” It will be an array that contains 100 bullets and loads the missile we created earlier. We’ll also create a variable called maxbull that will limit the number of bullets in our cartridge to 100 before having to reload. We’ll deal with reloading later; for now, let’s create the bullets by adding the following code in bold:

EntityParent gun,camera
EntityColor gun, 100,100,100
;Creating the bullets
maxbull = 100
      Dim bullet(maxbull)
      For i=0 To maxbull
         bullet(i)=LoadMesh ("bullet.3ds")
         EntityColor bullet(i), 100,100,100
      Next

Run the program now, and you should see the gun at the bottom of the screen. You won’t see any bullets because we haven’t positioned them; we’ll do that during the firing process a little later on in the program.

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

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