healthBar

Non-platform specific questions.

healthBar

Postby raminkhan » Fri Dec 23, 2011 5:00 am

how can I make a auto filler health bar. I mean when I hit my character, the health decreases but when i don't hit him I want his health to increase automatically how?
raminkhan
 
Posts: 63
Joined: Mon Sep 12, 2011 3:35 pm
Score: 0 Give a positive score

Re: healthBar

Postby Hblade » Fri Dec 23, 2011 5:32 am

In draw actor of the player, have this somewhere

Make a variable called "timer" and do this
Code: Select all
timer++;
if(timer>=30 && HP<50) // 1 second, 50 is max HP limit
{
    HP++;
    timer=0;
}


Every 1 second HP will go up by 1.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: healthBar

Postby phyzix5761 » Fri Dec 23, 2011 1:03 pm

Great simple code Hblade. Raminkhan, just make sure your game speed is 30 frames per second in order for the health to regenerate 1 point per second.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: healthBar

Postby lcl » Fri Dec 23, 2011 1:33 pm

Hblade, better to use real_fps instead of 30.
So the code would be:
Code: Select all
timer++;
if(timer>=real_fps && HP<50) // 1 second, 50 is max HP limit
{
    HP++;
    timer=0;
}

:D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: healthBar

Postby Hblade » Fri Dec 23, 2011 3:13 pm

Ahh yes :) I forgotz about that.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: healthBar

Postby raminkhan » Sat Dec 24, 2011 6:29 am

but I dont get it, timer++ why do i need to make this variable? what is this variable? and how would this code load my individual health pieces which makes up a full health bar?


lcl wrote:Hblade, better to use real_fps instead of 30.
So the code would be:
Code: Select all
timer++;
if(timer>=real_fps && HP<50) // 1 second, 50 is max HP limit
{
    HP++;
    timer=0;
}

:D
raminkhan
 
Posts: 63
Joined: Mon Sep 12, 2011 3:35 pm
Score: 0 Give a positive score

Re: healthBar

Postby skydereign » Sat Dec 24, 2011 8:29 am

The timer variable is what makes sure this increasing of hp only occurs once a second. All the variable does is increase to some value, and then increase hp, while setting it back to zero. If you look at the if statement, that's all it does (because it is in draw, it just repeats over and over). Now, how are you displaying hp? It sounds like you are using individual actors, in which case I'd suggest you not. It gets more complex if you do that, while the idea behind using an animation is much easier.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest