Count Down
Part of the Game Rules section of Coddy's Godot journey. Lesson 23 of 29.
A countdown turns reaching the flag into a race.
It works like the clock from earlier, but it counts down. Keep the time left in a variable. Take one away each time the one second Clock runs out:
var time_left = 10
func _on_clock_timeout():
time_left -= 1
$HUD/Time.text = "Time: %d" % time_leftAlso show the time in _ready(), so the player sees Time: 10 before the first second passes.
Challenge
EasyAdd a ten second countdown:
- Add
var time_left = 10at the top, and showTime: 10on$HUD/Timein_ready(). - Connect
$Clock.timeoutto_on_clock_timeout. - In
_on_clock_timeout(), take one away fromtime_leftand show it.
Try it yourself
extends Node2D
func _ready():
$Goal.body_entered.connect(_on_goal_body_entered)
func _on_goal_body_entered(body):
if body.is_in_group("player"):
$HUD/Message.text = "You win!"
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