This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-02-08 10:59:54

timmymc20
New Scratcher
Registered: 2013-02-08
Posts: 3

Life points

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

Offline

 

#2 2013-02-13 10:28:04

Zelphase
New Scratcher
Registered: 2013-02-13
Posts: 24

Re: Life points

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

 

#3 2013-02-13 11:15:10

Zelphase
New Scratcher
Registered: 2013-02-13
Posts: 24

Re: Life points

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 2
Here, Costume 1 = 100%/Full
         Costume 2 = 75%
         Costume 3 = 50%
         Costume 4 = 25%
         Costume 5 = 0%/Empty

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 5
Along with this, for balancing purposes, you can also do this:

when gf clicked
forever if <(Life Points) < [0]>
set (Life Points) 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!

Offline

 

#4 2013-02-17 20:11:49

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Life points

Moving to Help with Scripts.


nXIII

Offline

 

#5 2013-02-17 20:55:35

bob6
Scratcher
Registered: 2010-07-01
Posts: 100+

Re: Life points

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 2
Here, Costume 1 = 100%/Full
         Costume 2 = 75%
         Costume 3 = 50%
         Costume 4 = 25%
         Costume 5 = 0%/Empty

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 5
Along with this, for balancing purposes, you can also do this:

when gf clicked
forever if <(Life Points) < [0]>
set (Life Points) 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  sad
Would anyone be nice to show what I mean?


http://i46.tinypic.com/3148ksz.gif

Offline

 

#6 2013-02-17 21:06:02

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Life points

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%/Empty

when 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  sad
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)


http://i46.tinypic.com/35ismmc.png

Offline

 

#7 2013-02-18 07:17:49

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: Life points

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


http://i50.tinypic.com/ded8m.png

Offline

 

#8 2013-02-18 10:48:18

bob6
Scratcher
Registered: 2010-07-01
Posts: 100+

Re: Life points

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?


http://i46.tinypic.com/3148ksz.gif

Offline

 

#9 2013-02-18 11:23:59

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Life points

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)


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer