2 Firing Bullets
The Firing Mechanism
In the arcade version of the game, the ship can fire bullets. Our first job is to create a sprite called, spr_bullet using the bullet graphic from the resources.
Make an object from this called obj_bullet.
Return to the ship object window. This is where the firing process starts. Add a Create Event and drag in a Set Variable icon. We will set a variable called canfire to 0 as shown in the screenshot.
Go to the End Step event that you created earlier and drag in another Set Variable icon. This time set the value of canfire to relative -1 as shown below.
This will be used to time when we can fire the bullets so that there will be a delay between each bullet fired.
Now add a Keyboard event for the CTRL key. Drag in a Test Expression icon and test that canfire<0 as shown,
Drag in a Start Block icon followed by a Create Instance icon, filling in the box as shown.
Create a sound using the zap sound and call it snd_zap. Drag in the Play Sound icon and play the sound.
Next, drag in a Set Variable icon and set the value of canfire to 15.
By adjusting the number, you will be able to increase and decrease the delay between bullets.
Finish with an End Block icon to give you the following,
Now we must turn our attention to the bullet - open up the object window and add a Create event. Drag in the Move Free icon and fill in the window like so,
The bullet will start moving in the direction in which the ship is facing.
Now drag in a Set Alarm icon and set Alarm0 to 60 as shown,
This gives you,
Now, add an Alarm event for Alarm0 and drag in a Destroy Instance icon.
Now we have to deal with what happens when the bullet goes off the screen. Add an Outside Room event and drag in a Wrap Screen icon and fill it in as shown,
Save your work and test the bullet firing mechanism. Adjust the speed of the bullet (in its create event) or the delay between bullets (in the CTRL keyboard event) until you are happy with the way it works.