Page 1 of 1

Canvas HP bar with gradients! version 2

PostPosted: Sun Dec 06, 2009 2:21 pm
by Hblade
Version 2:

Hello everyone, this is version 2 of my gradient HP bar :D
New features from version 1:
Color change,
a gray bar that represents your max hp that hides behind your current HP
CONTROLES: use the arrow keys to add / minus HP
(screenshot)
pic1x.png

pic2x.png

pic3x.png

Like the last version, no images are needed, so you dont have to worry about making tons of images for an hp bar :D
CONTROLES: Use the arrow keys to add / minus HP.
Gradient HP bars version 2.zip
(1.38 KiB) Downloaded 172 times

Here's the code for version 2:
Code: Select all
for (i2=0; i2<maxhp; i2++)
{
    setpen(69, 69, 69, 0, 3);
    moveto(i2, 0);
    lineto(i2, height-1);
    i2++;
}
for (i=0; i<hp; i++)
{
    for (gradl=0; hp>gradl; gradl++)
    {
    setpen(gradl, hp+gradl, 255, 0, 3);
    moveto(i, 0);
    lineto(i, height-1);
    i++;
    }
}

NOTE:
Your canvas can go all the way across the screen but it wont change the gray bar, You have to set the max hp and the normal hp in create actor. Look inside the GED file for more information :D

Old Version:
Hello, I made an H P bar that can be used for many games and it's not 1 solid color, it's a gradient and requires no images! It's all done by canvas.
Code: Select all
for (i=0; i<hp; i++)
{
    for (gradl=0; hp>gradl; gradl++)
    {
    setpen(gradl, hp, 255, 0, 3);
    moveto(i, 0);
    lineto(i, height-1);
    i++;
    }
}


Here's a few screenshots
p1.png

p2.png


Here's the GED file. Likewise, no data folder needed :)
Gradient HP bars.zip
(1.22 KiB) Downloaded 128 times


CONTROLES:
Use the left and right keys to make the hp bar bigger / smaller

Re: Canvas HP bar with gradients! version 2

PostPosted: Sun Dec 06, 2009 8:04 pm
by Scorpion50o1
Nice I think i could really use this and it looks cool , but how do i keep from going to far? Does it go on and on and on? 8)

Re: Canvas HP bar with gradients! version 2

PostPosted: Sun Dec 06, 2009 8:07 pm
by Hblade
Version 2 fixes that. WHen your adding / subtracting the HP, instead of putting hp-=6 or something, you would put this:
Code: Select all
if (hp>0)
{
hp-=6;
}

And for adding HP via item or something you picked up,
Code: Select all
if (hp<maxhp)
{
hp+=50;
}

Where 50 is your item's recover rate or what ever :D

Then if you have like 45 / 50 HP, and you heal with 50 HP, to stop it from having 95 / 50 HP, make this code in the draw actor of your player
Code: Select all
if (hp>maxhp)
{
hp = maxhp;
}

The same with if you have 3 HP left, and someone does 40 damage, use this code:
Code: Select all
if (hp<0)
{
hp = 0;
}


But you wont even see it go pass 0 :D
Theres also more advanced methods I could explain if you want me to.

Re: Canvas HP bar with gradients! version 2

PostPosted: Sun Dec 06, 2009 8:10 pm
by DST
Nice work, but since you have the erase being sent on the keydown (or player collision), why not send the draw then too? You can save a lot of cpu that way. Just remove canvas>draw actor alltogether.

Re: Canvas HP bar with gradients! version 2

PostPosted: Sun Dec 06, 2009 8:12 pm
by Hblade
OH! LOL i put it in the wrong spot last time - Thanks DST

Re: Canvas HP bar with gradients! version 2

PostPosted: Sun Dec 06, 2009 11:24 pm
by makslane
Works great, congratulations.

Re: Canvas HP bar with gradients! version 2

PostPosted: Sun Dec 06, 2009 11:28 pm
by Hblade
Thanks :D