Reach the Goal
Part of the Game Rules section of Coddy's Godot journey. Lesson 22 of 29.
A game you can lose needs a way to win. Often it is a place, like a flag at the end of a level.
The flag here is an Area2D called Goal. When a body walks in, it sends body_entered with that body. The player is in the player group, so the goal can tell it apart from other bodies:
func _on_goal_body_entered(body):
if body.is_in_group("player"):
$HUD/Message.text = "You win!"The HUD has an empty Message label across the middle of the screen.
Challenge
EasyWalk to the flag to win:
- In
_ready(), connect$Goal.body_enteredto_on_goal_body_entered. - In
_on_goal_body_entered(body), when the body is in theplayergroup, set$HUD/MessagetoYou win!.
Try it yourself
extends Node2D
func _ready():
pass
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