ZFGC

Resources => Coding => Topic started by: NaviSaysHEY on May 12, 2013, 02:20:13 am

Title: Health Coding
Post by: NaviSaysHEY on May 12, 2013, 02:20:13 am
Hello,

I'm trying to figure out how to code a health system just as in the zelda games where you have a heart comprised of four smaller bits. Ugh, how do I say this? Each heart can take four damage before a complete heart is lost - you know what I mean.

so, what I did so far was declare an array eg. Hearts[10] and an integer: int Heart=9; and had a function with something like this within it:

if(Hearts[Heart]==2 && Heart!=0)Heart--;
if(Hearts[Heart]<2)Hearts[Heart]++;

Actually, each heart in my game can take 2 damage.

Does anyone have any suggestions on how I can make this better? Like, how take away so many hearts at a time?
I'm not sure if I saw any tutorial on how to do this...
Title: Re: Health Coding
Post by: wildex999 on May 12, 2013, 03:38:43 am
Instead of trying to store hearts as hearts and heart pieces, store heart pieces only.

so
heartpieces = 10;
maxheartpieces = 10;

And then in rendering you split the pieces into full hearts and heart pieces.

fullhearts = heartpieces % 2; //for 2 pieces per heart % 4 for 4 pieces per heart etc.
if(fullhearts*2 != heartpieces)
 //Then you got one heart that has missing pieces.

Title: Re: Health Coding
Post by: Knighty on May 12, 2013, 03:41:45 am
Using an array like this to keep track of your health is a really confusing and bad idea.
Just use a single int. So if Hearts = 10 then you have five full hearts, if Hearts = 13 then you have 6 1/2 hearts, etc.

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved