ONE Health Bar for each Enemy

For questions about using Classic.

Post » Sun Jun 10, 2012 7:13 pm

Welcome all, and sorry for my english (in advance).

Question is:
How to do one HP Bar, which is assigned for each of the enemy (something like in Diablo 2)

Value of HP Bar would be depending on who (of enemy) was hit at a time and show his own HP. When sombody else get hit, then this same HP Bar will replace that value on new one.

I did HP bars for each enemy separately, however when is only one HP Bar for all of them, then I have a problem to make it works.


I hope that the question is understandable.Eternit2013-04-03 17:43:41
B
10
S
2
G
2
Posts: 11
Reputation: 931

Post » Sun Jun 10, 2012 7:38 pm

Oh, I know what you mean. I got 2 solutions. First requires one hp bar for each different kind of enemies. The second is one hp bar for all enemies.

1. Make your enemy, make your hpbar. Click on the enemy, left is your properties bar, seek for the container option and add the hp bar for it.
If you spawn your enemy, the hpbar will spawn also, linked tot he enemy.
Make a private variable "hp". And then:
"condition when player hits enemy:
subtract 'value' from enemy('hp')
set hpbar.width to (100/enemy_max_hp) * enemy('hp')"

Replace the 100 for the with of the hpbar.

2. I'm not sure with that one. I would try a "for each" loop.
For each family(enemy):
condition when player hits enemy:
set hpbar.width to the private variable 'hp' of the family, again like in step one, with the rule of three.
But I'm not very sure with this one^^. Someone has to reply/improve/add this one, so that it's right

ps: I'm not one of the advanced users here, this the way I would do it, maybe someone else has better solutions :)zyblade2012-06-10 19:46:59
B
24
S
9
G
2
Posts: 294
Reputation: 3,160

Post » Sun Jun 10, 2012 8:28 pm

Thanks for reply.

I made first of Your solution and when I hit one of the enemy and then hit other one, his HP Bar decrease but only to HP value of the first one that I hit.

Example:
I hit ENEMY1 for 20, his HP decrease to 80
I hit ENEMY2 for 20, his HP decrease to 80, I hit him again for 20, but his HP still 80

So it's close but still something wrong.


EDIT
Second solution do this same. I hit somebody, HP Bar show how his HP decrease - but when I hit next enemy, HP Bar decrease and stop at the value of HP that first enemy had left.

Some others idea?Eternit2012-06-10 20:58:41
B
10
S
2
G
2
Posts: 11
Reputation: 931

Post » Sun Jun 10, 2012 8:52 pm

The solution is correct, you are making something wrong Eternit.
It's a simple rule of 3 equation, it can't be wrong.

You need to put a fixed maximum value to the bar width when the Enemy HP are at 100%. And replace the number 100 to that maximum width value on the equation:
set hpbar.width to (100/enemy_max_hp) * enemy('hp')"
B
22
S
7
G
5
Posts: 90
Reputation: 3,430

Post » Sun Jun 10, 2012 10:09 pm

"Set hpbar.width to (100/enemy_max_hp) * enemy('hp')" - this work great, problem is in something else.

I noticed that the HP Bar overlap each other when I hit more than one opponent. Which means that I always see enemy HP who was hit already and also has the highest value of HP. I should see only one HP Bar at a time, not all of them overplaping each other - and that's the problem now.Eternit2012-06-10 22:10:36
B
10
S
2
G
2
Posts: 11
Reputation: 931

Post » Sun Jun 10, 2012 10:33 pm

Create a variable to the family Enemy to keep track of the last enemy hited.
Always set all the bars to be invisible, and when you hit an enemy set the current variable of that enemy to keep track of its HP bar(value=1) and set all others to don't keep track of its HP bar (value=0).
Now make visible only the current HP bar enemy variable that is keep tracking (value=1).
B
22
S
7
G
5
Posts: 90
Reputation: 3,430

Post » Mon Jun 11, 2012 10:45 am

Probably I doing something wrong because it still not working. I don't know how to do ...
[QUOTE=Metal_X]... and when you hit an enemy set the current variable of that enemy to keep track of its HP bar(value=1) and set all others to don't keep track of its HP bar (value=0).[/QUOTE]
How to set to don't keep track others HP bar, where they are the same enemy but just duplicate? Enemy have HP container so it's should work, right? I don't know ... my mind is just blow away.

Can I ask You for more detailed reply?Eternit2012-06-11 10:45:13
B
10
S
2
G
2
Posts: 11
Reputation: 931

Post » Mon Jun 11, 2012 12:29 pm

@Eternit
it's a clearer solution in my point of view if you using a global variable("enemy_hit_bar" for example), and a private variable("id"), assign this to every enemy.

When you hit the enemy, save it's pv(id) to the globalvar(enemy_hit_bar), after this, you can easily define wich is your target like this:

for each enemy:
if enemy.value('id') == globalvar('enemy_hit_bar'):
<the code where you set the hp bar>

this will pick the correct instance, and you can debug it a lot easier beacuse you don't have to check every instance by hand if something went wrong.


Edit: and don't put the hp bar in the container when you only want to display one.Pecek2012-06-11 12:47:59
B
10
S
6
G
3
Posts: 127
Reputation: 2,481

Post » Mon Jun 11, 2012 2:33 pm

I just unnecessarily add container when I do zyblade first solution. I remove container, like You Pecek said in "Edit" and it's work great. Now it's so simple ...

So if someone will have a similar problem, just do what zyblade said, but NOT add the container for HP bar.


Thanks zyblade, Pecek and Metal_X for help!Eternit2012-06-11 14:34:40
B
10
S
2
G
2
Posts: 11
Reputation: 931

Post » Mon Jun 11, 2012 3:32 pm

No problem, the container makes it just easier to pick if they're more than just 1 hpbar/enemy^^ But you can do it without using the container. Hope to see some demo in the forum of your game. ;)zyblade2012-06-11 15:34:11
B
24
S
9
G
2
Posts: 294
Reputation: 3,160

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests