Menu
CoddyTech

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_left

Also show the time in _ready(), so the player sees Time: 10 before the first second passes.

challenge icon

Challenge

Easy

Add a ten second countdown:

  1. Add var time_left = 10 at the top, and show Time: 10 on $HUD/Time in _ready().
  2. Connect $Clock.timeout to _on_clock_timeout.
  3. In _on_clock_timeout(), take one away from time_left and 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!"
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