This post is about how I made my health system in Playdate Pulp. So I first made a design for the hearts which was just a full heart a half heart and an empty heart. The event declaration is on draw, draw requests that a certain tile change to another tile. You can set a max health which in my game is 20. Then there is a heart count variable which starts at zero. Now here the actual code is.

All of it is contained in a while event, and the idea is that we want this while event to continue drawing hearts until the hearts are equal to the amount of health we want. So while the heart count which is zero is less than twenty add two to the heart count (that would be a full heart no two hearts since each number in max health is half a heart). This loop will run 2,4…18,20 till it has made 20 half hearts. now we create a variable heart swap which is equal to the empty heart design. Now we want to be able to display the hearts on the top of the screen. 

We can calculate this by dividing heart count by two but that would mess up our heart count and it would be faulty so we make a new variable heartX and make it equal to heart count, then divide that by two. We tell heartX,0 to swap to heart swap so now we are drawing X amount of empty hearts. now we need to make them full and half hearts.

We do this by making an if event, if health>heart count then our variable from before heart swap is equal to a full heart. This is fine except if we have a half heart our health will be equal to three and our heart count is equal to two so it still works and it draws a full heart. To make this work we create a new variable half heart. Half heart is = to our health. Then we compare the half heart with heart count then inside the if we minus one from half heart. If half heart is now equal to heart count we know that it should have been a half heart and set heart swap to a half heart otherwise we continue and make it a full heart. That is the health system, now how you take damage.

I just made it a simple function when something damages you, in their code they say tell event.player to do the damage function and they set the damage to whatever they want it to be. When the function on the player runs it first checks if a shield was used(In my game there is a shield) if not it subtracts the damage from your health, makes a sound, and shakes the screen. It finally checks if you have more than zero health and if you do it says “You died!” and then sends you back to the start. The only other thing that I did was make sure you could only get damaged once every half second so you wouldn’t get camped by some glitched enemy.

Thank You for reading!