Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Health Coding  (Read 2792 times)

0 Members and 1 Guest are viewing this topic.
Health Coding
« on: May 12, 2013, 02:20:13 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 32
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...
« Last Edit: May 12, 2013, 02:22:11 am by NaviSaysHEY »
Logged
Re: Health Coding
« Reply #1 on: May 12, 2013, 03:38:43 am »
  • The devil in the mirror.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 238
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.

Logged
Working on my Masters Degree in Computer Science.
Hey look, Zelda Coop....later.
Proud user of C++ for 9 years, and counting!
Re: Health Coding
« Reply #2 on: May 12, 2013, 03:41:45 am »
  • :D
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 151
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.
Logged
  • Knighty Games
Pages: [1]   Go Up

 


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



Page created in 0.047 seconds with 44 queries.