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:

when green flag clicked
forever
if <touching [enemy] ?> then
broadcast [player hit]
end
end

Different code now:

when I receive [player hit]
play sound [optional]
switch costume to [?]

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
16 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.
when green flag clicked
forever
if <(hp) = [5]> then
switch costume to [5 v]
end
if <(hp) = [4]> then
switch costume to [4 v]
end
if <(hp) = [3]> then
switch costume to [3 v]
end
if <(hp) = [2]> then
switch costume to [2 v]
end
if <(hp) = [1]> then
switch costume to [1 v]
end
if <(hp) = [0]> then
switch costume to [0 v]
end
end
as many if statements as the hp.
and in a different sprite you can do this


when green flag clicked
forever
if <(hp) = [0]> then
broadcast [game over v]
end
end

when I receive [game over v]
set [do anything v] to [do anything you want here]
important:
when green flag clicked
set [hp v] to [total 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 here
forever
switch costume to (([floor v] of ((((current health) / (max health)) * (100)) / (increment))) * (increment))
feel free to make it do other stuff if you want
end

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:
when green flag clicked
set [HP] to [100]
forever
if <touching [ enemy] ?> then
broadcast [take damage]
end
end
a take damage feature right here:
when I receive [take damage]
change [HP] by (-10)
forever
if <<[0] = [HP]> or <[HP] < [0]>> then
broadcast [death]

end
end

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

Powered by DjangoBB