The first custom contact logic is player damage. We will assign the player health points and take them away when damaged. The game will end when the player runs out of health. This is one of the core mechanics of our gameplay. Follow these steps to implement the health logic:
Player.swiftfile, add six new properties to the
// The player will be able to take 3 hits before game over: var health:Int = 3 // Keep track of when the player is invulnerable: var invulnerable = false // Keep track of when the player is newly damaged: var damaged = false // We will create animations to run when the player takes // damage or dies. Add these properties to store them: var damageAnimation = SKAction() var dieAnimation ...