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

34
gui/speed.tscn Normal file
View file

@ -0,0 +1,34 @@
[gd_scene load_steps=4 format=3 uid="uid://cckeamgkt8bqo"]
[ext_resource type="FontFile" uid="uid://c3fsj6knyiuhl" path="res://fonts/Knewave/Knewave-Regular.ttf" id="1_xaun4"]
[sub_resource type="LabelSettings" id="LabelSettings_8g5s8"]
font = ExtResource("1_xaun4")
font_size = 32
font_color = Color(1, 0, 0, 1)
outline_size = 8
shadow_size = 8
shadow_color = Color(0, 0, 0, 1)
[sub_resource type="GDScript" id="GDScript_xaun4"]
script/source = "extends Label
var ball_velocity := 0.0:
get: return ball_velocity
set(value):
ball_velocity = value
var rounded := int(floor(value))
self.text = str(rounded) + \" km/h\"
const min_px = 32.0
const max_px = 56.0
self.label_settings.font_size = min(max(rounded / 3, min_px), max_px)
self.label_settings.outline_size = min(max(rounded / 12, min_px / 4), max_px / 4)
self.label_settings.shadow_size = min(max(rounded / 12, min_px / 4), max_px / 4)
"
[node name="Speed" type="Label"]
text = "0 km/h"
label_settings = SubResource("LabelSettings_8g5s8")
horizontal_alignment = 2
script = SubResource("GDScript_xaun4")

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=5 format=3 uid="uid://xd3nsiglcdfc"]
[gd_scene load_steps=9 format=3 uid="uid://xd3nsiglcdfc"]
[ext_resource type="FontFile" uid="uid://c3fsj6knyiuhl" path="res://fonts/Knewave/Knewave-Regular.ttf" id="1_m1tld"]
@ -15,6 +15,10 @@ var enabled := false:
seconds_spent_total = save_file.played_for
else:
seconds_spent_total = 0.0
if value == false:
$AnimationPlayer.play(\"scale_linear\")
await get_tree().create_timer($AnimationPlayer.current_animation_length).timeout
$AnimationPlayer.play_backwards(\"scale_cubic\")
var seconds_spent_total := 0.0:
get: return seconds_spent_total
@ -58,6 +62,62 @@ outline_color = Color(0, 0, 1, 1)
shadow_size = 8
shadow_color = Color(0, 0, 0, 1)
[sub_resource type="Animation" id="Animation_m1tld"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(1, 1)]
}
[sub_resource type="Animation" id="Animation_2a86r"]
resource_name = "scale_linear"
length = 0.25
step = 0.25
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.25),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(1, 1), Vector2(1.2, 1.2)]
}
[sub_resource type="Animation" id="Animation_houb3"]
resource_name = "scale_cubic"
length = 0.25
step = 0.25
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.25),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(1, 1), Vector2(1.2, 1.2)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_jmgpn"]
_data = {
&"RESET": SubResource("Animation_m1tld"),
&"scale_cubic": SubResource("Animation_houb3"),
&"scale_linear": SubResource("Animation_2a86r")
}
[node name="Timer" type="VBoxContainer"]
process_mode = 3
anchors_preset = 15
@ -79,3 +139,8 @@ label_settings = SubResource("LabelSettings_m1tld")
layout_mode = 2
text = "Level timer"
label_settings = SubResource("LabelSettings_2a86r")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_jmgpn")
}

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