Making a Health Bar - Tutorial

Learn how to make certain types of games and use gameEditor.

Postby cyber ruler » Thu Aug 16, 2007 5:38 pm

I havn't used this kind of health bar in a while, so I may be a little off with this explanation.

Notice how there are 3 sections of the coding. Update health bar, change health, and set health.

Updatehealthbar: doesn't do much.

changehealth: put it in script editor when you want to add or subtract health. put ChangeHealth(*) but instead of the star, put a posotive number to add that much to the healthbar, or a negative to subtract it.

Sethealth: put it in script editor when you want to set exactly how much health you want to have at the time. use SetHealth(*) but instead of the star, put the amount of health you want the actor to have.

you will also have to put stuff in like (and some1 plz correct me if I did this wrong)
Code: Select all
if (g_PlayerHealth <= 0)
{
    ***
}

put in place of the star what you want to happen when the health bar is empty
cyber ruler
 
Posts: 52
Joined: Sat Apr 28, 2007 7:59 pm
Location: Je ne parle englais : /
Score: 0 Give a positive score

Postby automail10 » Thu Aug 16, 2007 8:36 pm

isn't this an old topic?
Back
User avatar
automail10
 
Posts: 280
Joined: Sun Jun 03, 2007 11:30 pm
Location: On a pancake on a bunny.
Score: 5 Give a positive score

Re: Making a Health Bar - Tutorial

Postby TheVoiceInMyHead » Mon Apr 13, 2009 4:27 pm

Hello There,

Well... newbie here - i'm sorry for digging such an old post but i've really been trying to put this to work for hours!

So, I followed the tutorial as I do a C/C++ background it was fairly easy to understand what the functions were doing.
Symptoms:
- In the CreateActor of my HealthBar actor i put: SetHealth(10);
Perfect, it works! (it did change the initial text that I put 00 to 10)

- Now in the collision event of a harmful actor I wrote code to destroy the harmful actor, create another actor for explosion aaaannnd ChangeHealth(-1)
Guess what?! the harmful actor is destroyed, the explosion is created but no change in my health bar!

Other info:
- I created a test actor to hold my player's health (g_PlayerHealth) and something really odd happened: If I attempt to update this actor TextNumber in an event (such as the above collision) it works just fine!
Buuuuut
if I attempt to update its textNumber inside any of the 3 functions that I did put in Global Code guess what?! It doesn update the textNumber...
It's like if the functions could be called only once (in the CreateActor of the health bar) and no more after that

Has anybody got any clue of what is going on?

Many Thanks!
TheVoiceInMyHead
 
Posts: 1
Joined: Sun Mar 15, 2009 7:15 pm
Score: 0 Give a positive score

Re: Making a Health Bar - Tutorial

Postby DST » Mon Apr 13, 2009 8:03 pm

This is more of a scripted c healthbar; Its how you would make one if you weren't using ge.

Ge has so many shortcuts for things, you can easily just report health as a global array, or send health to the text actor.

textNumber=actorname.health; etc. etc. There are lots of simple health bars in ge.

If you're just messing with it for fun, then whatever.

If you're trying to make better health bars, check these topics:

viewtopic.php?f=6&t=5756

viewtopic.php?f=6&t=6335

viewtopic.php?f=6&t=6360
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Making a Health Bar - Tutorial

Postby jimmynewguy » Mon Apr 13, 2009 9:20 pm

oh, about the tower defense one. Is there anyway to edit that code to make it where it works when the view is moving?
i'm sure it's something simple im over looking......thnx in advanced anyone :)
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Making a Health Bar - Tutorial

Postby sillydraco » Tue Apr 14, 2009 1:48 am

MOVED
Last edited by sillydraco on Tue Apr 14, 2009 2:08 am, edited 1 time in total.
Time for sleepy, dream of new things...new life, new reality, new wings.
Image
User avatar
sillydraco
 
Posts: 71
Joined: Fri Apr 03, 2009 7:54 am
Score: 3 Give a positive score

Re: Making a Health Bar - Tutorial

Postby DST » Tue Apr 14, 2009 1:50 am

xscreen
yscreen
screen_to_actor
actor_to_screen

