new speed display + save best level times (#3)

This commit is contained in:
Taevas 2025-04-21 16:06:56 +02:00
parent ac1f29d111
commit b81eb08e05
Signed by: Taevas
SSH key fingerprint: SHA256:Y5Hv18xwPvUKSlgkx1sPnRO3L2mc03ehC7BzrnZVEyY
3 changed files with 140 additions and 20 deletions

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://ccgnnif026wb4"]
[gd_scene load_steps=6 format=3 uid="uid://ccgnnif026wb4"]
[ext_resource type="PackedScene" uid="uid://xd3nsiglcdfc" path="res://elements/timer.tscn" id="1_356j3"]
[ext_resource type="PackedScene" uid="uid://xd3nsiglcdfc" path="res://gui/timer.tscn" id="1_356j3"]
[ext_resource type="PackedScene" uid="uid://cckeamgkt8bqo" path="res://gui/speed.tscn" id="2_2gn6w"]
[sub_resource type="GDScript" id="GDScript_8n212"]
script/source = "extends Node
@ -16,7 +17,8 @@ var levels = [
]
var area_resource = preload(\"res://menus/main/area.tscn\")
@onready var timer := $GUI/Timer
@onready var timer := $GUI/TopLeft/Timer
@onready var speed := $GUI/TopRight/Speed
func _ready() -> void:
var os_name = OS.get_name()
@ -69,7 +71,12 @@ func stop_level() -> void:
PhysicsServer3D.area_set_param(get_viewport().find_world_3d().space, PhysicsServer3D.AREA_PARAM_GRAVITY, 1)
playing = false
changing_level = true
SaveFiles.change_property(\"played_for\", timer.seconds_spent_total, SaveFiles.selected_file)
var save_file_data = SaveFiles.read(SaveFiles.selected_file)
var property_name := \"best_time_for_level_\" + str(current_level_int)
if !save_file_data.has(property_name) or save_file_data[property_name] is not float or save_file_data[property_name] > timer.seconds_spent_level_attempt:
SaveFiles.change_property(property_name, timer.seconds_spent_level_attempt, SaveFiles.selected_file)
var current_levels = get_current_levels()
for level in current_levels:
@ -136,7 +143,7 @@ func _process(_delta: float) -> void:
var current_levels = get_current_levels()
if len(current_levels):
var current_level = current_levels[0]
$Informations/MarginContainer/VBoxContainer/Speed.text = str(int(floor(current_level.velocity))) + \" km/h\"
speed.ball_velocity = current_level.velocity
$Informations/MarginContainer/VBoxContainer/Rings.text = str(current_level.finished_rings_count) + \"/\" + str(len(current_level.rings))
func _unhandled_key_input(event: InputEvent) -> void:
@ -166,20 +173,41 @@ outline_color = Color(0, 0, 0, 1)
[node name="Game" type="Node"]
script = SubResource("GDScript_8n212")
[node name="GUI" type="MarginContainer" parent="."]
offset_right = 201.0
offset_bottom = 104.0
[node name="GUI" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 1
[node name="TopLeft" type="MarginContainer" parent="GUI"]
layout_mode = 1
offset_right = 160.0
offset_bottom = 85.0
rotation = 0.0523599
theme_override_constants/margin_left = 15
theme_override_constants/margin_top = 15
theme_override_constants/margin_right = 15
theme_override_constants/margin_bottom = 15
[node name="Timer" parent="GUI" instance=ExtResource("1_356j3")]
[node name="Timer" parent="GUI/TopLeft" instance=ExtResource("1_356j3")]
layout_mode = 2
[node name="TopRight" type="MarginContainer" parent="GUI"]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -106.0
offset_bottom = 51.0
grow_horizontal = 0
rotation = -0.0523599
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 15
[node name="Speed" parent="GUI/TopRight" instance=ExtResource("2_2gn6w")]
layout_mode = 2
[node name="Informations" type="Control" parent="."]
visible = false
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@ -210,13 +238,6 @@ label_settings = SubResource("LabelSettings_0s07t")
horizontal_alignment = 2
vertical_alignment = 2
[node name="Speed" type="Label" parent="Informations/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "0 km/h"
label_settings = SubResource("LabelSettings_0s07t")
horizontal_alignment = 2
vertical_alignment = 2
[node name="VictoryScreen" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15