Health(Bar)

R

Ryan Leithall

Guest
I am trying to implement a health bar into my game that changed depending on health out of 100.
I want an enemy to do -25 damage when it collides with the main character but wait for a second or two before doing more damage (I used an alarm here). Obviously when Main character health = 0 restart level. I have displayed a healthbar but it doesn't move, however, I think this is to do with the health and collision (maybe alarm) because the main character seems dies straight away (after first collision) when it is supposed to take a few hit?

Not sure if I have given all the information needed sorry. Haha, I am confused and am not 100% where the problem lies. Feel free to ask me any questions I am active for a while. Thanks in advance.
 
R

Ryan Leithall

Guest

Attachments

R

Ryan Leithall

Guest
Create (Main Character)
HarryHealth = 100;
HarryLives = 5;
damage = 0;

Alarm1 (Main Character)
damage = false;

Collision with enemy (Main Character)
if damage = false
{
damage = true;
alarm[1] = 100;
}
HarryHealth = HarryHealth - 25;

Create (Health)
HarryHealth = 100;

Draw (Health)
var pc;
pc = (HarryHealth / 100) * 100;
draw_healthbar(202, 18, 276, 40, HarryHealth, c_black, c_red, c_lime, 0, true, true);

Step (Main Character)
if (HarryHealth <= 0)
{
room_restart();
HarryLives = HarryLives - 1;
}

Lives (Step)
if (HarryLives = 0)
{
room_goto(rm_GameOver1)
}
 
A

arirish

Guest
Collision with enemy (Main Character)
if damage = false
{
damage = true;
alarm[1] = 100;
}
HarryHealth = HarryHealth - 25;
Here you're subtracting from HarryHealth OUTSIDE your curly braces, so it'll do the damage regardless of whether the player has already been hit.

Also 'HarryHealth-=25' will suffice

For the Draw event, you will probably want to set up a new variable HealthMax in your Create event (this will make it easy to increase or low the player's max health later, if you decide to), and then do:
draw_healthbar(202,18,276,40,(HarryHealth/HealthMax)*100,0,c_black,c_red,0,1,1);
 
Last edited by a moderator:
R

Ryan Leithall

Guest
Here you're subtracting from HarryHealth OUTSIDE your curly braces, so it'll do the damage regardless of whether the player has already been hit.

Also 'HarryHealth-=25' will suffice

For the Draw event, you will probably want to set up a new variable HealthMax in your Create event (this will make it easy to increase or low the player's max health later, if you decide to), and then do:
draw_healthbar(202,18,276,40,(HarryHealth/HealthMax)*100,0,c_black,c_red,0,1,1);
Thanks I think that sorted the problem of dieing instantly but now it isn't doing damage at all.

Harry - Step
if damage = false
{
damage = true;
HarryHealth-=25;
alarm[1] = 1000;
}

Health - Draw
var pc;
pc = (HarryHealth / max_hp) * 100;
draw_healthbar(202, 18, 276, 40, pc, c_black, c_red, c_lime, 0, true, true);

It's saying HarryHealth is not defined but it is for another object. can you not use them ac...... wait I see problem need global variable. be right back ahaha
 
R

Ryan Leithall

Guest
Thanks I think that sorted the problem of dieing instantly but now it isn't doing damage at all.

Harry - Step
if damage = false
{
damage = true;
HarryHealth-=25;
alarm[1] = 1000;
}

Health - Draw
var pc;
pc = (HarryHealth / max_hp) * 100;
draw_healthbar(202, 18, 276, 40, pc, c_black, c_red, c_lime, 0, true, true);

It's saying HarryHealth is not defined but it is for another object. can you not use them ac...... wait I see problem need global variable. be right back ahaha
WOHOOOO fixed it! thank you everyone for your help!
 
Top