X-Git-Url: http://git.purplebirdman.com/mushroom-game.git/blobdiff_plain/5a21298c3ff31c639d9bb73c45e138441359e889..HEAD:/world.gd diff --git a/world.gd b/world.gd index 07e281d..91b1bc6 100644 --- a/world.gd +++ b/world.gd @@ -1,12 +1,7 @@ extends Node3D -func quit_game() -> void: - get_tree().quit() - -# Quit the game -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed("quit-game"): - quit_game() +signal victory +signal quit # Called when the node enters the scene tree for the first time. @@ -19,6 +14,28 @@ func _process(_delta: float) -> void: pass +# Quit the game on user action +func _unhandled_input(event: InputEvent) -> void: + if event.is_action_pressed("quit-game"): + quit.emit() + + +# if all mushrooms have been picked, +# then game is over func _on_mushroom_picked() -> void: - print("Player picked all mushrooms!") - #quit_game() + print("Player picked a mushroom!") + + for mushroom in $mushrooms.get_children(): + if mushroom.is_picked == false: + return + + print("Player picked all mushrooms, game over") + victory.emit() + + +func _on_victory() -> void: + get_tree().change_scene_to_file("res://victory-screen.tscn") + + +func _on_quit() -> void: + get_tree().quit()