Page 1 of 1

Health/armour system health

Posted: Thu Mar 27, 2014 3:10 am
by funnygamemaker
This is my first post here. I need help with my health system. when my player touches my enemy I want it to -1 heart every second.


Code: Select all

if ply.y + ply.h + enemy.y and ply.y < enemy.y + enemy.y and ply.x + ply.w > enemy.x and ply.x < enemy.x + enemy.w then -- collision
		 ply.healthscore = ply.healthscore + ply.damage *dt --health subtraction 
		end

Re: Health/armour system health

Posted: Thu Mar 27, 2014 5:20 am
by micha
Hello and welcome to the forum.

The only error I see is you put a "+" instead of a ">". It should be this:

Code: Select all

if ply.y + ply.h > enemy.y and 
   ply.y < enemy.y + enemy.y and 
   ply.x + ply.w > enemy.x and 
   ply.x < enemy.x + enemy.w then -- collision
      ply.healthscore = ply.healthscore + ply.damage *dt --health subtraction
end
If this is not what you are asking for, then please describe in more details what you want to achieve and what happens instead. And if possible provide a .love file of your code.

Re: Health/armour system health

Posted: Thu Mar 27, 2014 6:26 am
by funnygamemaker
what happens is, that the health goes down instance once the play touches and or if I *dt it goes down 1 every second but in very long decimals.

Re: Health/armour system health

Posted: Thu Mar 27, 2014 9:09 am
by Plu
You probably want to put the damage on a cooldown, then. Assuming you want to immediately lose a heart on first contact and then another after a second:

Code: Select all

if ply.y + ply.h > enemy.y and 
   ply.y < enemy.y + enemy.y and 
   ply.x + ply.w > enemy.x and 
   ply.x < enemy.x + enemy.w then -- collision
    if ply.invulnerable <= 0 then
      ply.healthscore = ply.healthscore + ply.damage
      ply.invulnerable = 1 -- this is a second
    end
end

-- reduce the invulnerable value every update cycle
ply.invulnerable = ply.invulnerable - dt