Percentage Explanation, please?

Non-platform specific questions.

Percentage Explanation, please?

Postby Hblade » Mon Dec 19, 2011 10:18 pm

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?
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: Percentage Explanation, please?

Postby skydereign » Mon Dec 19, 2011 10:24 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Percentage Explanation, please?

Postby Hblade » Tue Dec 20, 2011 3:19 am

Thank you very very much!
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: Percentage Explanation, please?

Postby Hblade » Tue Dec 20, 2011 3:31 am

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
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: Percentage Explanation, please?

Postby skydereign » Tue Dec 20, 2011 3:46 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Percentage Explanation, please?

Postby Hblade » Tue Dec 20, 2011 3:50 am

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 ;)
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: Percentage Explanation, please?

Postby SuperSonic » Tue Dec 20, 2011 4:36 am

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 :lol:
No offense to you Hblade of course =D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Percentage Explanation, please?

Postby Hblade » Tue Dec 20, 2011 5:25 am

lol sorry guys xD
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: Percentage Explanation, please?

Postby lcl » Tue Dec 20, 2011 9:05 am

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 :lol:
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.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Percentage Explanation, please?

Postby Hblade » Tue Dec 20, 2011 2:18 pm

Where should I place the brackets? Oh and None taken LCL XD
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: Percentage Explanation, please?

Postby foleyjo » Tue Dec 20, 2011 2:33 pm

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 
}
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Percentage Explanation, please?

Postby SuperSonic » Tue Dec 20, 2011 2:36 pm

Yeah, me too :D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Percentage Explanation, please?

Postby Hblade » Tue Dec 20, 2011 2:40 pm

xD Alrighty, traditional it is :3
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: Percentage Explanation, please?

Postby lcl » Tue Dec 20, 2011 2:44 pm

Hblade wrote:xD Alrighty, traditional it is :3

Woohoo the old Hblade has returned! xDD
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Percentage Explanation, please?

Postby Hblade » Tue Dec 20, 2011 2:57 pm

xDD
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