Use these along with a canvas that moves along with view to translate from global x to screen x.

This would be good too, moving the canvas along with view, as then the canvas won't need to render anything that isn't on screen to begin with.

You can look those up in the script reference, using them to modify the draw shouldn't be difficult.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Making a Health Bar - Tutorial

Postby sillydraco » Tue Apr 14, 2009 2:09 am

i'm working on a health bar atm ( viewtopic.php?f=6&t=6659&p=47716#p47716 ) but im having some trouble with the code :/ i know whats wrong with the code, i just dont know how to fix it!

i have the code set to if the animation is HP100, then it changes the animation to HP90, and 90 to 80, and so forth. then when its HP10, it changes the animation of the character to Splode (three guesses as to what that means!). i have the character set to destroy itself when the animation ends. yet when the character takes damage, it goes to HP90 and the character goes to splode, but thats it! i think the if code is going into a loop instead of only doing one :3


EDIT: i fixed it! i had one too many } between the Else statements :3 heres my code! i have ten animations, animindex 0-9, 0 being HP10 and 9 being HP100. going in increments of ten, being one box to ten full boxes. i made an activation event (collide finish with enemy) from my character to the health bar, and this script whenever i collide with the enemy. it just checks what animation the health bar is on, then puts it to one less. also i put a changeanimation function at the beginning, so he does his little OMG animation whenever he gets hit. i might add another changeanimation for my character blowing up, then have an animationfinish event, to destroy the actor.

heres the code!

Code: Select all
ChangeAnimation("Draco", "hurt1", FORWARD);

if(animindex == 9)
{
    {
    ChangeAnimation("Health", "HP90", FORWARD);
    }
}


else
{
 if(animindex == 8) {
    ChangeAnimation("Health", "HP80", FORWARD); }

else
{
 if(animindex == 7) {
    ChangeAnimation("Health", "HP70", FORWARD); }


else
{
 if(animindex == 6) {
    ChangeAnimation("Health", "HP60", FORWARD); }

else
{
 if(animindex == 5) {
    ChangeAnimation("Health", "HP50", FORWARD); }


else
{
 if(animindex == 4) {
    ChangeAnimation("Health", "HP40", FORWARD); }


else
{
 if(animindex == 3) {
    ChangeAnimation("Health", "HP30", FORWARD); }


else
{
 if(animindex == 2) {
    ChangeAnimation("Health", "HP20", FORWARD); }


else
{
 if(animindex == 1) {
    ChangeAnimation("Health", "HP10", FORWARD); }


else
{
 if(animindex == 0) {
    ChangeAnimation("Health", "HP0", FORWARD); }
}}}}}}}}}
Time for sleepy, dream of new things...new life, new reality, new wings.
Image
User avatar
sillydraco
 
Posts: 71
Joined: Fri Apr 03, 2009 7:54 am
Score: 3 Give a positive score

Re: Making a Health Bar - Tutorial

Postby DST » Tue Apr 14, 2009 12:15 pm

Draco, you're doing it the ultra mega kamehameha hard way!

Don't use all those animations. Just pile them into one 10 frame animation.

then....are you ready for this?

healthmeter>draw actor>

Code: Select all
animpos=round(health/10);


or player.health if health is an actor variable.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Making a Health Bar - Tutorial

Postby sillydraco » Tue Apr 14, 2009 7:04 pm

OMG im retarded! x.x ah well, at least its working!
Time for sleepy, dream of new things...new life, new reality, new wings.
Image
User avatar
sillydraco
 
Posts: 71
Joined: Fri Apr 03, 2009 7:54 am
Score: 3 Give a positive score

Re: Making a Health Bar - Tutorial

Postby DST » Tue Apr 14, 2009 7:20 pm

Learning is fun!
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Making a Health Bar - Tutorial

Postby BlarghNRawr » Sat Apr 18, 2009 3:35 pm

only if its interesting
Download Game Music
current projects:
Bold! ?% Started mechanics
Unnamed puzzle game 60% --i need a name!--
User avatar
BlarghNRawr
 
Posts: 767
Joined: Wed Jun 25, 2008 12:36 am
Location: Not using G-E anymore. Now using Source SDK.
Score: 27 Give a positive score

Previous

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest