This site requires JavaScript, please enable it in your browser!
Greenfoot back
Zyphos
Zyphos wrote ...

2012/5/14

Health Bar and Stop/Play Problem

Zyphos Zyphos

2012/5/14

#
Hi all, I am having a problem with creating a health bar. I have an idea of how to do with one actor, but since I'm trying to make a game with two human controlled actors, with separate health bars. On top of that, I have it so the game stops (not resets) after a single movement and (hopefully) damage is taken (collision). I need it so that when play is then pressed after a single collision, it puts both actors back to their start locations. The idea is to make the game turn based in a way. Thanks in advance for any help offered, Zyphos.
danpost danpost

2012/5/15

#
In the player class, add an instance Bar variable to hold the health bar that the player uses. After adding the instance variable, add a method in the same class to recieve and set the value of its new instance variable (call it 'setBar(Bar bar)'). Finally, in the world class constructor (when creating and adding your objects), create a player and a bar, call the method in the player class to set that bar to the player, and add them to the world; then, do it again for the other player (create a player and a bar, ...).
Zyphos Zyphos

2012/5/15

#
I have only one thing to say about parts of you reply... uhhhhh... what? I never learned much terminology... Can you please explain your reply a bit with actual code?
danpost danpost

2012/5/15

#
First, let us see what you have as your bar class so far.
Zyphos Zyphos

2012/5/15

#
*edit* Actually, I currently have the Progress bar/ health bar class that you uploaded danpost, Due to the fact that I thought that might work if I changed some of thing to work be used in collision (and took out all the strings in the world class). My main problem with this though is that I don't know how to call for the collision in the world class or the bar class to subtract the bar. Another issue is that since I created the world like this:
super(60,60, 10); 
        addObject(new Player(), (getWidth()/2)-15, (getHeight()/2));
        addObject(new Opponent(), (getWidth()/2)+15, (getHeight()/2));
I still converted the variables as such (making 100 -> 10, making the bar decrease by 10 (ie: 1)). As of right now, I have my code, somewhat mixed with your code (I gave credit, don't worry), mixed in with some errors... A little help please?
IsVarious IsVarious

2012/5/24

#
I would take a look at this project, it's pretty much exactly what you want, and you can customize it a lot. http://www.greenfoot.org/scenarios/4114 I used it for our final project, and it worked nicely.
danpost danpost

2012/5/24

#
The bar class code was not meant to be edited. Everything, and I mean everything, that you could possibly do to it has a method call to do it (if there is something you think I missed, let me know, and I will rectify it). What exactly are you trying to add or change in the bar class? Maybe, you should post the bar class code, as it is right now, here.
You need to login to post a reply.