Zelda Health Bar

You must understand the Game Editor concepts, before post here.

Zelda Health Bar

Postby DrakeStoel » Fri Oct 05, 2012 4:57 am

I'm making a Zelda-esqu game and am having trouble figuring out the health bar. I want it to be just the same as the original, full hearts and half hearts. Another tricky part is when the health bar is extended. I understand that I'd need different animations for the health bar, but other than that... I'm very unclear on how...
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: Zelda Health Bar

Postby skydereign » Fri Oct 05, 2012 5:40 am

The way I'd suggest is to create one actor with a heart animation, with the 5 frames (or more since you want the white outlined hearts). From there, you'll need 20 of them (if you want you can create them from the editor, but I'd recommend creating it through code). Something like this.
view -> Create Actor -> Script Editor
Code: Select all
int i, j;

for(j=0;j<2;j++)
{
    for(i=0;i<10;i++)
    {
        CreateActor("heart_disp", "full_heart", "view", "(none)", 30+i*20, 30+j*20, true);
    }
}


Now these won't act quite as a conventional hp bar because it is 20 different actors. But using division you can set it up to still work. This might not make sense at first glance, but if you write out the hp values each actor have, and their cloneindexes, the (hp-1)/4 becomes pretty obvious.
heart_disp -> Draw Actor -> Script Editor
Code: Select all
if((hp-1)/4 == cloneindex)
{ // hp value at this heart
    animpos = hp-cloneindex*4;
}
else if(hp>(cloneindex+1)*4)
{ // greater than current heart's max
    animpos = 4;
}
else
{ // less than this heart's min
    animpos = 0;
}


Now you'll need to prevent hp from ever increasing beyond the max (full_hearts*4), as well as make sure the hearts won't display if they aren't yet obtained. But that should be just a matter of putting in an if statement to set the transp or visibility state. If you want me to elaborate on any of this, feel free to ask.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Zelda Health Bar

Postby DrakeStoel » Fri Oct 05, 2012 5:57 am

Honestly, all I'll understood from that is that I need to make 18 actors, one for each heart (my game has only 18 hearts), and give them the animation of full, half full, and empty? Is that about right? Other than that... a bit of explanation would be nice
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: Zelda Health Bar

Postby skydereign » Fri Oct 05, 2012 6:09 am

You'll need a heart actor with an animation that has 5 frames (one for each quarter heart and empty). You'll need your hp variable (in the code I gave I just had it named hp). In the heart display's create actor you'll need to change the animation state to stopped. But that's pretty much it for displaying the proper hp via hearts. In the end you'll need variables for hp, max hp, and double hp (if you want the white outlined hearts). Each time you complete a new heart, you'd of course increase max hp by 4, and so on for any other interaction.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Zelda Health Bar

Postby DrakeStoel » Fri Oct 05, 2012 6:45 am

Ok, I got most of it. I'm just unsure on how I would have my actor lose health. I know it would be in a collision with an enemy or hazard, but would I just write a script to subtract x amount from the hp variable?

EDIT: Also, I stated before that I only have full and half hearts, so my animation is only 3 frames. How would I change this script to fit those needs?
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: Zelda Health Bar

Postby master0500 » Fri Oct 05, 2012 7:15 am

yup, hp=hp-1; or something like that and link it to animIndex
master0500
 
Posts: 409
Joined: Sun Jun 26, 2011 9:42 pm
Score: 27 Give a positive score

Re: Zelda Health Bar

Postby skydereign » Fri Oct 05, 2012 4:46 pm

DrakeStoel wrote:EDIT: Also, I stated before that I only have full and half hearts, so my animation is only 3 frames. How would I change this script to fit those needs?

Oh, didn't realize you said the original. Just change 4 to 2 in the script. Four was the max hp if you had four quarter hearts, and two is the max if you have two halves.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Zelda Health Bar

Postby DrakeStoel » Fri Oct 05, 2012 6:29 pm

Ok, so is that ALL the 4s are changed to 2s? And I'm not quite clear on how to add or subtract hearts, and what division you were talking about, or really how to get the hp value to drop properly
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: Zelda Health Bar

Postby skydereign » Fri Oct 05, 2012 6:50 pm

DrakeStoel wrote:Ok, so is that ALL the 4s are changed to 2s?

Right.

DrakeStoel wrote: And I'm not quite clear on how to add or subtract hearts

skydereign wrote:Now you'll need to prevent hp from ever increasing beyond the max (full_hearts*4), as well as make sure the hearts won't display if they aren't yet obtained. But that should be just a matter of putting in an if statement to set the transp or visibility state.

Essentially create them all at the beginning, and don't display the ones that the player hasn't gotten.

DrakeStoel wrote: and what division you were talking about

I mentioned division because I assumed you wanted to know how it works, and by dividing hp-1 by the max each heart can hold (2 hp), the game can know if the heart is the one that needs to have a fractional heart.

DrakeStoel wrote:or really how to get the hp value to drop properly

Do you know how to use variables? If so, that is all it takes. Increase and decrease it as you would a normal variable. The only thing to watch out for is never increase it over the max hp value, and you shouldn't decrease it beyond zero.

To make this easier, here is a small example of it. Up and down increases and decreases the max hp (number of hearts). Left and right increases/decreases hp by one. Space will set hp to the current max.
Attachments
zelda_hp.zip
(19.9 KiB) Downloaded 172 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Zelda Health Bar

Postby DrakeStoel » Fri Oct 05, 2012 7:30 pm

Oh! Ok. Everything makes sense now! There's just one problem. For some reason the sprites aren't showing up when I try to run my game

EDIT: Never mind! I forgot that they all started as transparent :oops:
I got it all figured out! Thanks for all your help
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron