timmymc20 wrote:
Hey I'm trying to make a game and i need a life bar for my characters i can't figure out how to make one and code it right PLEASE HELP
You can use variables to display Life Points. Make a variable named 'HP', 'Life Points' or whatever you please. You can increase or decrease the 'Life Points' whenever you want. For example, if you want a sprite to have 100 Life Points at the start, script it like this.
when green flag clicked set Life Points to 100
Offline
timmymc20 wrote:
Hey I'm trying to make a game and i need a life bar for my characters i can't figure out how to make one and code it right PLEASE HELP
In addition, you can also make a true 'Life Bar'. However, this is more complex. You need to make different 'costumes' of the Life Bar sprite, which display all the possible outcomes. For example, a life bar has 100 life, which decreases at a rate of 25 life. You will have to make costume which display a full life bar, one which is 75% full, one which is 50% full, one which is 25% full and finally one that is empty. You will also need to know simple Maths to calculate the outcome each time. To make this system work, you can do this:
when gf clicked switch to costume 1 forever if <(Life Points) < [75]> switch to costume 2Here, Costume 1 = 100%/Full
when gf clicked forever if <(Life Points) < [50]> switch to costume 3
when gf clicked forever if <(Life Points) < [25]> switch to costume 4
when gf clicked forever if <(Life Points) < [1]> switch to costume 5Along with this, for balancing purposes, you can also do this:
when gf clicked forever if <(Life Points) < [0]> set (Life Points) to 0This is to avoid the Life Points from going to negative numbers, in case you are using variables.
Offline
Zelphase wrote:
timmymc20 wrote:
Hey I'm trying to make a game and i need a life bar for my characters i can't figure out how to make one and code it right PLEASE HELP
In addition, you can also make a true 'Life Bar'. However, this is more complex. You need to make different 'costumes' of the Life Bar sprite, which display all the possible outcomes. For example, a life bar has 100 life, which decreases at a rate of 25 life. You will have to make costume which display a full life bar, one which is 75% full, one which is 50% full, one which is 25% full and finally one that is empty. You will also need to know simple Maths to calculate the outcome each time. To make this system work, you can do this:
when gf clicked switch to costume 1 forever if <(Life Points) < [75]> switch to costume 2Here, Costume 1 = 100%/Full
Costume 2 = 75%
Costume 3 = 50%
Costume 4 = 25%
Costume 5 = 0%/Emptywhen gf clicked forever if <(Life Points) < [50]> switch to costume 3when gf clicked forever if <(Life Points) < [25]> switch to costume 4when gf clicked forever if <(Life Points) < [1]> switch to costume 5Along with this, for balancing purposes, you can also do this:when gf clicked forever if <(Life Points) < [0]> set (Life Points) to 0This is to avoid the Life Points from going to negative numbers, in case you are using variables.
I hope this helps you.
Good Luck!
Actually, the multiple "forever" loops will just conflict with each other.
So instead, use a series of "else if" blocks to act as a kind of "switch" block (programmers you know what I'm talking about)
I would show you what I mean, but unfortunately I am an amateur at making scratch blocks
Would anyone be nice to show what I mean?
Offline
bob6 wrote:
Zelphase wrote:
timmymc20 wrote:
Hey I'm trying to make a game and i need a life bar for my characters i can't figure out how to make one and code it right PLEASE HELP
In addition, you can also make a true 'Life Bar'. However, this is more complex. You need to make different 'costumes' of the Life Bar sprite, which display all the possible outcomes. For example, a life bar has 100 life, which decreases at a rate of 25 life. You will have to make costume which display a full life bar, one which is 75% full, one which is 50% full, one which is 25% full and finally one that is empty. You will also need to know simple Maths to calculate the outcome each time. To make this system work, you can do this:
when gf clicked switch to costume [costume 1 v] forever if <(Life Points) < [75]> switch to costume [costume 2 v]Here, Costume 1 = 100%/Full
Costume 2 = 75%
Costume 3 = 50%
Costume 4 = 25%
Costume 5 = 0%/Emptywhen gf clicked forever if <(Life Points) < [50]> switch to costume [costume 3 v]when gf clicked forever if <(Life Points) < [25]> switch to costume [costume 4 v]when gf clicked forever if <(Life Points) < [1]> switch to costume [costume 5 v]Along with this, for balancing purposes, you can also do this:when gf clicked forever if <(Life Points) < [0]> set [Life Points v] to (0)This is to avoid the Life Points from going to negative numbers, in case you are using variables.
I hope this helps you.
Good Luck!Actually, the multiple "forever" loops will just conflict with each other.
So instead, use a series of "else if" blocks to act as a kind of "switch" block (programmers you know what I'm talking about)
I would show you what I mean, but unfortunately I am an amateur at making scratch blocks
Would anyone be nice to show what I mean?
Yes, yes I am.
when gf clicked switch to costume [costume1 v] forever if <(Life Points) < (1)> switch to costume [costume5 v] set [Life Points v] to (0) else if <(Life Points) < (25)> switch to costume [costume4 v] else if <(Life Points) < (50)> switch to costume [costume3 v] else if <(Life Points) < (75)> switch to costume [costume2 v] end end end end
Last edited by ErnieParke (2013-02-17 21:08:19)
Offline
There is also a third option not mentioned above which can be used to get more precise health management but does require some loading time between health changes:
Healthbar Project
Offline
bob6 wrote:
I'm interested in knowing how to make a health bar gradually lower (obviously not with costumes). Is there a slick way to do this?
Yes, there is, through using stamping, pen, or through sprites (though this last one is for a number display of your health). So let's say that you have a maximum health of 100, with a health bar 100 pixels long. Do you see where I'm heading now? Well, if you don't, well be using the pen feature or stamping here. Now you just need to create a script that'll continuously stamp or write down a pixel for each unit of health that you have, and viola, you're good!
Now, the only issue that this arrises is that if you lose health, then how are you going to show that? Using a clear block would mean that you'll have to redraw the bar with no repeats (which can create a long script, and if you don't, a flashing health bar), or you'll have to stamp/draw black for no health, which can be a bit tedious if you have multiple non-black backgrounds, especially if they contain multiple colors where the health bar should be. So here, it just depends on what you prefer or need.
I hope that this answers your question!
Last edited by ErnieParke (2013-02-18 11:25:39)
Offline