Users browsing this thread: 1 Guest(s)
PBG's ADVENTURE! (Yeah!)
#4
Are you unsure of of to set up the code for a health system, or just specifically rendering hearts appropriately?

How do you track the current health? Since each heart has a smallest value of 1/4, you can use integers to represent health. For every 4 whole numbers, you have 1 whole heart. Doing this makes it easier to render than using decimal numeric types and comparing decimal values like .25, .5, .75, etc. You can use the % (remainder) operator like so:

wholeHearts = totalHealth / 4; //integer math, so 3/4 = 0 whole hearts.
fractionalHearts = totalhealth % 4; //Ex) 5 % 4 = 1, 4 % 4 = 0, 3 % 4 = 3

For the fractionalHearts, you render whatever sprite represents the fraction, 1 -> 1/4, 2 -> 1/2, 3 -> 3/4.

To render new rows of hearts, you can probably iterate over all your hearts when rendering while tracking the total. If the total is greater than the max row size, then you reset the render position and offset in the YAxis.
Animations - MFGG TKO (scrapped) - tFR
[Image: QUmE6.gif]
"It feels that time is better spent on original creations" - Konjak
Focus on the performance, the idea, not the technical bits or details - Milt Kahl
Reply
Thanked by: Joxon


Messages In This Thread
PBG's ADVENTURE! (Yeah!) - by Joxon - 08-17-2015, 12:12 AM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-18-2015, 07:18 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-29-2015, 08:38 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-29-2015, 09:55 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-29-2015, 10:12 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-29-2015, 10:56 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 12:36 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 02:28 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 02:47 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 03:16 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 03:23 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 03:36 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 03:38 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 04:08 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 04:18 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 04:43 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 04:55 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 04:57 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 05:30 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 07:49 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 07:52 PM
RE: PBG's ADVENTURE! (Yeah!) - by TheShyGuy - 08-30-2015, 07:59 PM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 08-30-2015, 08:05 PM
RE: PBG's ADVENTURE! (Yeah!) - by Silversea - 09-04-2015, 12:20 AM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 11-04-2015, 09:27 AM
RE: PBG's ADVENTURE! (Yeah!) - by Joxon - 11-07-2015, 11:14 AM

Forum Jump: