I am trying to make a system that shows 3 health icons (hearts in this instance). When the player is hit it'll remove the furthest right icon until they are all gone.
Then, if you pick up a new health heart in the level I want to add a new heart up to the maximum of three.
I can get the health removing itself in a brute force method by manually assigning each heart a specific number (0,1,2) to coincide with the players health. But can't reverse the process when you pick up more health. So far I do this:
- when health = 2
- play the animation for heart 2 disappearing
But what do I do when I pick up more health, how do I say, health was 1, and now it's 2 so play the animation for heart 2 appearing.
I wanted to use a for each loop, and number them based on the sprite.x position but I couldn't get that working. I'm keen to learn to do things programmatically rather than brute force every time :)
Any ideas on the logic I should be using?