Discuss Scratch

Coolbee14
Scratcher
13 posts

Health Bars

How do I make Amy health bars? I have a game that uses lots of enemies and it has the mall on the same screen at a time. So I want to make it like a regular health bar or if you hit it it goes down automatically. How would I make that? Is it possible to use a list of variables? I think I could but I'm just wondering if I have to put in every single detail at to work. I know there's a few videos out there but it's kind of hard to find a good one. Can you guys send a video link or something?
Thank you- Coolbee
red-fox-codes
Scratcher
43 posts

Health Bars

Coolbee14 wrote:

How do I make Amy health bars? I have a game that uses lots of enemies and it has the mall on the same screen at a time. So I want to make it like a regular health bar or if you hit it it goes down automatically. How would I make that? Is it possible to use a list of variables? I think I could but I'm just wondering if I have to put in every single detail at to work. I know there's a few videos out there but it's kind of hard to find a good one. Can you guys send a video link or something?
Thank you- Coolbee

Create a list of all enemy health.
Create a list of all enemy x positions.
Create a list of all enemy y positions.

This allows up to 20,000 enemies at a time.

Create a sprite and name it “Pen” or “hpRenderer” or something.

Add the following code:
Pen up.
Change pen color to black.
Go to x: (enemyX + (hpBarSize / 2))
Pen down.
Go to x: (enemyX - (hpBarSize / 2))
Pen up.
Change pen color to green.
Go to x: (enemyX + (hpBarSize / 2))
Pen down.
Go to x: ((enemyX + (hpBarSize / 2)) - enemyHealth)
Pen up.

If that was confusing I could make a demo for you, which would be easier to follow.
Coolbee14
Scratcher
13 posts

Health Bars

Ok, that makes sense. Also lol I just realized I forgot to overlook it before sending it. I used speech to text… How would I make the enemy health variable? I saw you said a list, do I put the enemy name or something to classify them and then their health or how should I make it?

Last edited by Coolbee14 (April 17, 2023 23:48:35)

--Dovahkiin--
Scratcher
100+ posts

Health Bars

Just put the health amount in the list and use the numbers on the side to match health to the right enemies.

(item (1 v) of [list v] :: list)

Then you can use this block thing for finding the amount of it

It also could help to make a comment inside your project naming the enemies and what number they are
//Basic enemy = 1
//Boss = 2
add [25] to [Health v]
add [100] to [Health v]


They will add in order so the 1st one here matches to the weaker enemy. Hope this helps

(also you can use this to see if they are dead)
forever
if <(item (1 v) of [Health] :: list) < [1]> then
hide
end
end
and item one is the Basic enemy as stated above. (But you can have it in any way, this is just how I wrote out the list)

Note: The comments don't actually do anything but help you figure out and keep track of the lists and enemies, so make sure to put code under the right enemies and stuff. (I keep editing this so much lol)

Last edited by --Dovahkiin-- (April 18, 2023 00:04:07)

Dinosaurguy77
Scratcher
500+ posts

Health Bars

To do this you must make a sprite with 5 costumes. Make the first 1 full hp.
The second one should have 3 fourths of hp.
The 3rd one should be 1 half hp left.
The 4th one should have 1 fourth hp left.
And the 5th costume should be no hp left.

Welcome.

-Dinosaurguy77




when not  green flag clicked
tell us [hi] forever 
kkidslogin
Scratcher
1000+ posts

Health Bars

Here's my fancy pen code, usually in a separate sprite:

when green flag clicked
set [health v] to [100]
set [health_max v] to [100]
set pen size to (15)
when green flag clicked
forever
clear
go to x: (-220) y: (160)
set pen color to [#DD3333]
pen down
set x to ((((health) / (health_max)) * (440)) - (220))
set pen color to [#444444]
set x to (220)
pen up
end

Don't let health_max change unless the maximum health for the sprite changes as well. The “clear” block is actually the “Erase All” block in Scratch 3.

Forum Clout: 232,655. Alright, who ate my Kumquats? Finally foruming again. Support for reasons in OP and no support for all the other reasons.



Enjoy my music.

[small]non-member post, take whatever I say with a hint of salt and remember there's no authority behind it[/small]
Coolbee14
Scratcher
13 posts

Health Bars

red-fox-codes wrote:

Coolbee14 wrote:

How do I make Amy health bars? I have a game that uses lots of enemies and it has the mall on the same screen at a time. So I want to make it like a regular health bar or if you hit it it goes down automatically. How would I make that? Is it possible to use a list of variables? I think I could but I'm just wondering if I have to put in every single detail at to work. I know there's a few videos out there but it's kind of hard to find a good one. Can you guys send a video link or something?
Thank you- Coolbee

Create a list of all enemy health.
Create a list of all enemy x positions.
Create a list of all enemy y positions.

This allows up to 20,000 enemies at a time.

Create a sprite and name it “Pen” or “hpRenderer” or something.

Add the following code:
Pen up.
Change pen color to black.
Go to x: (enemyX + (hpBarSize / 2))
Pen down.
Go to x: (enemyX - (hpBarSize / 2))
Pen up.
Change pen color to green.
Go to x: (enemyX + (hpBarSize / 2))
Pen down.
Go to x: ((enemyX + (hpBarSize / 2)) - enemyHealth)
Pen up.

If that was confusing I could make a demo for you, which would be easier to follow.

How do I make a system so the enemies know what item number they are? If all of the enemies are one sprite, and I just have multiple clones, what should I do to keep everything organized?

Last edited by Coolbee14 (April 24, 2023 19:09:45)

yvin
New to Scratch
1 post

Health Bars

Coolbee14 wrote:

red-fox-codes wrote:

Coolbee14 wrote:

How do I make Amy health bars? I have a game that uses lots of enemies and it has the mall on the same screen at a time. So I want to make it like a regular health bar or if you hit it it goes down automatically. How would I make that? Is it possible to use a list of variables? I think I could but I'm just wondering if I have to put in every single detail at to work. I know there's a few videos out there but it's kind of hard to find a good one. Can you guys send a video link or something?
Thank you- Coolbee

Create a list of all enemy health.
Create a list of all enemy x positions.
Create a list of all enemy y positions.

This allows up to 20,000 enemies at a time.

Create a sprite and name it “Pen” or “hpRenderer” or something.

Add the following code:
Pen up.
Change pen color to black.
Go to x: (enemyX + (hpBarSize / 2))
Pen down.
Go to x: (enemyX - (hpBarSize / 2))
Pen up.
Change pen color to green.
Go to x: (enemyX + (hpBarSize / 2))
Pen down.
Go to x: ((enemyX + (hpBarSize / 2)) - enemyHealth)
Pen up.

If that was confusing I could make a demo for you, which would be easier to follow.

How do I make a system so the enemies know what item number they are? If all of the enemies are one sprite, and I just have multiple clones, what should I do to keep everything organized?

Not sure what you need it for exactly, but here's an idea. You need to maintain a list of enemies' IDs. It should be placed in a common place, like the stage. Adding a unique clone ID should be performed by the clone itself. And the ID should be stored in the clone as well:
when I start as a clone
set [my_id v] to ((length of [IDs v] :: list) + (1))
add (my_id) to [IDs v]
booger_and_moose
Scratcher
1 post

Health Bars

Have you made a health bar sprite yet? If you have, do this:
when green flag clicked
forever

if <touching enemy> then
switch costume to [costume2 v]
switch costume to [costume3 v]
switch costume to [costume4 v]

endend

Powered by DjangoBB