Asteroids
4 Collisions, Lives & Scoring

Section Menu

Asteroids Home | 1 | 2 | 3 | 4 | 5

We will need to keep track of the score between different rooms (levels) and when the ship is not there. In order to do this, we create an invisible, persistent object called obj_game_controller,

Game Maker Screenshot

Add the object to the first room.

Add a Create event to the object. Drag in icons to Set Score to 0, Set Lives to 3 and finally drag in the Score Caption icon and fill it in as shown,

Game Maker Screenshot

When Asteroids Hit The Ship

Create a sound called snd_dead and load an appropriate sound.

Return to the ship object and add 3 collision events (one for each of the asteroid types). In each event we need to,

  • Play the sound
  • Reduce the number of lives by 1
  • Destroy the ship instance

The events will look like the screenshot.

Game Maker Screenshot

Now, with the ship disappearing on us, we need to make sure it comes back on the screen if there are lives left. In the classic game, your ship does not reappear in the middle of an asteroid. This is a bit tricky, but here goes,

Go to the obj_game_controller window and add an End Step event. Drag in a Test Instance Count icon and fill in the window as shown,

Game Maker Screenshot

Drag in a Start Block icon

Drag in a Test Expression icon and fill in the expression box with (x<280 || x>320) && (y<180 || y>250), like so,

Game Maker Screenshot

Drag in another Start Block icon

Drag in another Test Expression icon and fill in the expression box with (x<280 || x>320) && (y<180 || y>250), this time for obj_roid_medium.

Drag in another Start Block icon

Now, drag in another Test Expression icon and fill in the expression box with (x<280 || x>320) && (y<180 || y>250), this time for obj_roid_small.

Drag in another Start Block icon

Drag in a Create Instance icon and fill in the details a shown,

Game Maker Screenshot

Drag in 4 End Block icons so that you have the following,

Game Maker Screenshot

This set of actions returns the ship to the screen usually avoiding a collision with the asteroids.

Checking For No More Lives

For now, you just need to end the game when the player runs out of lives. Go to the obj_game_controller window and create a No More Lives event. Drag in icons to give the player a message that the game is over and then to end the game.

Checking For The End Of The Level

The level is over if there are no more asteroid instances left in the room.

Add a Begin Step event to the obj_game_controller window and drag in a Test Instance Count icon. Fill it in to check whether there are 0 instances of the large asteroid. Like so,

Game Maker Screenshot

Follow this with a Start Block icon. Drag in another Test Instance Count icon and fill it in to check whether there are no instances of the medium asteroid.

Add another Start Block icon and then drag in the icon to test whether there are 0 instances of the small asteroid.

The remainder of the actions check to see whether there are any other rooms. If there is a next room (level 2), then it will be loaded, otherwise the current room is restarted. Make sure your event looks like the screenshot,

Game Maker Screenshot

Save and test the game.

⇐ Previous | Next ⇒