In this section, you'll make the player detect when it is hit by rocks, add an invulnerability feature, and end the game when the player runs out of lives.
Add an instance of the Explosion to the Player, as well as a Timer node (named InvulnerabilityTimer). In the Inspector, set the Wait Time of InvulnerabilityTimer to 2 and its One Shot to On. Add this to the top of Player.gd:
signal dead
This signal will notify the Main scene that the player has run out of lives and the game is over. Before that, however, you need to update the state machine to do a little more with each state:
func change_state(new_state):
match new_state:
INIT:
$CollisionShape2D.disabled = true
$Sprite.modulate.a = 0.5
ALIVE:
$CollisionShape2D.disabled = false
$Sprite.modulate.a = 1.0
INVULNERABLE:
$CollisionShape2D...