Creating Bullets

Click here to load the completed tutorial directly into the editor SWARM-17.DBA. If you want to step through and make the modifications, click here to load SWARM-16.DBA.

Creating bullets is almost exactly like creating aliens. We will use a user-defined function to create a single bullet, and then use a FOR NEXT loop to create many bullets. We will then store the bullet data in an array.

Replace the line REM * HERE B * to read:
rem Load bullet image
load image "bmp\bullet.bmp",3

Replace the line REM * HERE E * to read:
rem Prepare the decal object to look like a bullet
texture object objid,3

We first load the image of our bullet into image number 3, and then inside the user defined function make_single_bullet() we assign this image to the decal object as a texture.

Replace the line REM * HERE A * to read:
rem Declare global array
dim bullet#(40,5)

Replace the line REM * HERE C * to read:
rem Make many bullets
gosub _create_bullets

We will assign one bullet to the ship and 39 bullets to the aliens, making a total array size of 40 bullets. For each bullet, we will set-up 5 data items to store individual bullet information. The GOSUB command will jump to a pre-created subroutine called _create_bullets where we shall fill the array with bullet data.

Replace the line REM * HERE D * to read:
rem Make bullet using object identity
make_single_bullet(objid)

Inside our _create_bullets subroutine, you will find most of the code is similar to the alien creation subroutine. Again, we place our function call inside a simple FOR NEXT loop to repeat the creation of a bullet forty times.

Click Here For The Next Tutorial Controlling The Bullets.