Limited Size HP bar help [solved]

Non-platform specific questions.

Limited Size HP bar help [solved]

Postby Hblade » Thu Dec 20, 2012 3:28 am

Yes. AGAIN lol, I'm asking this same question for probably the third time. (This is what I get for not using GE in a while hehe). Basically I have a fixed-width canvas, I don't want it to get any bigger or smaller but I want it to be able to "draw" an HP bar. I got the bar drawing but how can I make it equal to the players HP again?
Code: Select all
int i;
erase(0, 0, 0, .5);
for(i=0;i<width;i++){
    setpen(255, i, 0, 0, 1);
    moveto(i, 0);
    lineto(i, height);
                    }


This is a small peice of code for an example, this draws an HP bar but when the HP is full, no matter how large or small I want it to stretch to the size of the canvas instead of increasing in size.

I wont forget again I PROMISE LOL
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: Limited Size HP bar help

Postby skydereign » Thu Dec 20, 2012 3:33 am

This has to do with percents. You know the max width of the bar, so you just multiply it by the percent of hp (remember, max health is 100% hp, and lowest health is 0%). width*1.0 will represent the full width, while width*0.0 will still equal 0.
Code: Select all
int hp_dist = ((float)hp/max_hp)*width;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Limited Size HP bar help

Postby Hblade » Thu Dec 20, 2012 3:34 am

Thanks again sky! Sorry for any inconvenience hehe

Edit:
Code: Select all
int i;
int hp_dist = (float)(hp/maxhp)*width;
erase(0, 0, 0, .5);
for(i=0;i<hp_dist;i++){
    setpen(255, i, 0, 0, 1);
    moveto(i, 0);
    lineto(i, height);
                    }


This for some reason isn't working, yet the text over the hp bar says "50/100"


Edit:
I also fail to see how hp/maxhp could result in anything -BUT- 0. Even as a float, it still returns a value of 0 when I debug using
Code: Select all
sprintf(text, "%f", (hp/maxhp)*HP_BAR.width);



Edit: fixed. thanks sky
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


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron