Health bar calculation

Non-platform specific questions.

Health bar calculation

Postby mcavalcanti » Sun Aug 21, 2011 10:48 pm

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.
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Health bar calculation

Postby schnellboot » Mon Aug 22, 2011 7:18 am

if life is 100 then enemy.animpos=hp/10;
if life is 400 then enemy.animpos=hp/40;
and so on
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Health bar calculation

Postby mcavalcanti » Mon Aug 22, 2011 12:23 pm

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. :?
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Health bar calculation

Postby savvy » Mon Aug 22, 2011 12:49 pm

healthbar.animpos = (10/maxhp)*currenthp;

this should work...

savvy
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: Health bar calculation

Postby mcavalcanti » Mon Aug 22, 2011 1:43 pm

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
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Health bar calculation

Postby mcavalcanti » Tue Aug 30, 2011 12:10 pm

Hello. Please, I still have doubt about this issue.
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Health bar calculation

Postby lcl » Tue Aug 30, 2011 1:48 pm

Show your exact code, please so I can help you :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest