small racing game im working on
checkpoints & such, cinematic entry in progress
43 files changed, 605 insertions, 97 deletions
diff --git a/assets/cars/cruella/cruella.tscn b/assets/cars/cruella/cruella.tscn index dd108f6..258961f 100644 --- a/assets/cars/cruella/cruella.tscn +++ b/assets/cars/cruella/cruella.tscn @@ -1,7 +1,7 @@ -[gd_scene load_steps=4 format=3 uid="uid://c4wei884eefjq"] +[gd_scene load_steps=4 format=3] [ext_resource type="PackedScene" uid="uid://ci8a2pe7ux1ol" path="res://assets/cars/cruella/cruella.blend" id="1_nkrbo"] -[ext_resource type="Script" path="res://car.gd" id="2_rs08l"] +[ext_resource type="Script" path="res://classes/car.gd" id="2_rs08l"] [sub_resource type="BoxShape3D" id="BoxShape3D_p6ojk"] size = Vector3(3, 1, 5.5) diff --git a/assets/cars/kenney_sedan/sedan.tscn b/assets/cars/kenney_sedan/sedan.tscn index c2ec224..f7d01c9 100644 --- a/assets/cars/kenney_sedan/sedan.tscn +++ b/assets/cars/kenney_sedan/sedan.tscn @@ -1,7 +1,7 @@ -[gd_scene load_steps=21 format=3 uid="uid://dyd5mqhgu6qfv"] +[gd_scene load_steps=21 format=3 uid="uid://ccn1nk1a0b0sa"] +[ext_resource type="Script" path="res://classes/human_car.gd" id="1_2rc1g"] [ext_resource type="PackedScene" uid="uid://bbj2agqv581cd" path="res://assets/cars/kenney_sedan/sedan.blend" id="1_a083g"] -[ext_resource type="Script" path="res://human_car.gd" id="1_dj6iq"] [ext_resource type="Material" uid="uid://b0t01t5nxdfdp" path="res://assets/cars/skid.tres" id="3_abyal"] [ext_resource type="SphereMesh" uid="uid://cd2plk55q0xr7" path="res://assets/cars/sphere.tres" id="4_nipof"] @@ -295,7 +295,7 @@ radial_segments = 16 rings = 12 [node name="Sedan" type="Node3D"] -script = ExtResource("1_dj6iq") +script = ExtResource("1_2rc1g") [node name="CarMesh" parent="." instance=ExtResource("1_a083g")] @@ -341,6 +341,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) [node name="Ball" type="RigidBody3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0.5) +collision_layer = 2 +collision_mask = 3 axis_lock_angular_y = true physics_material_override = SubResource("PhysicsMaterial_grep7") linear_damp = 0.1 diff --git a/assets/mats/outline.tres b/assets/mats/outline.tres new file mode 100644 index 0000000..6181d52 --- /dev/null +++ b/assets/mats/outline.tres @@ -0,0 +1,9 @@ +[gd_resource type="StandardMaterial3D" format=3 uid="uid://daq466g05ublu"] + +[resource] +cull_mode = 1 +shading_mode = 0 +albedo_color = Color(0, 0, 0, 1) +texture_filter = 0 +grow = true +grow_amount = 2.0 diff --git a/assets/mats/ring_checkpoint.tres b/assets/mats/ring_checkpoint.tres new file mode 100644 index 0000000..4077c54 --- /dev/null +++ b/assets/mats/ring_checkpoint.tres @@ -0,0 +1,11 @@ +[gd_resource type="StandardMaterial3D" load_steps=3 format=3 uid="uid://c0lc82y5l5pmx"] + +[ext_resource type="Material" uid="uid://daq466g05ublu" path="res://assets/mats/outline.tres" id="1_5pppj"] +[ext_resource type="Texture2D" uid="uid://bvpakhb1dybl1" path="res://assets/textures/checkpoint.png" id="1_70653"] + +[resource] +next_pass = ExtResource("1_5pppj") +albedo_texture = ExtResource("1_70653") +metallic_specular = 0.0 +uv1_scale = Vector3(8, 8, 8) +texture_filter = 0 diff --git a/assets/mats/ring_finish.tres b/assets/mats/ring_finish.tres new file mode 100644 index 0000000..0cff10d --- /dev/null +++ b/assets/mats/ring_finish.tres @@ -0,0 +1,11 @@ +[gd_resource type="StandardMaterial3D" load_steps=3 format=3 uid="uid://ch2cbq0vpj0to"] + +[ext_resource type="Texture2D" uid="uid://c4e2s06xl4u0x" path="res://assets/textures/finish.png" id="1_2ka05"] +[ext_resource type="Material" uid="uid://daq466g05ublu" path="res://assets/mats/outline.tres" id="2_pcrim"] + +[resource] +next_pass = ExtResource("2_pcrim") +albedo_texture = ExtResource("1_2ka05") +metallic_specular = 0.0 +uv1_scale = Vector3(8, 8, 8) +texture_filter = 0 diff --git a/assets/mats/ring_start.tres b/assets/mats/ring_start.tres new file mode 100644 index 0000000..e33e4ab --- /dev/null +++ b/assets/mats/ring_start.tres @@ -0,0 +1,11 @@ +[gd_resource type="StandardMaterial3D" load_steps=3 format=3 uid="uid://cpjh47d4kaxtx"] + +[ext_resource type="Texture2D" uid="uid://bt35gqul2twf6" path="res://assets/textures/start.png" id="1_fs7sc"] +[ext_resource type="Material" uid="uid://daq466g05ublu" path="res://assets/mats/outline.tres" id="2_akkc8"] + +[resource] +next_pass = ExtResource("2_akkc8") +albedo_texture = ExtResource("1_fs7sc") +metallic_specular = 0.0 +uv1_scale = Vector3(8, 8, 8) +texture_filter = 0 diff --git a/assets/meshes/checkpoint.tres b/assets/meshes/checkpoint.tres new file mode 100644 index 0000000..b065f89 --- /dev/null +++ b/assets/meshes/checkpoint.tres @@ -0,0 +1,10 @@ +[gd_resource type="TorusMesh" load_steps=2 format=3 uid="uid://dlbpusye3e33p"] + +[ext_resource type="Material" uid="uid://c0lc82y5l5pmx" path="res://assets/mats/ring_checkpoint.tres" id="1_64nbs"] + +[resource] +material = ExtResource("1_64nbs") +inner_radius = 25.0 +outer_radius = 40.0 +rings = 32 +ring_segments = 16 diff --git a/assets/meshes/ring_finish.tres b/assets/meshes/ring_finish.tres new file mode 100644 index 0000000..5901c9a --- /dev/null +++ b/assets/meshes/ring_finish.tres @@ -0,0 +1,10 @@ +[gd_resource type="TorusMesh" load_steps=2 format=3 uid="uid://bc8hyk8kfo4q1"] + +[ext_resource type="Material" uid="uid://ch2cbq0vpj0to" path="res://assets/mats/ring_finish.tres" id="1_wa3lo"] + +[resource] +material = ExtResource("1_wa3lo") +inner_radius = 25.0 +outer_radius = 40.0 +rings = 32 +ring_segments = 16 diff --git a/assets/meshes/ring_start.tres b/assets/meshes/ring_start.tres new file mode 100644 index 0000000..e3621e9 --- /dev/null +++ b/assets/meshes/ring_start.tres @@ -0,0 +1,10 @@ +[gd_resource type="TorusMesh" load_steps=2 format=3 uid="uid://cwiqggu3nwbyh"] + +[ext_resource type="Material" uid="uid://cpjh47d4kaxtx" path="res://assets/mats/ring_start.tres" id="1_hr1sx"] + +[resource] +material = ExtResource("1_hr1sx") +inner_radius = 25.0 +outer_radius = 40.0 +rings = 32 +ring_segments = 16 diff --git a/assets/textures/checkpoint.png b/assets/textures/checkpoint.png Binary files differnew file mode 100644 index 0000000..76756be --- /dev/null +++ b/assets/textures/checkpoint.png diff --git a/assets/textures/checkpoint.png.import b/assets/textures/checkpoint.png.import new file mode 100644 index 0000000..d573eb7 --- /dev/null +++ b/assets/textures/checkpoint.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bvpakhb1dybl1" +path="res://.godot/imported/checkpoint.png-dac8cd7986b94a518a1a7788f75dc78f.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/textures/checkpoint.png" +dest_files=["res://.godot/imported/checkpoint.png-dac8cd7986b94a518a1a7788f75dc78f.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/assets/textures/finish.png b/assets/textures/finish.png Binary files differnew file mode 100644 index 0000000..e30912b --- /dev/null +++ b/assets/textures/finish.png diff --git a/assets/textures/finish.png.import b/assets/textures/finish.png.import new file mode 100644 index 0000000..fa9915d --- /dev/null +++ b/assets/textures/finish.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c4e2s06xl4u0x" +path="res://.godot/imported/finish.png-8d313dadff4636164fef822b4b0a8dae.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/textures/finish.png" +dest_files=["res://.godot/imported/finish.png-8d313dadff4636164fef822b4b0a8dae.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/assets/textures/start.png b/assets/textures/start.png Binary files differnew file mode 100644 index 0000000..0678420 --- /dev/null +++ b/assets/textures/start.png diff --git a/assets/textures/start.png.import b/assets/textures/start.png.import new file mode 100644 index 0000000..ee31170 --- /dev/null +++ b/assets/textures/start.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bt35gqul2twf6" +path="res://.godot/imported/start.png-3733841c0e1b31b58bc761257dcedb56.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/textures/start.png" +dest_files=["res://.godot/imported/start.png-3733841c0e1b31b58bc761257dcedb56.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=0 diff --git a/ai_car.gd b/classes/ai_car.gd index 58c37d1..58c37d1 100644 --- a/ai_car.gd +++ b/classes/ai_car.gd diff --git a/classes/checkpoint.gd b/classes/checkpoint.gd new file mode 100644 index 0000000..47844c4 --- /dev/null +++ b/classes/checkpoint.gd @@ -0,0 +1,6 @@ +extends PathFollow3D +class_name CheckPoint + +signal player_entered + +@export var needs_collision := true diff --git a/classes/finish.gd b/classes/finish.gd new file mode 100644 index 0000000..a936380 --- /dev/null +++ b/classes/finish.gd @@ -0,0 +1,2 @@ +extends CheckPoint +class_name Finish
\ No newline at end of file diff --git a/human_car.gd b/classes/human_car.gd index 989339d..989339d 100644 --- a/human_car.gd +++ b/classes/human_car.gd diff --git a/classes/start.gd b/classes/start.gd new file mode 100644 index 0000000..4fca566 --- /dev/null +++ b/classes/start.gd @@ -0,0 +1,4 @@ +extends PathFollow3D +class_name Start + +@export var needs_collision := true
\ No newline at end of file diff --git a/classes/track.gd b/classes/track.gd new file mode 100644 index 0000000..956fe39 --- /dev/null +++ b/classes/track.gd @@ -0,0 +1,56 @@ +extends Resource +class_name TrackResource +@export_group("Road") +## Width of road +@export var track_width := 17.0 +## Distance between rails and road +@export var rail_distance := 3.0 +## Support base width +@export var lower_support_width := 15.0 +## Height of supports +@export var support_height := 8.0 +## Track curve +@export var track: Curve3D = null +@export_subgroup("Barriers") +## Left barrier? (does not change collisions). see also [member right_barrier] +@export var left_barrier := true +## Right barrier? (does not change collisions). see also [member left_barrier] +@export var right_barrier := true +@export_group("Sun position") +## Sun x rotation +@export_range(-360, 360) var sun_x := -90 +## Sun y rotation ( its a game, the sun rotates around us ) +@export_range(-360, 360) var sun_y := 0 +@export_group("", "") +## Does the track loop around? +@export var is_loop := true +## Offset the entire track +@export var offset := Vector3.UP +@export_group("Race") +## Num laps, 0 = no laps +@export var laps := 0 +@export_subgroup("Checkpoints") +## Place the path offsets of checkpoint locations in this array +@export var checkpoints: PackedFloat32Array = [] +## The checkpoint scene +@export var checkpoint_scene: PackedScene = preload("res://scenes/ring_checkpoint.tscn") +## How much to scale each checkpoint +@export var checkpoint_scale := Vector3.ONE +@export var checkpoint_needs_collision := false +@export_subgroup("Finish") +## Finish (or lap cp) location in path offset +@export var finish_location: float = 0.0 +## The finish scene +@export var finish_scene: PackedScene = preload("res://scenes/ring_finish.tscn") +## How much to scale the finish +@export var finish_scale := Vector3.ONE +@export var finish_needs_collision := false +@export_subgroup("Start") +## Start location in path offset (unused if [member laps] > 0) +@export var start_location: float = 0.0 +## Start scene (disregarded if [member laps] > 0) +@export var start_scene: PackedScene = preload("res://scenes/ring_start.tscn") +## How much to scale the start (see above) +@export var start_scale := Vector3.ONE +@export var start_needs_collision := false + diff --git a/default_env.tres b/default_env.tres index 7310986..c9aa0a3 100644 --- a/default_env.tres +++ b/default_env.tres @@ -9,9 +9,8 @@ sky_material = ExtResource("1_jcf87") background_mode = 2 sky = SubResource("Sky_r1yiu") ambient_light_source = 3 -ambient_light_color = Color(0.87451, 0.87451, 0.815686, 1) +ambient_light_color = Color(0.176471, 0.188235, 0.145098, 1) reflected_light_source = 2 -glow_enabled = true fog_light_color = Color(0.388235, 0.172549, 0.235294, 1) fog_density = 0.1832 fog_height = -638.24 diff --git a/main.gd b/main.gd deleted file mode 100644 index 67e954f..0000000 --- a/main.gd +++ /dev/null @@ -1 +0,0 @@ -extends Node3D diff --git a/project.godot b/project.godot index 8ef945d..6d328fa 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="tracer" -run/main_scene="res://main.tscn" +run/main_scene="res://race.tscn" config/features=PackedStringArray("4.0") [display] @@ -27,6 +27,28 @@ movie_writer/movie_file="/home/bendn/Documents/tracer/movie.mp4.avi" movie_writer/disable_vsync=true movie_writer/fps=30 +[importer_defaults] + +texture={ +"compress/bptc_ldr": 0, +"compress/channel_pack": 0, +"compress/hdr_compression": 1, +"compress/lossy_quality": 0.7, +"compress/mode": 0, +"compress/normal_map": 0, +"detect_3d/compress_to": 0, +"mipmaps/generate": false, +"mipmaps/limit": -1, +"process/fix_alpha_border": true, +"process/hdr_as_srgb": false, +"process/hdr_clamp_exposure": false, +"process/normal_map_invert_y": false, +"process/premult_alpha": false, +"process/size_limit": 0, +"roughness/mode": 0, +"roughness/src_normal": "" +} + [input] ui_left={ @@ -66,6 +88,11 @@ shift_down={ ] } +[layer_names] + +3d_physics/layer_1="world" +3d_physics/layer_2="player" + [physics] 3d/default_gravity=25.0 @@ -0,0 +1,9 @@ +extends Node3D + +@export var car: Car + +func _on_track_place_car(at: Vector3, rot: Vector3) -> void: + # await car.ready + car.ball.global_position = at + (Vector3.UP * 2) + car.ball.global_rotation = rot + @@ -1,30 +1,32 @@ -[gd_scene load_steps=15 format=3 uid="uid://bnbab2hgqh4w5"] - -[ext_resource type="Script" path="res://main.gd" id="1_cps4g"] -[ext_resource type="Environment" uid="uid://biwshm46yl62v" path="res://default_env.tres" id="1_rbfsw"] -[ext_resource type="CameraAttributesPractical" uid="uid://nhsovwj5hjip" path="res://cam.tres" id="2_rymfk"] -[ext_resource type="Material" uid="uid://bdyn312e6c3ll" path="res://assets/mats/grass.tres" id="3_iiti7"] -[ext_resource type="Script" path="res://cam.gd" id="4_u07o8"] -[ext_resource type="PackedScene" uid="uid://dyd5mqhgu6qfv" path="res://assets/cars/kenney_sedan/sedan.tscn" id="6_1vlt4"] -[ext_resource type="PackedScene" uid="uid://clw61td2wh84w" path="res://scenes/track.tscn" id="6_u5ece"] -[ext_resource type="Theme" uid="uid://ch2uo5qd8ubx6" path="res://ui/theme.tres" id="8_qjj2f"] -[ext_resource type="Script" path="res://ui/map.gd" id="9_17iea"] -[ext_resource type="Script" path="res://ui/speedometer.gd" id="10_fu5aw"] -[ext_resource type="Curve3D" uid="uid://u2f56xx8h2re" path="res://tracks/speedway_curve.tres" id="12_5lojs"] -[ext_resource type="Resource" uid="uid://d3te55uy5ei7k" path="res://tracks/speedway_track.tres" id="13_pjowj"] +[gd_scene load_steps=16 format=3 uid="uid://dmkcxlevx4c7g"] + +[ext_resource type="Script" path="res://race.gd" id="1_ckbwd"] +[ext_resource type="Environment" uid="uid://biwshm46yl62v" path="res://default_env.tres" id="2_pnp7e"] +[ext_resource type="CameraAttributesPractical" uid="uid://nhsovwj5hjip" path="res://cam.tres" id="3_jx550"] +[ext_resource type="Material" uid="uid://bdyn312e6c3ll" path="res://assets/mats/grass.tres" id="4_i1mlf"] +[ext_resource type="Script" path="res://cam.gd" id="5_nb035"] +[ext_resource type="PackedScene" uid="uid://ccn1nk1a0b0sa" path="res://assets/cars/kenney_sedan/sedan.tscn" id="6_nu32e"] +[ext_resource type="Theme" uid="uid://ch2uo5qd8ubx6" path="res://ui/theme.tres" id="7_6itw5"] +[ext_resource type="Script" path="res://ui/speedometer.gd" id="8_awr5n"] +[ext_resource type="Script" path="res://ui/timer.gd" id="9_dn61b"] +[ext_resource type="Script" path="res://ui/map.gd" id="10_58kgt"] +[ext_resource type="PackedScene" uid="uid://clw61td2wh84w" path="res://scenes/track.tscn" id="11_6q53c"] +[ext_resource type="Curve3D" uid="uid://cuonflkcdybj0" path="res://tracks/test_curve.tres" id="12_8yl7p"] +[ext_resource type="Resource" uid="uid://de46bcu1ivmtq" path="res://tracks/test.tres" id="13_sh6e8"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_tkhh8"] [sub_resource type="PlaneMesh" id="PlaneMesh_ta0cd"] -material = ExtResource("3_iiti7") +material = ExtResource("4_i1mlf") size = Vector2(5000, 5000) -[node name="main" type="Node3D"] -script = ExtResource("1_cps4g") +[node name="race" type="Node3D" node_paths=PackedStringArray("car")] +script = ExtResource("1_ckbwd") +car = NodePath("Sedan") [node name="Env" type="WorldEnvironment" parent="."] -environment = ExtResource("1_rbfsw") -camera_attributes = ExtResource("2_rymfk") +environment = ExtResource("2_pnp7e") +camera_attributes = ExtResource("3_jx550") [node name="Ground" type="StaticBody3D" parent="."] metadata/_edit_lock_ = true @@ -37,35 +39,31 @@ shape = SubResource("WorldBoundaryShape3D_tkhh8") mesh = SubResource("PlaneMesh_ta0cd") [node name="Camera3D" type="Camera3D" parent="." node_paths=PackedStringArray("follow_this")] -transform = Transform3D(-0.718418, -0.318909, -0.618201, 0.111279, -0.92996, 0.350416, -0.686653, 0.182953, 0.703588, -7.07504, 13.1712, 16.3801) -far = 400.0 -script = ExtResource("4_u07o8") +far = 500.0 +script = ExtResource("5_nb035") follow_this = NodePath("../Sedan") target_distance = 9.0 target_height = 5.0 -[node name="Sedan" parent="." instance=ExtResource("6_1vlt4")] +[node name="Sedan" parent="." instance=ExtResource("6_nu32e")] transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 2, 100) [node name="CanvasLayer" type="CanvasLayer" parent="."] [node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer"] -anchors_preset = 7 -anchor_left = 0.5 +anchors_preset = 12 anchor_top = 1.0 -anchor_right = 0.5 +anchor_right = 1.0 anchor_bottom = 1.0 -offset_left = -152.0 offset_top = -105.0 -offset_right = 152.0 grow_horizontal = 2 grow_vertical = 0 -theme = ExtResource("8_qjj2f") +theme = ExtResource("7_6itw5") theme_override_constants/separation = 50 +alignment = 1 [node name="Panel" type="PanelContainer" parent="CanvasLayer/HBoxContainer"] layout_mode = 2 -theme = ExtResource("8_qjj2f") [node name="Speedometer" type="Label" parent="CanvasLayer/HBoxContainer/Panel" node_paths=PackedStringArray("car")] custom_minimum_size = Vector2(0, 105) @@ -74,21 +72,34 @@ size_flags_horizontal = 4 text = "龍 0km/h" horizontal_alignment = 1 vertical_alignment = 1 -script = ExtResource("10_fu5aw") +script = ExtResource("8_awr5n") car = NodePath("../../../../Sedan") +[node name="Panel2" type="PanelContainer" parent="CanvasLayer/HBoxContainer"] +layout_mode = 2 + +[node name="Timer" type="Label" parent="CanvasLayer/HBoxContainer/Panel2"] +custom_minimum_size = Vector2(0, 105) +layout_mode = 2 +size_flags_horizontal = 4 +text = "祥 0:00:00" +horizontal_alignment = 1 +vertical_alignment = 1 +script = ExtResource("9_dn61b") + [node name="MiniMap" type="Line2D" parent="CanvasLayer" node_paths=PackedStringArray("track", "car")] position = Vector2(300, 145) -points = PackedVector2Array(-66, -46, 128, 3, -55, 150, -84, -24) default_color = Color(0.588235, 0.588235, 0.588235, 0.537255) joint_mode = 2 antialiased = true -script = ExtResource("9_17iea") +script = ExtResource("10_58kgt") track = NodePath("../../Track") car = NodePath("../../Sedan") player_color = Color(1, 0.388235, 0.321569, 0.803922) -[node name="Track" parent="." instance=ExtResource("6_u5ece")] +[node name="Track" parent="." instance=ExtResource("11_6q53c")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) -curve = ExtResource("12_5lojs") -track = ExtResource("13_pjowj") +curve = ExtResource("12_8yl7p") +track = ExtResource("13_sh6e8") + +[connection signal="place_car" from="Track" to="." method="_on_track_place_car"] diff --git a/scenes/ring_checkpoint.gd b/scenes/ring_checkpoint.gd new file mode 100644 index 0000000..07443f4 --- /dev/null +++ b/scenes/ring_checkpoint.gd @@ -0,0 +1,9 @@ +extends CheckPoint + +func _ready() -> void: + if not needs_collision: + $Ring/Collision.queue_free() + +func _on_player_entered(_body: Node3D) -> void: + print("player entered!") + player_entered.emit() diff --git a/scenes/ring_checkpoint.tscn b/scenes/ring_checkpoint.tscn new file mode 100644 index 0000000..315c8d7 --- /dev/null +++ b/scenes/ring_checkpoint.tscn @@ -0,0 +1,37 @@ +[gd_scene load_steps=5 format=3 uid="uid://d4a3e1w62m3ck"] + +[ext_resource type="Script" path="res://classes/checkpoint.gd" id="1_kak2a"] +[ext_resource type="TorusMesh" uid="uid://dlbpusye3e33p" path="res://assets/meshes/checkpoint.tres" id="2_xys6y"] + +[sub_resource type="TorusMesh" id="TorusMesh_nyq70"] +inner_radius = 25.0 +outer_radius = 40.0 +rings = 10 +ring_segments = 4 + +[sub_resource type="BoxShape3D" id="BoxShape3D_0mg7y"] +size = Vector3(52, 52, 3) + +[node name="Checkpoint" type="PathFollow3D"] +transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0) +script = ExtResource("1_kak2a") + +[node name="Ring" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0) +mesh = ExtResource("2_xys6y") + +[node name="Collision" type="CSGMesh3D" parent="Ring"] +transform = Transform3D(1, 0, 0, 0, 1, -8.35187e-23, 0, -8.35187e-23, 1, 0, 0, 0) +visible = false +use_collision = true +mesh = SubResource("TorusMesh_nyq70") + +[node name="PlayerDetector" type="Area3D" parent="."] +collision_layer = 0 +collision_mask = 2 +monitorable = false + +[node name="Area" type="CollisionShape3D" parent="PlayerDetector"] +shape = SubResource("BoxShape3D_0mg7y") + +[connection signal="body_entered" from="PlayerDetector" to="." method="_on_player_entered"] diff --git a/scenes/ring_finish.gd b/scenes/ring_finish.gd new file mode 100644 index 0000000..ce7501e --- /dev/null +++ b/scenes/ring_finish.gd @@ -0,0 +1,9 @@ +extends Finish + +func _ready() -> void: + if not needs_collision: + $Ring/Collision.queue_free() + +func _on_player_entered(_body: Node3D) -> void: + print("player finished!") + player_entered.emit() diff --git a/scenes/ring_finish.tscn b/scenes/ring_finish.tscn new file mode 100644 index 0000000..7e9f7d0 --- /dev/null +++ b/scenes/ring_finish.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=5 format=3 uid="uid://t8ywjcjgw322"] + +[ext_resource type="Script" path="res://scenes/ring_finish.gd" id="1_oj823"] +[ext_resource type="TorusMesh" uid="uid://bc8hyk8kfo4q1" path="res://assets/meshes/ring_finish.tres" id="2_hvrqd"] + +[sub_resource type="TorusMesh" id="TorusMesh_oms0g"] +inner_radius = 25.0 +outer_radius = 40.0 +rings = 10 +ring_segments = 4 + +[sub_resource type="BoxShape3D" id="BoxShape3D_ue5ee"] +size = Vector3(52, 52, 3) + +[node name="RingFinish" type="PathFollow3D"] +script = ExtResource("1_oj823") + +[node name="Ring" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0) +mesh = ExtResource("2_hvrqd") + +[node name="Collision" type="CSGMesh3D" parent="Ring"] +transform = Transform3D(1, 0, 0, 0, 1, -8.35187e-23, 0, -8.35187e-23, 1, 0, 0, 0) +visible = false +use_collision = true +mesh = SubResource("TorusMesh_oms0g") + +[node name="PlayerDetector" type="Area3D" parent="."] +collision_layer = 0 +collision_mask = 2 +monitorable = false + +[node name="Area" type="CollisionShape3D" parent="PlayerDetector"] +shape = SubResource("BoxShape3D_ue5ee") diff --git a/scenes/ring_start.gd b/scenes/ring_start.gd new file mode 100644 index 0000000..a841f4d --- /dev/null +++ b/scenes/ring_start.gd @@ -0,0 +1,5 @@ +extends Start + +func _ready() -> void: + if not needs_collision: + $Ring/Collision.queue_free() diff --git a/scenes/ring_start.tscn b/scenes/ring_start.tscn new file mode 100644 index 0000000..0135c28 --- /dev/null +++ b/scenes/ring_start.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=4 format=3 uid="uid://bsftidvcmsha0"] + +[ext_resource type="TorusMesh" uid="uid://cwiqggu3nwbyh" path="res://assets/meshes/ring_start.tres" id="1_ksild"] +[ext_resource type="Script" path="res://scenes/ring_start.gd" id="1_kvj6d"] + +[sub_resource type="TorusMesh" id="TorusMesh_24cjh"] +inner_radius = 25.0 +outer_radius = 40.0 +rings = 10 +ring_segments = 4 + +[node name="ring_start" type="PathFollow3D"] +script = ExtResource("1_kvj6d") + +[node name="Ring" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0) +mesh = ExtResource("1_ksild") + +[node name="Collision" type="CSGMesh3D" parent="Ring"] +transform = Transform3D(1, 0, 0, 0, 1, -8.35187e-23, 0, -8.35187e-23, 1, 0, 0, 0) +visible = false +use_collision = true +mesh = SubResource("TorusMesh_24cjh") diff --git a/scenes/track-base.gd b/scenes/track-base.gd index a320614..ab034e8 100644 --- a/scenes/track-base.gd +++ b/scenes/track-base.gd @@ -23,6 +23,7 @@ class_name TrackLoader @onready var collision := $CollisionShape as CSGPolygon3D @onready var sun := $Sun as DirectionalLight3D +signal place_car(at: Vector3, rot: Vector3) var is_dirty := true func vec(x := 0.0, y := 0.0) -> Vector2: @@ -79,28 +80,59 @@ func _update(): vec(-rp - 0.05, .5) ]) rail_r.visible = track.right_barrier - # update our collision - var c = collision.polygon - c.set(0, Vector2(-rp, 0.0)) - c.set(1, Vector2( rp, 0.0)) - c.set(2, Vector2( rp, 5.0)) - c.set(3, Vector2( rp + 3.0, 5.0)) - c.set(4, Vector2( rp + 3.0, -1.0)) - c.set(5, Vector2(-rp - 3.0, -1.0)) - c.set(6, Vector2(-rp - 3.0, 5.0)) - c.set(7, Vector2(-rp, 5.0)) - collision.polygon = c - - # annd offset + # update our collision + collision.polygon = PackedVector2Array([ + vec(-rp, 0.0), + vec(rp, 0.0), + vec(rp, 5.0), + vec(rp + 3.0, 5.0), + vec(rp + 3.0, -1.0), + vec(-rp - 3.0, -1.0), + vec(-rp - 3.0, 5.0), + vec(-rp, 5.0), + ]) + # offset position = track.offset + # objects + for child in get_children(): + if child is PathFollow3D: + child.queue_free() + + for cp in track.checkpoints: + var _c: CheckPoint = make_follower(track.checkpoint_scene, cp, track.checkpoint_scale, track.checkpoint_needs_collision) + + var f: Finish = make_follower(track.finish_scene, track.finish_location, track.finish_scale, track.finish_needs_collision) + var start_position := f.global_position + var start_rot := f.global_rotation + if track.laps == 0: + var s: Start = make_follower(track.start_scene, track.start_location, track.start_scale, track.start_needs_collision) + start_position = s.global_position + start_rot = s.global_rotation + if not Engine.is_editor_hint(): + place_car.emit(start_position, start_rot) + + # loopage + rail_l.path_joined = track.is_loop + rail_r.path_joined = track.is_loop + collision.path_joined = track.is_loop + road.path_joined = track.is_loop + support.path_joined = track.is_loop + is_dirty = false func _ready(): call_deferred("_update") - func _on_curve_changed() -> void: is_dirty = true call_deferred("_update") + +func make_follower(scene: PackedScene, ratio: float, scl: Vector3, collision: bool) -> PathFollow3D: + var follower: PathFollow3D = scene.instantiate() + add_child(follower) + follower.scale = scl + follower.needs_collision = collision + follower.progress_ratio = ratio # ratio set must be after add_child() + return follower
\ No newline at end of file diff --git a/scenes/track.tscn b/scenes/track.tscn index bab3bde..5f5ace8 100644 --- a/scenes/track.tscn +++ b/scenes/track.tscn @@ -32,7 +32,7 @@ mode = 2 path_node = NodePath("..") path_interval_type = 0 path_interval = 1.0 -path_simplify_angle = 6.0 +path_simplify_angle = 10.0 path_rotation = 2 path_local = false path_continuous_u = true diff --git a/start.tscn b/start.tscn new file mode 100644 index 0000000..e5a8f9d --- /dev/null +++ b/start.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=2 format=3 uid="uid://bvfqaoqjsxj73"] + +[ext_resource type="Theme" uid="uid://ch2uo5qd8ubx6" path="res://ui/theme.tres" id="1_gm0ws"] + +[node name="start" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme = ExtResource("1_gm0ws") + +[node name="GridContainer" type="GridContainer" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -11.5 +offset_top = -15.5 +offset_right = 11.5 +offset_bottom = 15.5 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Button" type="Button" parent="GridContainer"] +layout_mode = 2 +text = "test" diff --git a/track.gd b/track.gd deleted file mode 100644 index d5db94f..0000000 --- a/track.gd +++ /dev/null @@ -1,26 +0,0 @@ -extends Resource -class_name TrackResource -@export_group("Road") -## Width of road -@export var track_width := 17.0 -## Distance between rails and road -@export var rail_distance := 3.0 -## Support base width -@export var lower_support_width := 15.0 -## Height of supports -@export var support_height := 8.0 -## Track curve -@export var track: Curve3D = null -@export_subgroup("Barriers") -## Left barrier? (does not change collisions). see also [member right_barrier] -@export var left_barrier := true -## Right barrier? (does not change collisions). see also [member left_barrier] -@export var right_barrier := true -@export_group("Sun position") -## Sun x rotation -@export_range(-360, 360) var sun_x := -90 -## Sun y rotation ( its a game, the sun rotates around us ) -@export_range(-360, 360) var sun_y := 0 -@export_group("", "") -## Offset -@export var offset := Vector3.UP
\ No newline at end of file diff --git a/tracks/speedway_track.tres b/tracks/speedway_track.tres index 756fe7e..9ee2d5e 100644 --- a/tracks/speedway_track.tres +++ b/tracks/speedway_track.tres @@ -1,7 +1,9 @@ -[gd_resource type="Resource" script_class="TrackResource" load_steps=3 format=3 uid="uid://d3te55uy5ei7k"] +[gd_resource type="Resource" script_class="TrackResource" load_steps=5 format=3 uid="uid://busubw34xl76"] -[ext_resource type="Script" path="res://track.gd" id="1_c5h3o"] +[ext_resource type="Script" path="res://classes/track.gd" id="1_c5h3o"] +[ext_resource type="PackedScene" uid="uid://d4a3e1w62m3ck" path="res://scenes/ring_checkpoint.tscn" id="1_ehf5p"] [ext_resource type="Curve3D" uid="uid://u2f56xx8h2re" path="res://tracks/speedway_curve.tres" id="2_33qpi"] +[ext_resource type="PackedScene" uid="uid://t8ywjcjgw322" path="res://scenes/ring_finish.tscn" id="2_lfdrw"] [resource] resource_local_to_scene = true @@ -16,3 +18,8 @@ right_barrier = true sun_x = -90 sun_y = 0 offset = Vector3(0, 1, 0) +checkpoints = PackedFloat32Array(0.2, 0.6) +checkpoint_scene = ExtResource("1_ehf5p") +finish_location = 0.0 +finish_scene = ExtResource("2_lfdrw") +laps = 0 diff --git a/tracks/test.tres b/tracks/test.tres new file mode 100644 index 0000000..f4ca576 --- /dev/null +++ b/tracks/test.tres @@ -0,0 +1,34 @@ +[gd_resource type="Resource" script_class="TrackResource" load_steps=6 format=3 uid="uid://de46bcu1ivmtq"] + +[ext_resource type="PackedScene" uid="uid://d4a3e1w62m3ck" path="res://scenes/ring_checkpoint.tscn" id="1_ra7ed"] +[ext_resource type="PackedScene" uid="uid://t8ywjcjgw322" path="res://scenes/ring_finish.tscn" id="2_e22em"] +[ext_resource type="Script" path="res://classes/track.gd" id="3_o0ql2"] +[ext_resource type="PackedScene" uid="uid://bsftidvcmsha0" path="res://scenes/ring_start.tscn" id="4_8biam"] +[ext_resource type="Curve3D" uid="uid://cuonflkcdybj0" path="res://tracks/test_curve.tres" id="5_35ahq"] + +[resource] +script = ExtResource("3_o0ql2") +track_width = 17.0 +rail_distance = 3.0 +lower_support_width = 15.0 +support_height = 8.0 +track = ExtResource("5_35ahq") +left_barrier = true +right_barrier = true +sun_x = -90 +sun_y = 0 +is_loop = false +offset = Vector3(0, 1, 0) +laps = 0 +checkpoints = PackedFloat32Array(0.5) +checkpoint_scene = ExtResource("1_ra7ed") +checkpoint_scale = Vector3(0.3, 0.3, 0.3) +checkpoint_needs_collision = false +finish_location = 1.0 +finish_scene = ExtResource("2_e22em") +finish_scale = Vector3(0.3, 0.3, 0.3) +finish_needs_collision = false +start_location = 0.0 +start_scene = ExtResource("4_8biam") +start_scale = Vector3(0.3, 0.3, 0.3) +start_needs_collision = false diff --git a/tracks/test_curve.tres b/tracks/test_curve.tres new file mode 100644 index 0000000..dfed068 --- /dev/null +++ b/tracks/test_curve.tres @@ -0,0 +1,9 @@ +[gd_resource type="Curve3D" format=3 uid="uid://cuonflkcdybj0"] + +[resource] +bake_interval = 10.0 +_data = { +"points": PackedVector3Array(110.965, 0, -2.66191, 0, 0, 0, 500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), +"tilts": PackedFloat32Array(1.5708, 0) +} +point_count = 2 @@ -7,18 +7,12 @@ extends Line2D func _ready() -> void: clear_points() width = track.track.track_width - # am on the fence about outlining - # var outline := Line2D.new() - # outline.width = width + 10 - # outline.default_color = Color.BLACK - # outline.show_behind_parent = true - # outline.antialiased = true - # outline.joint_mode = LINE_JOINT_ROUND - # add_child(outline) + if !track.track.is_loop: + end_cap_mode = LINE_CAP_ROUND + begin_cap_mode = LINE_CAP_ROUND for point_3d in track.curve.get_baked_points(): var p := flatten(point_3d) add_point(p) - # outline.add_point(p) func _process(_delta: float) -> void: diff --git a/ui/theme.tres b/ui/theme.tres index edf3250..5c40ab7 100644 --- a/ui/theme.tres +++ b/ui/theme.tres @@ -5,6 +5,8 @@ [ext_resource type="FontVariation" uid="uid://ba8ab6dti2fvo" path="res://ui/boldsans.tres" id="3_fpgf0"] [resource] +default_font = ExtResource("1_37cf0") +default_font_size = 76 Label/font_sizes/font_size = 76 Label/fonts/font = ExtResource("1_37cf0") PanelContainer/styles/panel = ExtResource("1_g8q83") diff --git a/ui/timer.gd b/ui/timer.gd new file mode 100644 index 0000000..e2508ed --- /dev/null +++ b/ui/timer.gd @@ -0,0 +1,20 @@ +extends Label + +var elapsed_time: float = 0.0 + +func _ready() -> void: + stop() + +func start() -> void: + set_process(true) + +func stop() -> void: + set_process(false) + +## format a number of seconds into m:s.ms +func format(time: float) -> String: + return "%01d:%02d.%02d" % [time / 60, fmod(time, 60), fmod(time * 1000, 100)] + +func _process(delta: float) -> void: + elapsed_time += delta + text = format(elapsed_time)
\ No newline at end of file |