How do I make enemies with health bars?

Get help using Construct 2

Post » Sat May 09, 2015 6:37 pm

Containers are definitly the better way but i figured that using the UID is easier to understand for beginners.
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Sat May 09, 2015 7:03 pm

@Fireche & @Jayjay Thanks a a lot for helping I don't know what I would do with out you!

I made 2 sprites on the zombie - 1 is Head, 2 is body.
- When the bullet collides with the Body subtract 20 from health.
-When the bullet collides with the Head kill instantly.

But the clone ( copied zombie ) still dies if i kill one of them .... Please help :(

here is the image of the event sheet... Direct Link - upload.ee/image/4715414/testing.png
Image

Thank you for any future help! It really helps me!
Last edited by Frap1K on Sat May 09, 2015 8:19 pm, edited 1 time in total.
B
8
S
3
Posts: 120
Reputation: 989

Post » Sat May 09, 2015 7:30 pm

add zombieheadbox and zombiebodybox into the container for the zombie, and make sure there is only one of each type these objects in the layout: zombie_Health, zombieHeadBox, zombieBodyBox.

The system will automatically create those afterward when the game is started/running for each zombie, so you can place or create or destroy zombie objects and the other stuff will be added and removed for you :)

That also means that the actions you made for sub-events 42 and 43 can be moved straight into the "for each Zombie" in event 41. In fact, you can copy the actions from event 44 into 41 as well and delete that.

That way there is only:

41 For Each Zombie -> All the actions from events 42, 43, 44

42 (was 45) Bullet: On collision with zombieBodyBox -> Zombie subtract 20 from Health

43 (was 46) Zombie: Health < 1 -> Set animation to ....

However, that last event might be better as a sub-event to 41 you might have to test for that

Hope that helps! Otherwise, please upload your capx to Dropbox or Google Drive (free) and then share a link here (to get past the link filter replace the .'s with (dot)'s eg: http://www.google.com/ becomes http://www(dot)google(dot)com/)
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
113
S
39
G
17
Posts: 2,184
Reputation: 19,217

Post » Sat May 09, 2015 8:50 pm

@Jayjay Thank you so much for explaining to me this mess! Will try to make it now, but I guess ill get stuck on the 41 as Im unsure what this means :

(zombieBodyBox.Health / zombieBodyBox.MaxHealth) * zombie_Health.MaxWidth

It devides the full health from health ? and times it by it's width ? If you have time could you explain this to me ?

Thank you for your attention!
B
8
S
3
Posts: 120
Reputation: 989

Post » Sat May 09, 2015 9:11 pm

Sure thing Frap1K, here's a break-down of how that works:

MaxWidth is a variable I gave to the healthbar that is literally a width value for when health is at its max size (it shrinks as health decreases). This could be any number, but usually should probably be the width of the object it represents (so full health has the bar the size of the object), so it could be 32px let's say.

MaxHealth is a variable to represent what full health is (eg: 20)

Health is the current health (eg: 20 to start)

The formula is taking a ratio of current health to max health to make it a number between 0% and 100% (0 and 1).

It then multiplies that by the max width, to represent how full the bar is.

So in our examples it would be like this at the start:

Healthbar width = (20 / 20) * 32 = (1) * 32 = 32px

But at half health it would be:

Healthbar width = (10/20) * 32 = (0.5) * 32 = 16px

At 0 health it's:

Healthbar width = (0/20) * 32 = (0) * 32 = 0px

Hope that helps! :)
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
113
S
39
G
17
Posts: 2,184
Reputation: 19,217

Post » Sat May 09, 2015 9:58 pm

Thank you @Jayjay I understood it! It helped me a lot!

Okey so I did what you told me:
Image

When Health is less then < 1 then animation play...
Image


1.) When the bullet colliding with 2 of them the healthbar doesn't seem to know what to do? IMAGE - 1
2.)But the death animation keep repeating over again. The repeat animation is set to 1 so once why does it do that then? do you have any idea? IMAGE - 2

I don't know how to thank you, you helped me so much on this...
B
8
S
3
Posts: 120
Reputation: 989

Post » Sun May 10, 2015 1:11 am

Frap1K Glad to see it's starting to take shape, nice looking game so far!

But remember, any objects in a container can't be destroyed unless you are also okay with everything else in the container being destroyed too. Try changing it so that the objects you don't want anymore are "Set Visible" set to "Invisible" and disable collisions (don't know that one from memory though).

Also, the healthbars being offset comes down to image hotspots, as the math for positioning the healtbar assumes it has a hotspot in its center.

As for issue #2, try adding a variable to the zombie like "alive" and have it start as 1, then in event 41 add the condition to check if alive = 1. Then you can set alive to 0 in the actions for it so it never triggers again after the first trigger :)

And anytime! I'm really glad to help :D
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
113
S
39
G
17
Posts: 2,184
Reputation: 19,217

Post » Sun May 10, 2015 9:49 pm

Hey @Jayjay Thank you! Everything works now! I set it all invisible so the zombie is only visible for the player but when the zombies are standing in the same line and position, what happens is when I shoot the zombie they die together so it doesn't really matter if there are 100 of them(zombies) you will still kill them with 2 bullets in the head as it takes away 50 health from 100... .

So I have come up with Idea creating:

Solid sprite that will separate them both from colliding together - Which is a pink block
Image

But...The zombies spazzing out (going crazy all over the place) when I add it.

Which is the best way of doing it?
- Putting the zombieCollider into the >> Zombie Container? that's what I tried doing ant I failed somewhere (thats where the zombie was spazzing out all over the map) :(
- On start of layout Pin it to each zombie?
- or any other ways to do it?

Thank you for you help I appreciate it!
B
8
S
3
Posts: 120
Reputation: 989

Post » Sun May 10, 2015 11:13 pm

Awesome progress :D I would try first just destroying the bullets when they collide first before trying those other methods, but otherwise I think adding it to the container, then on start of layout (or when a zombie is created) you position the pink box to the center of the zombie and then pin it. Hope that helps too!

Nice graphics by the way!
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
113
S
39
G
17
Posts: 2,184
Reputation: 19,217

Post » Mon May 11, 2015 1:29 pm

Hey @Jayjay Ty for replying! Yes I did the bullet collide it with zombie but it wont work as the zombies are standing at exact same pixel. So it's gonna kill them both or if there is 10 of them.

I'm having trouble with creating the thing you told me :(. I'm probably doing something wrong again ...
Image

What Happens:
Image

Maybe it's because the pink box is too low? how do I align it to the center :o ?
Thank you again!
B
8
S
3
Posts: 120
Reputation: 989

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests