Expanding healtbars

Get help using Construct 2

Post » Thu Nov 07, 2013 9:19 pm

Hey there!
I am currently making a Tower defense game and with this i am creating enemies that has increasing health each wave. The formula goes CurrentWave*5 which means that on wave 1 they have 5 health, wave 2 10 health, wave 3 15 health and so on and so no. Problem is that i want to add healthbars on top of their little heads, and i since i want to accurately show the health that they have i have made the healthbars width to set after their current health. This of course makes their healthsbars insanely long after a few waves, covering the entire room at later waves.

So my question is, do you have any ideas on how i could make a static expanding bar but still accurately show the health of my enemies? Or perhaps you have a better idea on how to show their health.

Any tip is appreciated

Thanks in advance!
Posts: 18
Reputation: 1,415

Post » Thu Nov 07, 2013 10:14 pm

Don't make them expand. If you want the player to know how much health they have, make them selectable and display it at an information panel or just generally show it somewhere.
Dota 2 uses separators on the health bar that visually divide it into 250 health segments, but that makes only sense for big health bars. Sure you could add such separation, but I don't think it adds something to you game. Just give the player another way of finding out how much total health those guys have imo.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
Posts: 788
Reputation: 3,788

Post » Thu Nov 07, 2013 10:32 pm

Its actually quite easy to do.

For your enemies you add 2 variables:
Max_health (Just hold the max health the enemy can have)
Current_health (Enemy current health)

Then you make a sprite to indicate the health bar. You can use whatever width you want.

have to be the same, so you can either add that as an variable to the healthbar it self, would probably be the best, or you can hardcode it or add it as a global whatever way you prefer doing it.

Then use the following math to control it.

Width_of_enemy_health_bar = int((Width_of_enemy_health_bar_start_width / Enemy_Max_health) * Enemy_current_health)

So it looks like this:

Width_of_enemy_healthbar = 100px
Enemy max health = 20
Enemy_current_health = 14

Width_of_enemy_healthbar = int(100 / 20) * 14) = 70 px
Width_of_enemy_healthbar = int(100 / 20) * 8) = 40 pxnimos1002013-11-07 22:37:22
Posts: 1,182
Reputation: 6,848

Post » Thu Nov 07, 2013 11:44 pm

I did about the same what nimos did, but added a red bar at max length below a green bar. As the green bar reduced, more of the red became visible :)
Who dares wins
Posts: 1,878
Reputation: 19,572

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 36 guests