small racing game im working on
make start button cooler
bendn 2023-03-07
parent 1f6df68 · commit 2d022f8
-rw-r--r--assets/cars/kenney_sedan/ghost.tscn2
-rw-r--r--globals.gd1
-rw-r--r--project.godot5
-rw-r--r--race.gd5
-rw-r--r--start.tscn6
-rw-r--r--ui/cascadiabold.tres6
-rw-r--r--ui/cascadiaregu.tres5
-rw-r--r--ui/finish.tscn12
-rw-r--r--ui/hud.tscn2
-rw-r--r--ui/splits/splits.tres6
-rw-r--r--ui/splits/splits.tscn10
-rw-r--r--ui/theme.tres2
-rw-r--r--ui/track_button.tscn43
-rw-r--r--ui/trackbutton.gd8
-rw-r--r--ui/tracks.gd7
15 files changed, 93 insertions, 27 deletions
diff --git a/assets/cars/kenney_sedan/ghost.tscn b/assets/cars/kenney_sedan/ghost.tscn
index f439f6d..9df9deb 100644
--- a/assets/cars/kenney_sedan/ghost.tscn
+++ b/assets/cars/kenney_sedan/ghost.tscn
@@ -373,7 +373,7 @@ transform = Transform3D(2.33967, -1.78815e-14, -2.0454e-07, 0, 2.33967, -2.0454e
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 1.2, 0.8, -1.51)
[node name="frontright" type="MeshInstance3D" parent="fr"]
-transform = Transform3D(-2.33967, 0, -2.0454e-07, 0, 2.33967, 0, 2.0454e-07, 0, -2.33967, 0.5, 0, 0)
+transform = Transform3D(2.33967, 0, 0, 0, 2.33967, 0, 0, 0, 2.33967, -0.5, 0, 0)
mesh = SubResource("ArrayMesh_qyvuj")
skeleton = NodePath("")
diff --git a/globals.gd b/globals.gd
index 7cb7939..3ae8391 100644
--- a/globals.gd
+++ b/globals.gd
@@ -1,3 +1,4 @@
extends Node
var playing: TrackResource
+const SAVES := "user://%s.ghost"
diff --git a/project.godot b/project.godot
index 5ebfcd9..d90ddcc 100644
--- a/project.godot
+++ b/project.godot
@@ -118,6 +118,11 @@ right={
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
+click={
+"deadzone": 0.5,
+"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null)
+]
+}
[layer_names]
diff --git a/race.gd b/race.gd
index 1c63537..9123c92 100644
--- a/race.gd
+++ b/race.gd
@@ -18,7 +18,6 @@ var playing := false
var timer := GameTimer.new()
const SaveLoad := preload("res://addons/@bendn/remap/private/SaveLoadUtils.gd")
-const saves := "user://%s.ghost"
signal next_lap
signal created_car(car: Car)
@@ -71,7 +70,7 @@ func _ready() -> void:
track.track = track_res
add_child(track)
data = GhostData.new(track_res.checkpoints.size(), track_res.laps)
- best_time_data = GhostData._load(saves % track_res.name)
+ best_time_data = GhostData._load(Globals.SAVES % track_res.name)
mkcar()
mkghost()
connect_checkpoints()
@@ -114,7 +113,7 @@ func passed_finish() -> void:
if not best_time_data or data.time < best_time_data.time:
print("new pb!")
finished.emit(data.time, best_time_data.time if best_time_data else -1.0)
- data.save(saves % track_res.name)
+ data.save(Globals.SAVES % track_res.name)
best_time_data = data
else:
finished.emit(data.time, best_time_data.time)
diff --git a/start.tscn b/start.tscn
index 4c1fc19..efc242d 100644
--- a/start.tscn
+++ b/start.tscn
@@ -1,11 +1,12 @@
-[gd_scene load_steps=7 format=3 uid="uid://bvfqaoqjsxj73"]
+[gd_scene load_steps=8 format=3 uid="uid://bvfqaoqjsxj73"]
-[ext_resource type="Theme" path="res://ui/theme.tres" id="1_gm0ws"]
+[ext_resource type="Theme" uid="uid://cru1d7n2ftrfm" path="res://ui/theme.tres" id="1_gm0ws"]
[ext_resource type="Script" path="res://ui/tracks.gd" id="2_po2ce"]
[ext_resource type="Resource" uid="uid://crye0ijvmtsyb" path="res://tracks/multilap_test.tres" id="3_0yjp1"]
[ext_resource type="Resource" uid="uid://de46bcu1ivmtq" path="res://tracks/test.tres" id="4_3xqvr"]
[ext_resource type="PackedScene" uid="uid://dhiei0g5tr74s" path="res://scenes/race_high.tscn" id="5_m5kci"]
[ext_resource type="Resource" uid="uid://crtutccbf1sxh" path="res://tracks/the fallen tramps.tres" id="5_qwie6"]
+[ext_resource type="PackedScene" uid="uid://dfvtugujgcjcw" path="res://ui/track_button.tscn" id="7_pchkj"]
[node name="start" type="Control"]
layout_mode = 3
@@ -42,3 +43,4 @@ columns = 5
script = ExtResource("2_po2ce")
tracks = Array[Resource("res://classes/track.gd")]([ExtResource("3_0yjp1"), ExtResource("4_3xqvr"), ExtResource("5_qwie6")])
race = ExtResource("5_m5kci")
+trackbutton = ExtResource("7_pchkj")
diff --git a/ui/cascadiabold.tres b/ui/cascadiabold.tres
new file mode 100644
index 0000000..2e3a543
--- /dev/null
+++ b/ui/cascadiabold.tres
@@ -0,0 +1,6 @@
+[gd_resource type="SystemFont" format=3 uid="uid://d2klp6vxh5l2d"]
+
+[resource]
+font_names = PackedStringArray("Cascadia Code")
+font_weight = 700
+oversampling = 5.0
diff --git a/ui/cascadiaregu.tres b/ui/cascadiaregu.tres
new file mode 100644
index 0000000..f1d3cea
--- /dev/null
+++ b/ui/cascadiaregu.tres
@@ -0,0 +1,5 @@
+[gd_resource type="SystemFont" format=3 uid="uid://de68sch0febc8"]
+
+[resource]
+font_names = PackedStringArray("Cascadia Code")
+oversampling = 5.0
diff --git a/ui/finish.tscn b/ui/finish.tscn
index fe17bbb..d87c7a3 100644
--- a/ui/finish.tscn
+++ b/ui/finish.tscn
@@ -1,8 +1,9 @@
[gd_scene load_steps=16 format=3 uid="uid://cr1mgp6bgxh64"]
-[ext_resource type="Theme" path="res://ui/theme.tres" id="1_aykd4"]
+[ext_resource type="Theme" uid="uid://cru1d7n2ftrfm" path="res://ui/theme.tres" id="1_aykd4"]
[ext_resource type="Script" path="res://ui/finish.gd" id="1_crs2w"]
[ext_resource type="Script" path="res://ui/diff.gd" id="2_gtres"]
+[ext_resource type="SystemFont" uid="uid://d2klp6vxh5l2d" path="res://ui/cascadiabold.tres" id="3_qktla"]
[ext_resource type="StyleBox" uid="uid://bxi4jeh5lf468" path="res://ui/assets/wide_button_focus.stylebox" id="4_dck0l"]
[ext_resource type="SystemFont" uid="uid://bkjqtc5i64r3j" path="res://ui/ubuntu.tres" id="5_llemr"]
@@ -25,13 +26,8 @@ shadow_size = 20
shadow_color = Color(0, 0, 0, 0.392157)
shadow_offset = Vector2(10, 10)
-[sub_resource type="SystemFont" id="SystemFont_0mxmp"]
-font_names = PackedStringArray("Cascadia Code")
-font_weight = 700
-oversampling = 5.0
-
[sub_resource type="LabelSettings" id="LabelSettings_m62vt"]
-font = SubResource("SystemFont_0mxmp")
+font = ExtResource("3_qktla")
font_size = 100
font_color = Color(0.992157, 0.964706, 0.890196, 1)
shadow_size = 20
@@ -42,7 +38,7 @@ shadow_offset = Vector2(5, 10)
content_margin_left = 250.0
[sub_resource type="LabelSettings" id="LabelSettings_irfee"]
-font = SubResource("SystemFont_0mxmp")
+font = ExtResource("3_qktla")
font_size = 50
font_color = Color(0.521569, 0.6, 0, 1)
shadow_size = 12
diff --git a/ui/hud.tscn b/ui/hud.tscn
index be83a0f..d6ccf3e 100644
--- a/ui/hud.tscn
+++ b/ui/hud.tscn
@@ -1,6 +1,6 @@
[gd_scene load_steps=18 format=3 uid="uid://vok7fdcyec68"]
-[ext_resource type="Theme" path="res://ui/theme.tres" id="1_ie2j2"]
+[ext_resource type="Theme" uid="uid://cru1d7n2ftrfm" path="res://ui/theme.tres" id="1_ie2j2"]
[ext_resource type="Script" path="res://ui/hud.gd" id="1_sfhpc"]
[ext_resource type="Script" path="res://ui/speedometer.gd" id="2_cvi37"]
[ext_resource type="Script" path="res://ui/timer.gd" id="3_poksb"]
diff --git a/ui/splits/splits.tres b/ui/splits/splits.tres
index b02bee5..602a7cc 100644
--- a/ui/splits/splits.tres
+++ b/ui/splits/splits.tres
@@ -1,10 +1,10 @@
-[gd_resource type="Theme" load_steps=3 format=3]
+[gd_resource type="Theme" load_steps=3 format=3 uid="uid://bsf7ap656ac0x"]
-[ext_resource type="SystemFont" uid="uid://xriuk0v4f6wj" path="res://ui/ubuntu_mononf.tres" id="1_feesq"]
[ext_resource type="StyleBox" uid="uid://dddpw6gu8fex7" path="res://ui/splits/neutral.tres" id="1_fv505"]
+[ext_resource type="SystemFont" uid="uid://de68sch0febc8" path="res://ui/cascadiaregu.tres" id="2_d3ff1"]
[resource]
-default_font = ExtResource("1_feesq")
+default_font = ExtResource("2_d3ff1")
default_font_size = 40
PanelContainer/styles/panel = ExtResource("1_fv505")
VBoxContainer/constants/separation = 0
diff --git a/ui/splits/splits.tscn b/ui/splits/splits.tscn
index 485f033..ffcc005 100644
--- a/ui/splits/splits.tscn
+++ b/ui/splits/splits.tscn
@@ -1,6 +1,6 @@
[gd_scene load_steps=7 format=3 uid="uid://nkh2xi7tnumc"]
-[ext_resource type="Theme" path="res://ui/splits/splits.tres" id="1_m5q5h"]
+[ext_resource type="Theme" uid="uid://bsf7ap656ac0x" path="res://ui/splits/splits.tres" id="1_m5q5h"]
[ext_resource type="Script" path="res://ui/splits/splits.gd" id="2_2frki"]
[ext_resource type="Script" path="res://ui/splits/difference.gd" id="3_4w6ms"]
[ext_resource type="StyleBox" uid="uid://dwfuwf6qbggrd" path="res://ui/splits/loss.tres" id="4_5hoie"]
@@ -12,8 +12,8 @@ anchors_preset = 14
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
-offset_top = -395.0
-offset_bottom = -307.0
+offset_top = -50.0
+offset_bottom = 50.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_m5q5h")
@@ -22,7 +22,7 @@ diff = NodePath("Difference")
current = NodePath("Current")
[node name="Current" type="Label" parent="."]
-custom_minimum_size = Vector2(170, 0)
+custom_minimum_size = Vector2(198, 0)
layout_mode = 2
size_flags_horizontal = 4
theme_override_styles/normal = ExtResource("4_ebhpa")
@@ -31,7 +31,7 @@ horizontal_alignment = 2
vertical_alignment = 1
[node name="Difference" type="Label" parent="."]
-custom_minimum_size = Vector2(170, 0)
+custom_minimum_size = Vector2(198, 0)
layout_mode = 2
size_flags_horizontal = 4
theme_override_styles/normal = ExtResource("4_ebhpa")
diff --git a/ui/theme.tres b/ui/theme.tres
index a8a24b3..a672edf 100644
--- a/ui/theme.tres
+++ b/ui/theme.tres
@@ -1,4 +1,4 @@
-[gd_resource type="Theme" load_steps=5 format=3]
+[gd_resource type="Theme" load_steps=5 format=3 uid="uid://cru1d7n2ftrfm"]
[ext_resource type="SystemFont" uid="uid://xriuk0v4f6wj" path="res://ui/ubuntu_mononf.tres" id="1_37cf0"]
[ext_resource type="StyleBox" uid="uid://cdth5nc7lbx1v" path="res://ui/panel_skewed.tres" id="1_g8q83"]
diff --git a/ui/track_button.tscn b/ui/track_button.tscn
new file mode 100644
index 0000000..e4652cb
--- /dev/null
+++ b/ui/track_button.tscn
@@ -0,0 +1,43 @@
+[gd_scene load_steps=6 format=3 uid="uid://dfvtugujgcjcw"]
+
+[ext_resource type="Script" path="res://ui/trackbutton.gd" id="2_bcpuy"]
+[ext_resource type="FontVariation" uid="uid://ba8ab6dti2fvo" path="res://ui/boldsans.tres" id="2_gctvu"]
+[ext_resource type="SystemFont" uid="uid://d2klp6vxh5l2d" path="res://ui/cascadiabold.tres" id="3_suph6"]
+
+[sub_resource type="LabelSettings" id="LabelSettings_sa0e6"]
+font = ExtResource("2_gctvu")
+font_size = 45
+font_color = Color(0.933333, 0.909804, 0.835294, 1)
+
+[sub_resource type="LabelSettings" id="LabelSettings_7u0yx"]
+font = ExtResource("3_suph6")
+font_size = 45
+font_color = Color(0.933333, 0.909804, 0.835294, 1)
+
+[node name="trackbutton" type="Button"]
+custom_minimum_size = Vector2(450, 150)
+offset_right = 200.0
+offset_bottom = 100.0
+script = ExtResource("2_bcpuy")
+
+[node name="VBoxContainer" type="VBoxContainer" parent="."]
+layout_mode = 1
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+mouse_filter = 2
+alignment = 1
+
+[node name="name" type="Label" parent="VBoxContainer"]
+layout_mode = 2
+text = "trambler 42"
+label_settings = SubResource("LabelSettings_sa0e6")
+horizontal_alignment = 1
+
+[node name="time" type="Label" parent="VBoxContainer"]
+layout_mode = 2
+text = "no time set"
+label_settings = SubResource("LabelSettings_7u0yx")
+horizontal_alignment = 1
diff --git a/ui/trackbutton.gd b/ui/trackbutton.gd
new file mode 100644
index 0000000..c046098
--- /dev/null
+++ b/ui/trackbutton.gd
@@ -0,0 +1,8 @@
+extends Control
+
+func init(t: float, n: String) -> void:
+ $VBoxContainer/name.text = n
+ if t < 0:
+ $VBoxContainer/time.text = "no time set"
+ else:
+ $VBoxContainer/time.text = GameTimer.format_precise(t)
diff --git a/ui/tracks.gd b/ui/tracks.gd
index 2f9d0ec..1b23df2 100644
--- a/ui/tracks.gd
+++ b/ui/tracks.gd
@@ -2,13 +2,14 @@ extends GridContainer
@export var tracks: Array[TrackResource]
@export var race: PackedScene
+@export var trackbutton: PackedScene
func _ready() -> void:
for track in tracks:
- var button := Button.new()
+ var button := trackbutton.instantiate()
add_child(button)
- button.name = track.name
- button.text = track.name
+ var ghost := GhostData._load(Globals.SAVES % track.name)
+ button.init(ghost.time if ghost else -1, track.name)
button.pressed.connect(track_selected.bind(track))
func track_selected(track: TrackResource) -> void: