feat(*): Add hud with timer

This commit is contained in:
Josh Creek
2025-07-13 18:36:48 +01:00
parent bdd0244873
commit 5ad381cf2f
7 changed files with 66 additions and 23 deletions
+23
View File
@@ -0,0 +1,23 @@
extends Node3D
@onready var game_timer: Timer = get_node("Timer")
signal timer_updated(minutes: int, seconds: int)
func _ready():
# Set timer to 2 minutes 30 seconds (150 seconds)
game_timer.wait_time = 150.0
game_timer.one_shot = true # Timer runs once
game_timer.start()
func _process(_delta):
if game_timer.time_left > 0:
var time_left = game_timer.time_left
var minutes = int(time_left) / 60
var seconds = int(time_left) % 60
timer_updated.emit(minutes, seconds)
else:
print("Timer finished!")
func _on_timer_timeout() -> void:
if game_timer.time_left == 0:
get_tree().change_scene_to_file("res://scenes/main_menu.tscn")
+1
View File
@@ -0,0 +1 @@
uid://bpxm8ge52w5g8
+12
View File
@@ -5,6 +5,18 @@ var speed = 10.0
@onready var camera : Camera3D = get_node("Camera3D")
@onready var ball = get_parent().get_node("Ball")
@onready var timer_label = get_node("HUD/Control/TimerLabel")
func _ready():
var game_scene = get_parent()
if game_scene and game_scene.has_signal("timer_updated"):
game_scene.timer_updated.connect(_on_timer_updated)
print("Connected to game scene timer signal")
else:
print("Game scene not found or doesn't have timer_updated signal")
func _on_timer_updated(minutes: int, seconds: int):
timer_label.text = "%02d:%02d" % [minutes, seconds]
func _physics_process(_delta):
if ball and camera:
-14
View File
@@ -1,14 +0,0 @@
extends Label3D
var time_left : int = 10
func _ready():
$".".text = "Time left: " + str(time_left) + "s"
func _on_time_left_timer_timeout():
time_left -= 1
$".".text = "Time left: " + str(time_left) + "s"
print(time_left)
if time_left == 0:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
get_tree().change_scene_to_file("res://scenes/main_menu.tscn")
-1
View File
@@ -1 +0,0 @@
uid://bj4jfixb8xuni