Page 1 of 1

Health bar calculation

PostPosted: Sun Aug 21, 2011 10:48 pm
by mcavalcanti
Hi, guys. I saw something about it in the forum, but I cant' find.

I have enemies with different life values (life=100; life=400; life=600) and my healthbar animation has 10 positions. But, to become more realistic, I would like to avoid this simple code:

hp-=10;
enemy.animpos=hp;

What could be a right calculation? Thanks.

Re: Health bar calculation

PostPosted: Mon Aug 22, 2011 7:18 am
by schnellboot
if life is 100 then enemy.animpos=hp/10;
if life is 400 then enemy.animpos=hp/40;
and so on

Re: Health bar calculation

PostPosted: Mon Aug 22, 2011 12:23 pm
by mcavalcanti
Hmm... I think it is not working. :(
For now, I'm putting this on lifebar Draw script:

if(creator.hp==100) { animpos = 10; }
else { animpos = creator.hp/10; }


I would like to put the suggested calculation method in this code. :?

Re: Health bar calculation

PostPosted: Mon Aug 22, 2011 12:49 pm
by savvy
healthbar.animpos = (10/maxhp)*currenthp;

this should work...

savvy

Re: Health bar calculation

PostPosted: Mon Aug 22, 2011 1:43 pm
by mcavalcanti
Thanks, Savvy. I understood the calculation, but I'm getting the 'illegal division by zero' error. :?
Seens to be correct... (10/100)*50 = 5
But the error is occurring

Re: Health bar calculation

PostPosted: Tue Aug 30, 2011 12:10 pm
by mcavalcanti
Hello. Please, I still have doubt about this issue.

Re: Health bar calculation

PostPosted: Tue Aug 30, 2011 1:48 pm
by lcl
Show your exact code, please so I can help you :D