Ending the game
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
scene to the Player
scene and uncheck its Visibility property. Also add a Timer
node named InvulnerabilityTimer
and set Wait Time to 2
and One Shot to “on.”
You’ll emit the dead
signal to notify Main
that the game should end. 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.set_deferred("disabled", true) $Sprite2D...