Health/armour system health

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
funnygamemaker
Prole
Posts: 2
Joined: Thu Mar 27, 2014 3:06 am

Health/armour system health

Post 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
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Health/armour system health

Post 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.
funnygamemaker
Prole
Posts: 2
Joined: Thu Mar 27, 2014 3:06 am

Re: Health/armour system health

Post 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.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Health/armour system health

Post 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
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests