7 Adding A UFO
So far we have a playable game. When you lose lives or clear the wave of ghosts, something happens. We can still add a few more points of interest though. The first thing that needs changing is how often the ghosts drop their bombs. It's currently not often enough.
Open up the obj_ghost window and click on the Step Event that we created earlier. Change the Test Chance window as shown below.
The next step is to add a UFO to our game. The UFO will appear at various times during the game in the top left of the screen. It will fly to the right hand side of the screen and disappear off the end. There are big points for shooting the UFO.
Start by creating a new sprite called spr_ufo. Load up the UFO graphic. Create a new object using this sprite called obj_ufo.
The next thing to consider is what is going to trigger the arrival of the UFO. We could do this when the player reaches a certain score or when they have shot a certain number of ghosts. It could be random like the dropping of the ghost bombs or when a certain period of time has passed. We are going to make the UFO appear when a certain period of time has passed.
Open up the obj_game_controller window. Go to the Create Event and drag in a Set Alarm icon. Set Alarm0 to 500.
Now add an Alarm Event and choose Alarm0
Drag in the Create Instance icon and fill in the pop-up as follows.
When a UFO has been created, we need to reset the alarm. Drag in another Set Alarm icon and fill it in like before.
The window should now look like the screenshot.
That handles creating the UFO. Now we need to make sure that the UFO does something when it appears. Return to the obj_ufo window and add a Create Event. Drag in the Move Fixed icon and start the UFO moving to the right with a speed of 2.
Create a sound called snd_woohoo and load the woohoo sound from the sounds folder. Drag in the Play Sound icon and play the woohoo noise when the UFO is created.
When the UFO leaves the right hand edge of the screen we want it to be destroyed. Add an Outside Room event (under Other). Drag in a Destroy Instance icon like below.
The player needs some big points if they hit the UFO and we need to remove the UFO and bullet from the screen. Add a Collision Event to the UFO object window - the collision should be with the bullet object.
The first job is to destroy the UFO. Drag in the Destroy Instance icon.
Next you need to increase the score by, say 100. Drag in a Set Score icon and set the new score to Relative 100.
We also need to make the bullet disappear. Open up the obj_bullet window and add a Collision Event with the UFO object.
Play the snd_boom sound, just like when the ghosts are hit. Also drag in a Destroy Instance icon.
Save and test the game so far. Make any adjustments that you think are necessary.