- Home /
Health System?
I know this is a pathetic noob question, but basically I have a system in my game where you start out with 3 hearts, and if you die, you lose one. Would there be an easier way other than a crapload of If statements on how to implement this? Currently, I'm thinking of having 'Heart1', 'Heart2', and checking for conditions on how many hears the player has, but there must be a simpler way... (And I'm using Javascript rather than C#).
Answer by WilliamLeu · Nov 19, 2013 at 08:10 PM
Have an integer with how many hearts the player has. When the player dies, decrement the heart count and check if the new heart count is non-zero or not.
If you need additional per-heart information, create a container (a list or whatever JS has for dynamic arrays) of "hearts". Pop a heart from the container when they die. Check if the container is empty if you want to see if they're out of hearts.