GAME MAKER STUDIO TUTORIAL
MINI TUTORIAL 05 – HEALTH BARS

separator-blank.png

DESCRIPTION

·         In this mini tutorial, you will learn how to add health bars above different objects such as enemies. 

RESOURCES

·         Click here.

STEPS

GameMaker Version 1.4.1749

 

1 – Creating our sprites

·         Create the following three sprites:

o   Names: spr_ship, spr_badguy, spr_torpedo

o   For each sprite, load the corresponding image from the resources.

o   For each sprite, make sure you center the image's origin.

2 – Creating our objects

·         Create corresponding objects for each sprite above.

o   Names: obj_ship, obj_badguy, obj_torpedo

3 – Create our room

·         Create a room. 

·         Add a badguy object near the top.

·         Add a ship object near the bottom.  Make sure the ship object is placed directly under the badguy object (so its bullets hit the badguy).

4 – Shooting

·         Inside the ship object, add a Keyboard <Space> event.

·         In that event, add a Create Instance action (main1 tab).

o   Object: obj_torpedo

o   X: 0

o   Y: 0

o   Relative: Checked

·         Now inside the torpedo object, add a Create event.

·         In that event, add a Move Fixed action (move tab).

o   Direction: Up

o   Speed: 20

o   Relative: Not checked

Save and test your game.  Your ship cannot move but it can shoot.  Next, we need to check for collisions between torpedos and the badguy.

 

5 – Badguy's HP

·         In the badguy object, add a Create event.

·         In that event, add a Set Variable action (Control tab).

o   Variable: maxhp

o   Value: 1000

o   Relative: Unchecked

·         In the same event, add another Set Variable action (Control tab).

o   Variable: hp

o   Value: 1000

o   Relative: Unchecked

6 – Collision between torpedos & badguy

·         Inside the badguy object, add a Colision <obj_torpedo> event.

·         You will now add the actions to remove the torpedo, low the badguy's hp and, if the badguy is dead, remove it from the game.  See the image below for details.


Save and test your game.  You can now shoot and kill the badguy.  Note that it takes a lot of torpedo to kill it.  Next, we work with the health bar for the badguy.

 

7 – The Health Bar

·         Inside the badguy object, add a Draw GUI event.

·         Inside that event, add a Set Color action (Draw tab)

o   Colour: red

·         Inside the same event, add a Draw Rectangle action (Draw tab)

o   Attributes are explained below:

 

·         Inside the same event, add a Set Color action (Draw tab)

o   Colour: green

·         Inside the same event, add a Draw Rectangle action (Draw tab)

o   Attributes are explained below.


Save and test your game.  You should now have an interactive health bar over your badguy.

 

                                               

SOURCE

  • Straight from Mr. Campeau's brain.  J

separator-campeau.png