mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-07-12 18:43:49 +00:00
feat(*): Add hud with timer
This commit is contained in:
+26
-1
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://p07epxnh8wwp"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://p07epxnh8wwp"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dyq1n7q1bqjps" path="res://scripts/ship.gd" id="1_efag7"]
|
||||
|
||||
@@ -8,6 +8,9 @@ size = Vector3(1, 1, 4)
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_dsjou"]
|
||||
size = Vector3(1, 1, 4)
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_efag7"]
|
||||
font_size = 32
|
||||
|
||||
[node name="Ship" type="RigidBody3D"]
|
||||
mass = 10.0
|
||||
gravity_scale = 10.0
|
||||
@@ -21,3 +24,25 @@ shape = SubResource("BoxShape3D_dsjou")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.867366, 0.497671, 0, -0.497671, 0.867366, 0, 2.04336, 3.31556)
|
||||
|
||||
[node name="HUD" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="Control" type="Control" parent="HUD"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="TimerLabel" type="Label" parent="HUD/Control"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 5
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
offset_left = -90.5
|
||||
offset_right = 90.5
|
||||
offset_bottom = 62.0
|
||||
grow_horizontal = 2
|
||||
label_settings = SubResource("LabelSettings_efag7")
|
||||
horizontal_alignment = 1
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://b82sy3js0vncb"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bpxm8ge52w5g8" path="res://scripts/game.gd" id="1_iywne"]
|
||||
[ext_resource type="Material" uid="uid://drm3clvqpis42" path="res://assets/models/TerrainMaterial.tres" id="1_lnu2h"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://cndcxj6gf0smr" path="res://assets/models/Terrain.obj" id="2_lbhrr"]
|
||||
[ext_resource type="Script" uid="uid://bj4jfixb8xuni" path="res://scripts/time_left_label.gd" id="3_iywne"]
|
||||
[ext_resource type="PackedScene" uid="uid://p07epxnh8wwp" path="res://objects/ship.tscn" id="4_iywne"]
|
||||
[ext_resource type="PackedScene" uid="uid://27u3tdc5yqnl" path="res://objects/ball.tscn" id="5_iywne"]
|
||||
|
||||
@@ -19,6 +19,7 @@ background_mode = 2
|
||||
sky = SubResource("Sky_gl6un")
|
||||
|
||||
[node name="Game" type="Node3D"]
|
||||
script = ExtResource("1_iywne")
|
||||
|
||||
[node name="Terrain" type="StaticBody3D" parent="."]
|
||||
|
||||
@@ -36,11 +37,7 @@ shadow_enabled = true
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_j5yw3")
|
||||
|
||||
[node name="TimeLeftLabel" type="Label3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.788399, 1.27559, -2.74564)
|
||||
script = ExtResource("3_iywne")
|
||||
|
||||
[node name="TimeLeftTimer" type="Timer" parent="."]
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
process_callback = 0
|
||||
autostart = true
|
||||
|
||||
@@ -51,4 +48,4 @@ lock_rotation = true
|
||||
[node name="Ball" parent="." instance=ExtResource("5_iywne")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 18.2942, 1.46401, -2.82393)
|
||||
|
||||
[connection signal="timeout" from="TimeLeftTimer" to="TimeLeftLabel" method="_on_time_left_timer_timeout"]
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
||||
|
||||
@@ -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")
|
||||
@@ -0,0 +1 @@
|
||||
uid://bpxm8ge52w5g8
|
||||
@@ -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:
|
||||
|
||||
@@ -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 +0,0 @@
|
||||
uid://bj4jfixb8xuni
|
||||
Reference in New Issue
Block a user