Ghost Invaders
4 Shooting The Ghosts

Section Menu

Ghost Invaders Home | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Create a new sprite called spr_bullet and load the bullet image.

Game Maker Screenshot

Create an object called obj_bullet and choose the bullet sprite from the list. Make the bullets solid.

Game Maker Screenshot

Go back to the ship object window. In the Create Event, add a Set Variable icon. Choose to set bullet_timer to 0.

Game Maker Screenshot

The bullet_timer variable will be used to make sure that there is a slight delay between each bullet. That stops the game being too easy.

Still in the obj_ship window, add a Step Event. Drag in the Set Variable icon and fill in the pop-up as follows,

Game Maker Screenshot

We will need a sound when the ship fires. Go to create a sound called snd_zap and load the zap sound.

Now return to the obj_ship window and add a Keyboard event. Choose the CTRL key. Drag in a Test Expression icon. We will only fire if the bullet_timer variable is 0 or less. Fill in the pop-up as shown

Game Maker Screenshot

Drag in a Start Block arrow followed by a Play Sound icon set to play the zap sound we added earlier.

Drag in the Create Instance icon and fill in the pop-up as shown,

Game Maker Screenshot

Drag in a Set Variable icon and set bullet_timer to 20. That means that there will be 20 game steps before the player can fire again. You will able to adjust this figure later if you need to.

Add an End Block icon to finish off, leaving your code looking like this,

Game Maker Screenshot

So far, we have made the bullet appear but haven't made it move. When the bullet is created, we want it to start moving directly up the screen.

Open up the obj_bullet window and add a Create Event. Drag in the Move Fixed icon and fill in the pop-up so the bullet moves up the screen at speed 5.

Game Maker Screenshot

When the bullet goes off the top of the screen, we might as well destroy it. Add an Intersect Boundary event (under Other) and drag in a Destroy Instance icon.

Game Maker Screenshot

We also need to make the bullet disappear when it hits a ghost. We should also play another sound. Create a sound called snd_boom and load the boom sound.

Add a Collision Event (with the ghost object) and drag in the play sound icon, set it to play the boom sound. Drag in a Destroy Instance icon.

Game Maker Screenshot

Finally, we need to make the ghosts disappear when the bullet hits them.

Open up the ghost object window. Add a Collision Event (with the bullet).

Drag in a Set Score icon, type in 10 and check the Relative checkbox.

Drag in a Destroy Instance icon.

Game Maker Screenshot

This is a good time to save your work and test the game so far. Make any adjustments to ship movement or firing that you think might be necessary.

⇐ Previous | Next ⇒