Health regen/damage with popup help

Get help using Construct 2

Post » Tue Feb 18, 2014 7:04 pm

hello good folks i would appreciate some help with a mechanic im struggling with in my project!

in my project there are sprites called "people".
people have the number variable "health".
when "people" overlap a certain other type of sprite, the "health" decreases by 0.X every 0.X seconds.
and when people dont overlap that sprite, the health increases by 0.X every 0.X seconds.
that part is easy enough, but it would be nice if there was a better way since "every X seconds" applying to potentially hundereds of "people" is probably not the way to do it...

the problem:
everytime a "people" sprite loses or gains health at an integer (example: 50.1->50.0 or 50.1->51) i want to spawn a popup on that "people" informing the player that that particular guy lost or gained 1 health.

how do i:
create an event that on "people" variable changed from X to an Integer (higher or lower than X, X can be an integer itself) spawns a popup sprite?

PS. i might be using the word "integer" incorrectly, but i hope i make sense anyway =)
openfocus2014-02-18 19:05:59
B
8
S
1
Posts: 25
Reputation: 1,140

Post » Tue Feb 18, 2014 8:15 pm

@openfocus

Okay, so I spent some time on this. It was fun to make an example for the explanation that follows, here it is.

In this example, a spawn button will let you spawn people, blue squares. There is also a red fire.
People have 100 life when spawned, and will loose 8 life point every 0.5 second passed in the fire (those are constants in the project, you can change it easily). Once their life is under 50, an alert displays over their head. Once their life is at 0, they die (destroyed).
This works with multiple fires and people of course.

I commented the code a maximum for you to look at the events, as they are not that hard. You might noticed I put the alert text in the same container as the people, so they spawn and die together, and when one is picked, so is the other.

What I did was create a separate function to handle all the changes in life. This way, you can easily write code with damage, without thinking about the alert or the death.
On the other hand, for a damage over time, the behavior "timer" seems the more appropriate.
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Tue Feb 18, 2014 8:24 pm

holy crap THANKS! that sounds amazing, checking it out!
B
8
S
1
Posts: 25
Reputation: 1,140

Post » Tue Feb 18, 2014 9:05 pm

and another capx
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Tue Feb 18, 2014 9:58 pm

great thanks! =) will check out your capx and see what i can learn!
B
8
S
1
Posts: 25
Reputation: 1,140

Post » Tue Feb 18, 2014 10:51 pm

Thanks RamPack and Guizmus! i actually had to use bits of both to make it work like i wanted to =)

Guizmus function was really clever but made it so MinusHealthSprite spawned at the end of every timer, regardless of how much health was lost as long as some was lost.

the solution to that problem was provided in rampacks capx
B
8
S
1
Posts: 25
Reputation: 1,140


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests