Clicker

Scenes

Scene “Menu” hierarchy

  • Menu (Control)
    • PlayButton

Scene “Game” hierarchy

  • Game (Control)
    • ClickButton
    • ScoreText (Label)
    • AimScoreText (Label)
    • TimeLeftText (Label)
    • Timer

Scene “Win” hierarchy

  • Win (Control)
    • ToMenu (Button)
    • PlayAgain (Button)
    • WinText (Label)

Scene “Lose” hierarchy

  • Lose (Control)
    • ToMenu (Button)
    • PlayAgain (Button)
    • LoseText (Label)

Codes

game.gd

extends Control

var score : int = 0
var aimScore : int = 5
var timer : int = 5

func _on_button_pressed() -> void:
	score += 1
	aimScore -= 1
	$ScoreText.text = "Score: " + str(score)
	if aimScore == 0:
		get_tree().change_scene_to_file("res://win.tscn")


func _on_timer_timeout() -> void:
	timer -= 1
	$TimeLeft.text = "Time left: " + str(timer) + "s"
	if timer == 0:
		get_tree().change_scene_to_file("res://loser.tscn")

menu.gd

extends Control

func _on_button_pressed() -> void:
	get_tree().change_scene_to_file("res://game.tscn")

win.gd

extends Control


func _on_to_menu_pressed() -> void:
	get_tree().change_scene_to_file("res://menu.tscn")


func _on_play_again_pressed() -> void:
	get_tree().change_scene_to_file("res://game.tscn")

Download / PWA

Scroll to Top