Escape the Dungeon
Part of the Projects section of Coddy's Godot journey. Lesson 33 of 33.
The stairs in the far corner are the way out. They are an Area2D called Exit. When the hero steps on them, the player wins:
func _on_exit_body_entered(body):
$HUD/Message.text = "You Escaped!"
get_tree().paused = trueConnect it in _ready with the other signals. Enter starts a new game after a win too, since the restart only checks that the game is paused.
Play your dungeon. Then change it: add a second guard, move the walls, or hide the key somewhere harder.
Challenge
EasyIn main.gd, connect $Exit.body_entered to a function that shows You Escaped! in $HUD/Message and pauses the game.
Try it yourself
extends Node2D
var has_key = false
var health = 3
func _ready():
$Key.body_entered.connect(_on_key_body_entered)
$DoorZone.body_entered.connect(_on_door_zone_body_entered)
$Enemy.body_entered.connect(_on_enemy_body_entered)
func _process(delta):
if get_tree().paused and Input.is_action_just_pressed("action"):
get_tree().paused = false
get_tree().reload_current_scene()
func _on_key_body_entered(body):
has_key = true
$Key.queue_free()
$HUD/KeyIcon.visible = true
func _on_door_zone_body_entered(body):
if has_key:
$Door.queue_free()
$DoorZone.queue_free()
func _on_enemy_body_entered(body):
health -= 1
$HUD/Hearts.get_child(health).visible = false
$Hero.flash()
if health == 0:
$HUD/Message.text = "Game Over"
get_tree().paused = true
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Projects
1Project: Breakout
Breakout PaddleKeep the Paddle on Screen4Project: Dungeon Crawler
Walk the DungeonPick Up the KeyPractice on your own: Godot playground