Discuss Scratch

rennamleart
Scratcher
9 posts

how do i make a HP bar for my player

im making an rpg game and need an hp bar. how do i do this?
RaMo-9
Scratcher
7 posts

how do i make a HP bar for my player

I haven't tried this in a project yet, but try it anyways:

whenclicked
foreveriftouchingenemy?thenbroadcastplayer hit

Different code now:

whenIreceiveplayer hitplaysoundoptionalswitchcostumeto?

Hope this helps!

Last edited by RaMo-9 (June 1, 2022 10:21:48)

zainelmawasef
Scratcher
41 posts

how do i make a HP bar for my player

You could draw it
randomguy3513
Scratcher
1000+ posts

how do i make a HP bar for my player

rennamleart wrote:

im making an rpg game and need an hp bar. how do i do this?
I made one for you
jaythunderbird
Scratcher
15 posts

how do i make a HP bar for my player

Okay i gotcha bro, (this only works for the main player.)

first create a sprite.
make it like a hp bar with full hp.
now make many costumes (as much as you want the hp), lowering the hp bar every costume.
once you get to last costume, make sure it has no hp.
lastly, name it from top to bottom.


ex. 5 for the highest hp (how high you want the hp)
and 0 for the lowest

now place the hp bar wherever you want to put it.

create a new variable called hp for all sprites

then code this.
whenclickedforeverifhp=5thenswitchcostumeto5ifhp=4thenswitchcostumeto4ifhp=3thenswitchcostumeto3ifhp=2thenswitchcostumeto2ifhp=1thenswitchcostumeto1ifhp=0thenswitchcostumeto0
as many if statements as the hp.
and in a different sprite you can do this


whenclickedforeverifhp=0thenbroadcastgame over

whenIreceivegame oversetdo anythingtodo anything you want here
important:
whenclickedsethptototal hp(your hp)

Last edited by jaythunderbird (June 1, 2022 16:46:07)

Huckleberry256
Scratcher
100+ posts

how do i make a HP bar for my player

Here's a script I used for something similar in one of my games.

1. Make costumes for the health bar. Each costume will represent a certain percentage of the maximum health. For the costumes' names, just put the percentage for that specific costume. The empty costume should be 0 and the full costume should be 100. Keep the increments' amounts consistent. (You'll need that later)
Example list of costumes: “0” (empty health bar), “25” (1/4 full), “50” (halfway full), “75” (3/4 full), “100” (completely full); increment is 25

2. Make this script in the health bar sprite. (Pay attention, the order of the blocks is important.)

make the health bar show, position itself, etc hereforeverswitchcostumetofloorofcurrenthealth/maxhealth*100/increment*incrementfeelfreetomakeitdootherstuffifyouwant

Hope this helps! Feel free to ask if you have any questions!

Last edited by Huckleberry256 (June 1, 2022 17:17:07)

hiiamshrek
Scratcher
66 posts

how do i make a HP bar for my player

rennamleart wrote:

im making an rpg game and need an hp bar. how do i do this?

Try this:
whenclickedsetHPto100foreveriftouching enemy?thenbroadcasttake damage
a take damage feature right here:
whenIreceivetake damagechangeHPby-10foreverif0=HPorHP<0thenbroadcastdeath

Last edited by hiiamshrek (June 1, 2022 19:52:54)

Powered by DjangoBB