Platform Game
8 Scoring, Health & Lives

Section Menu

Platform Game Home | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

In this game the character loses health when it touches something bad. When all of your health is gone, you lose a life and the health guage goes back up to scratch. When the player runs out of lives, the game is over.

Not only do we have to manage this, but we are going to have all of this information displayed on screen during the game.

Start by creating a new object called obj_score_life_health. Look carefully at the settings in its window and make sure that you make it a persisitent object. This means that it will keep track of the score between levels.

Add a Create Event. You will need the following actions. On the last window, fill in the pop-up with all items set to show.

Game Maker Screenshot

Add a No More Health Event. and drag in the following actions.

Game Maker Screenshot

Add a No More Lives Event and drag in a Restart Room action. You can change this later to go to a Game Over screen, if you get around to making one.

Test the game at this point. You're nearly there!

Drawing The Score (Optional Extra)

You don't need to draw the score on the screen, most of the necessary information is shown in the caption of the game window. It does look a lot better though and you may find the techniques shown here useful when designing other games.

The drawing of the items on the screen takes place in the Draw Event for the obj_score_life_health object. Add the event to the object window.

Now you will create 2 fonts to use for writing text on the screen. They should be created as shown in the screenshots below.

Game Maker Screenshot Game Maker Screenshot

You can always change them later if you like.

Now return to the Draw Event you created. Drag in a Set Color action and choose the colour white. Now drag in a Draw Rectangle action and fill in the pop-up as shown,

Game Maker Screenshot

The settings look a bit scary. Be calm, little one - they can be explained. x1, y1 is the postion of the top left of the rectangle we are drawing. x2, y2 is the position of the bottom left of the reactangle. Because our game uses views, some of the game field is not visble in the window. There is no point drawing there so we add on the view_xview and view_yview values to keep our rectanlge on the screen. If you draw in a game that doesn't use views, you wouldn't need to add on these values.

Now drag in another Set Color action and choose solid red.

Drag in another Draw Rectangle action and fill this one in as follows,

Game Maker Screenshot

This gives a border to our panel.

Drag in a Set Font action and fill it in as shown,

Game Maker Screenshot

Drag in a Draw Score action and fill it in as shown below,

Game Maker Screenshot

Now to draw the number of cherries remaining in the box. We'll use a cherry icon to let them know what the number means. Drag in a Draw Sprite action and fill in the pop-up as shown,

Game Maker Screenshot

Drag in a Set Font action and set the font to the fnt_cherry font that we created earlier.

I couldn't think of an easier way of the drawing the number of cherries on the screen, so you're going to have to drag in an Execute Code action and type in the following,

Game Maker Screenshot

It's quite normal to draw the number of lives using a small version of the player's character graphic. Save the graphic below and create a spirte called spr_lives with it.

lives.gif

Drag in a Draw Lives action and fill in its boxes as shown,

Game Maker Screenshot

Finally, drag in a Draw Health action and give it the following values,

Game Maker Screenshot

You should now have something like this,

Game Maker Screenshot

Save and test this.

You should have a little play with these settings to get different effects. Remember that you will only need to add on view_xview and view_yview if your game uses views.

⇐ Previous | Next ⇒