Ghost Invaders

5 The Ghosts Fight Back

To make the game more interesting, we need to give the ghosts some way to fight back. The ghosts are going to drop bombs. If a bomb hits the ship, the player will lose a life.

Start by creating a new sprite called spr_bomb and load the bomb graphic.

Create an object using this sprite. Call the object obj_bomb.

We want the ghosts to drop bombs at random intervals. We also want to make it so that as we shoot more of the ghosts, the ones that are left drop more bombs.

Add a Step event to the Ghost object window. Then drag in the Test Chance icon (looks like a dice). Fill in the pop-up as shown.

Increase or decrease the number 20 to vary how often the bombs appear.

Add a Start Block (up arrow) and then a Create Instance icon. Fill in the pop-up as shown in the screenshot.

Drag in an End Block (down arrow). Your window should look like the screenshot.

Now we need to make sure that the bombs fall down the screen. The actions for this are just like the ones we used to make the bullets fly up the screen except that we move the bombs downwards.

Open up the Bomb object window. Add a Create Event. Drag in a Move Fixed icon and fill in the pop-up as shown.

That gives you this,

We want to destroy the bombs when they reach the bottom of the screen. To do this add a Intersect Boundary Event (other). Drag in a Destroy Instance icon so that you have the following,

Create a new sound called snd_dead and load one of the sounds that you haven't used.

Go back to the bomb object window and add a Collision Event for when the bomb hits the ship. We need to do the following things,

Use the Destroy Instance icon to remove the bomb from the screen.
Use the Set Lives icon to set the number of lives to relative -1.
Use the Play Sound icon to play the dead sound.
You should end up with the following.

Save and test the game so far. Make sure that the bombs fall correctly and that they come more often when you shoot some of the ghosts.