Page 1 of 1
Percentage Explanation, please?
Posted:
Mon Dec 19, 2011 10:18 pm
by Hblade
I've asked this before, but now I'm actually ready to "Pay Attention". How would one go about making an HP bar but keep it's width solid and yet still be able to gain HP? Example, the start off HP is 100, but the HP Bar is 200Pixels. And never changes. How would I keep the HP bar 200 pixels even if the HP is 9999? and still go down slowly until it reaches 0?
Re: Percentage Explanation, please?
Posted:
Mon Dec 19, 2011 10:24 pm
by skydereign
If you have a fixed width, so a canvas's width, then the full width is 100% hp. Completely empty is 0%. Half of it, 50%. That's pretty straightforward, so, all you need is to multiply the width by the percent of hp, which can be obtained by hp/maxhp. If you make maxhp a variable, you can increase the player's maxhp at any time.
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 3:19 am
by Hblade
Thank you very very much!
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 3:31 am
by Hblade
Actually I'm still confused. What I currently have is:
- Code: Select all
void Draw(int R, int G, int B, double TRANS, double VAR) {
int i, i2;
erase(0, 0, 0, 1); //Empty the canvas
setpen(R,G,B,TRANS,1);
for(i2=0;i2<250;i2++){
setpen(0, 0, 0, 0, 1);
moveto(i2, 0);
lineto(i2, 12);
}
for(i=0;i<VAR;i++) {
moveto(i, 0);
setpen(R+(255/250), G+(255/250), B+(255/250), TRANS, 1);
lineto(i, 12);
}
}
And 3 variables
HPX
MAXHP
LENGTH
I tried:
- Code: Select all
LENGTH=(HPX/MAXHP);
but that bugged out and only made 1 pixel line. I have:
- Code: Select all
Draw(150, 0, 0, 0, LENGTH);
EDIT:
I tried
- Code: Select all
LENGTH=(HPX/MAXHP)*250;
Which 250 is the width. now it just teleports to 0 o-o
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 3:46 am
by skydereign
Made a few optimizations, and since I honestly can't stand your bracket placement I changed that as well.
- Code: Select all
void
draw (int R, int G, int B, double TRANS, double VAR)
{
int i;
erase(0, 0, 0, 1); //Empty the canvas
setpen(R,G,B,TRANS,1);
setpen(0, 0, 0, 0, 1);
for(i=0;i<12;i++)
{
moveto(0, i);
lineto(250, i);
}
setpen(R+(255/250), G+(255/250), B+(255/250), TRANS, 1); // what?
for(i=0;i<12;i++)
{
moveto(0, i);
lineto(VAR, i);
}
}
Using, width*HPX/MAXHP should work.
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 3:50 am
by Hblade
Hahaha, sorry about that. I always seem to make messy code.
Thanks again, and "what?" I was trying to make it get lighter color for a gradiented look. >.> Again, a fail on my part.
Edit:
Oh god yes! It works!
Thanks a billion. now only to find out the color gradient
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 4:36 am
by SuperSonic
skydereign wrote:and since I honestly can't stand your bracket placement I changed that as well.
Haha yes. I get really annoyed when I see people online put there brackets like that
No offense to you Hblade of course =D
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 5:25 am
by Hblade
lol sorry guys xD
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 9:05 am
by lcl
SuperSonic wrote:skydereign wrote:and since I honestly can't stand your bracket placement I changed that as well.
Haha yes. I get really annoyed when I see people online put there brackets like that
No offense to you Hblade of course =D
Same. For example, DST has done many great things but I can't understand the code because of how he places the brackets. It makes it very hard to understand where the brackets start and end.
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 2:18 pm
by Hblade
Where should I place the brackets? Oh and None taken LCL XD
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 2:33 pm
by foleyjo
I use this method
- Code: Select all
statement //The bit of code above the bracket
{
code //indented to make it easier to keep track of
}
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 2:36 pm
by SuperSonic
Yeah, me too
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 2:40 pm
by Hblade
xD Alrighty, traditional it is :3
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 2:44 pm
by lcl
Hblade wrote:xD Alrighty, traditional it is :3
Woohoo the old Hblade has returned! xDD
Re: Percentage Explanation, please?
Posted:
Tue Dec 20, 2011 2:57 pm
by Hblade
xDD