Menu
CoddyTech

Game Over

Part of the Game Rules section of Coddy's Godot journey. Lesson 12 of 29.

The HUD has a big GameOver label in the middle of the screen. Its visible is off in the scene, so it starts hidden.

After a life is lost, check whether any are left:

if lives == 0:
	$HUD/GameOver.visible = true

Two equals signs compare. lives == 0 asks whether lives is 0. One equals sign sets a value, and Godot does not allow it inside an if.

challenge icon

Challenge

Easy

In _on_player_hurt(), after the label is updated, show $HUD/GameOver when lives is 0.

Try it yourself

extends Node2D

var lives = 3

func _ready():
	$HUD/Lives.text = "Lives: %d" % lives
	$Player.hurt.connect(_on_player_hurt)

func _on_player_hurt():
	lives -= 1
	$HUD/Lives.text = "Lives: %d" % lives
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Game Rules

Practice on your own: Godot playground