Menu
CoddyTech

Coin Collector: You Win

Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 27 of 27.

You win when no coins are left. _on_coin_collected already counts down, so check the count right after it changes:

if coins_left == 0:
	print("You collected every coin!")

The scene has a hidden Label, WinBanner, with the words You collected every coin! on it. Show it the same way you showed the lamps.

challenge icon

Challenge

Medium

Win the game when every coin is taken.

  1. At the end of _on_coin_collected(), add an if for coins_left equal to 0.
  2. Inside it, print You collected every coin! and show $WinBanner.

Press Play and take all six coins: the win banner shows. Then Check.

Try it yourself

extends Node2D

var coins_left = 0

func _ready():
	coins_left = get_tree().get_nodes_in_group("coins").size()
	for coin in get_tree().get_nodes_in_group("coins"):
		coin.collected.connect(_on_coin_collected)

func _on_coin_collected():
	coins_left -= 1
	print("Coins left: ", coins_left)
quiz iconTest yourself

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

All lessons in Signals and Collisions

Practice on your own: Godot playground