Health regen/damage with popup help

0 favourites
  • 6 posts
From the Asset Store
Relax and relieve stress by popping bubbles in Fidget Anti- Stress Releaser!
  • 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 =)

  • 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.

  • holy crap THANKS! that sounds amazing, checking it out!

  • and another capx

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • great thanks! =) will check out your capx and see what i can learn!

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)