Life HUD
The life HUD will display the number of lives the player has left. We'll just do simple math to add life when a player collides with the life item, and subtract it when a player dies.
local life = 3
When a player hits the life item, the calculations are as follows:
life = life + 1
When s player dies, the calculations are as follows:
life = life – 1
Print the life count on screen using the following code:
love.graphics.print("Life: " life, 32, 32) love.graphics.setFont(medium)
Now let's insert this into our main chunk:
life = 3 ---when player picks life item function LifePick(v) v.picked = true LifePicked = true lifebar = lifebar + 1 end Now when player dies, update the Die() function: ---for now make the player re-spawn to position 32,32 on the tilemap when it dies. function Die() life = life - 1 player.l = 32 player.t = 32 end