Ten Pipes to Win
Part of the Projects section of Coddy's Godot journey. Lesson 25 of 33.
The player can lose but not win yet. At a score of 10, show You Win! and pause. Test it where the score goes up:
if score == 10:
$HUD/Message.text = "You Win!"
get_tree().paused = trueLast, let the player play again. While the game is paused, Space reloads the scene. Main is Always, so its _process still runs:
func _process(delta):
if get_tree().paused and Input.is_action_just_pressed("jump"):
get_tree().paused = false
get_tree().reload_current_scene()Space is also the flap key. The flyer is Pausable, so it ignores the press while the game is paused.
Challenge
Medium- When the score reaches 10, show
You Win!and pause the game. - While paused, Space (
jump) unpauses and reloads the scene.
Try it yourself
extends Node2D
const PIPE = preload("res://pipe.tscn")
var score = 0
func _ready():
$PipeTimer.timeout.connect(_on_pipe_timer_timeout)
$Flyer.crashed.connect(_on_crash)
$HUD/Score.text = "0"
func _on_pipe_timer_timeout():
var pipe = PIPE.instantiate()
pipe.position = Vector2(700, randf_range(100, 250))
pipe.hit.connect(_on_crash)
pipe.scored.connect(_on_scored)
$Pipes.add_child(pipe)
func _on_crash():
$HUD/Message.text = "Game Over"
get_tree().paused = true
func _on_scored():
score += 1
$HUD/Score.text = str(score)
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Projects
Practice on your own: Godot playground