A
Akari_Enderwolf
Guest
I've put together a health system which acts similar to that of the Metroid games, even being able to have and display extra health tanks.
I used some tutorials for setting up a testing game for it by following the tutorials from Shaun Spalding.
I also set up a hud handler to handle both the health system(which is incomplete as it doesn't include a death state yet) and displaying the hud.
Health Object
The Create Event code
The Step Event code
The Draw Event code
The Spike Object(used to test damage)
The Create Event Code
The Step Event Code
As you can see, the damage is supposed to only be calculated once, and in testing it does only run once, other than when the player is at full health, if the player is at full health then for some reason it deals damage twice. This applies to both having totally full 99 health, and to having a energy tank get emptied to reach 99 health again. I'm not sure why it's doing this. Healing items currently seem to work just fine with no issues.
I used some tutorials for setting up a testing game for it by following the tutorials from Shaun Spalding.
I also set up a hud handler to handle both the health system(which is incomplete as it doesn't include a death state yet) and displaying the hud.
Health Object
The Create Event code
global.hp = 99;
global.curexhp = 0;
global.currenthp = 0;
global.damage = 0;
global.totexhp = 0;
global.healing = 0;
global.curexhp = 0;
global.currenthp = 0;
global.damage = 0;
global.totexhp = 0;
global.healing = 0;
The Step Event code
//Damage Handling
if (global.damage > 0)
{
global.currenthp = global.hp;
global.hp -= global.damage;
}
if (global.hp < 0)
{
if(global.curexhp > 0)
{
global.curexhp -= 1;
global.hp = 99-(global.damage-global.hp);
}
}
global.damage = 0;
//Healing Handling
if (global.healing > 0)
{
global.currenthp = global.hp;
while (global.hp < 100)
{
global.hp += sign(global.healing);
global.healing -= 1;
}
}
if (global.hp > 99)
{
if (global.totexhp > 0)
{
if (global.curexhp < global.totexhp)
{
global.curexhp += 1;
while (global.hp < 100)
{
global.hp += sign(global.healing);
global.healing -= 1;
}
global.hp = 0+(global.healing);
}
else
{
global.healing = 0;
}
}
else
{
global.healing = 0;
global.hp = 99;
}
}
global.healing = 0;
if (global.damage > 0)
{
global.currenthp = global.hp;
global.hp -= global.damage;
}
if (global.hp < 0)
{
if(global.curexhp > 0)
{
global.curexhp -= 1;
global.hp = 99-(global.damage-global.hp);
}
}
global.damage = 0;
//Healing Handling
if (global.healing > 0)
{
global.currenthp = global.hp;
while (global.hp < 100)
{
global.hp += sign(global.healing);
global.healing -= 1;
}
}
if (global.hp > 99)
{
if (global.totexhp > 0)
{
if (global.curexhp < global.totexhp)
{
global.curexhp += 1;
while (global.hp < 100)
{
global.hp += sign(global.healing);
global.healing -= 1;
}
global.hp = 0+(global.healing);
}
else
{
global.healing = 0;
}
}
else
{
global.healing = 0;
global.hp = 99;
}
}
global.healing = 0;
The Draw Event code
draw_set_halign(fa_left);
draw_set_valign(fa_middle);
draw_set_color(c_white);
draw_set_font(fnt_small);
draw_text(32,32,global.hp);
if (global.totexhp > 0)
{
if (global.curexhp >= 1)
{
draw_sprite(exhp1,-1,64,32);
}
else
{
draw_sprite(exhp2,-1,64,32);
}
}
draw_set_valign(fa_middle);
draw_set_color(c_white);
draw_set_font(fnt_small);
draw_text(32,32,global.hp);
if (global.totexhp > 0)
{
if (global.curexhp >= 1)
{
draw_sprite(exhp1,-1,64,32);
}
else
{
draw_sprite(exhp2,-1,64,32);
}
}
The Spike Object(used to test damage)
The Create Event Code
//initialize variables
dam_deal = 3;
dam_deal = 3;
The Step Event Code
//damage step
if (place_meeting(x,y,Playerobj))
{
if (Playerobj.y < y-16)
{
with (Playerobj) vsp = -jumpspeed/2;
global.damage = dam_deal;
}
}
if (place_meeting(x,y,Playerobj))
{
if (Playerobj.y < y-16)
{
with (Playerobj) vsp = -jumpspeed/2;
global.damage = dam_deal;
}
}
As you can see, the damage is supposed to only be calculated once, and in testing it does only run once, other than when the player is at full health, if the player is at full health then for some reason it deals damage twice. This applies to both having totally full 99 health, and to having a energy tank get emptied to reach 99 health again. I'm not sure why it's doing this. Healing items currently seem to work just fine with no issues.