Page 1 of 1

Limited Size HP bar help [solved]

PostPosted: Thu Dec 20, 2012 3:28 am
by Hblade
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

Re: Limited Size HP bar help

PostPosted: Thu Dec 20, 2012 3:33 am
by skydereign
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;

Re: Limited Size HP bar help

PostPosted: Thu Dec 20, 2012 3:34 am
by Hblade
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