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 called WinBanner that says You collected every coin!. Show it the same way you showed the lamps.

challenge icon

Challenge

Medium

At the end of _on_coin_collected(), when coins_left reaches 0:

  • print You collected every coin!
  • show $WinBanner

Then take all six coins.

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