From fa024c2516c9aca2a7954c0b2f1207f3bf6aab5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 18 Nov 2021 21:07:42 +0100 Subject: [PATCH] Separate out common track logic --- menu/pause_menu.tscn | 2 +- menu/start_menu.gd | 2 - project.godot | 8 +- scenes/{test_level.gd => base_track_level.gd} | 3 + scenes/base_track_level.tscn | 77 ++++++++ scenes/test_level.tscn | 174 +++--------------- scenes/trackgui.tscn | 104 +++++++++++ scenes/{ => tracks}/track.gd | 0 scenes/tracks/track.tscn | 20 ++ 9 files changed, 239 insertions(+), 151 deletions(-) rename scenes/{test_level.gd => base_track_level.gd} (74%) create mode 100644 scenes/base_track_level.tscn create mode 100644 scenes/trackgui.tscn rename scenes/{ => tracks}/track.gd (100%) create mode 100644 scenes/tracks/track.tscn diff --git a/menu/pause_menu.tscn b/menu/pause_menu.tscn index b05a387..08a0d8e 100644 --- a/menu/pause_menu.tscn +++ b/menu/pause_menu.tscn @@ -45,7 +45,7 @@ __meta__ = { } [node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VSplitContainer"] -margin_top = 30.0 +margin_top = 42.0 margin_right = 472.0 margin_bottom = 260.0 alignment = 1 diff --git a/menu/start_menu.gd b/menu/start_menu.gd index eb82131..595c113 100644 --- a/menu/start_menu.gd +++ b/menu/start_menu.gd @@ -21,8 +21,6 @@ func _ready() -> void: track_selector.add_item("Test track") func _on_StartButton_pressed() -> void: - print(vehicle_selector.get_selected_id()) - print(track_selector.get_selected_id()) if vehicle_selector.get_selected_id() < 0: return if track_selector.get_selected_id() < 0: diff --git a/project.godot b/project.godot index e7542cb..a5544c9 100644 --- a/project.godot +++ b/project.godot @@ -9,6 +9,11 @@ config_version=4 _global_script_classes=[ { +"base": "Spatial", +"class": "BaseTrackLevel", +"language": "GDScript", +"path": "res://scenes/base_track_level.gd" +}, { "base": "Particles", "class": "TireSmoke", "language": "GDScript", @@ -17,9 +22,10 @@ _global_script_classes=[ { "base": "Spatial", "class": "Track", "language": "GDScript", -"path": "res://scenes/track.gd" +"path": "res://scenes/tracks/track.gd" } ] _global_script_class_icons={ +"BaseTrackLevel": "", "TireSmoke": "", "Track": "" } diff --git a/scenes/test_level.gd b/scenes/base_track_level.gd similarity index 74% rename from scenes/test_level.gd rename to scenes/base_track_level.gd index bdae7c8..457b5fe 100644 --- a/scenes/test_level.gd +++ b/scenes/base_track_level.gd @@ -1,3 +1,4 @@ +class_name BaseTrackLevel extends Spatial const camera = preload("res://player/camera.tscn") @@ -10,6 +11,8 @@ func _ready() -> void: add_child(player_node) add_child(gui) var player_camera = camera.instance() + player_camera.global_transform = spawn_point.global_transform + player_camera.global_transform.origin = -spawn_point.global_transform.basis.z * 1000 player_camera.follow_target_path = player_node.get_path() add_child(player_camera) diff --git a/scenes/base_track_level.tscn b/scenes/base_track_level.tscn new file mode 100644 index 0000000..a69b4ce --- /dev/null +++ b/scenes/base_track_level.tscn @@ -0,0 +1,77 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://scenes/base_track_level.gd" type="Script" id=1] +[ext_resource path="res://assets/fonts/kenney-future-narrow.ttf" type="DynamicFontData" id=2] +[ext_resource path="res://menu/pause_menu.gd" type="Script" id=5] +[ext_resource path="res://scenes/tracks/track.tscn" type="PackedScene" id=6] + +[sub_resource type="DynamicFont" id=1] +font_data = ExtResource( 2 ) + +[sub_resource type="DynamicFont" id=2] +font_data = ExtResource( 2 ) + +[node name="Spatial" type="Spatial"] +script = ExtResource( 1 ) + +[node name="PauseMenu" type="PopupDialog" parent="."] +pause_mode = 2 +anchor_left = 0.25 +anchor_top = 0.25 +anchor_right = 0.75 +anchor_bottom = 0.75 +script = ExtResource( 5 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MarginContainer" type="MarginContainer" parent="PauseMenu"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 20.0 +margin_top = 20.0 +margin_right = -20.0 +margin_bottom = -20.0 + +[node name="VSplitContainer" type="VSplitContainer" parent="PauseMenu/MarginContainer"] +margin_right = 472.0 +margin_bottom = 260.0 +dragger_visibility = 1 + +[node name="Title" type="Label" parent="PauseMenu/MarginContainer/VSplitContainer"] +margin_right = 472.0 +margin_bottom = 18.0 +custom_fonts/font = SubResource( 1 ) +text = "Game Paused" +align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="PauseMenu/MarginContainer/VSplitContainer"] +margin_top = 42.0 +margin_right = 472.0 +margin_bottom = 260.0 +alignment = 1 + +[node name="ContinueButton" type="Button" parent="PauseMenu/MarginContainer/VSplitContainer/VBoxContainer"] +margin_top = 75.0 +margin_right = 472.0 +margin_bottom = 105.0 +custom_fonts/font = SubResource( 2 ) +text = "Continue" + +[node name="ExitButton" type="Button" parent="PauseMenu/MarginContainer/VSplitContainer/VBoxContainer"] +margin_top = 113.0 +margin_right = 472.0 +margin_bottom = 143.0 +custom_fonts/font = SubResource( 2 ) +text = "Exit to main menu" + +[node name="PlayerSpawnLocation" type="Position3D" parent="."] + +[node name="Track" parent="." instance=ExtResource( 6 )] + +[connection signal="pressed" from="PauseMenu/MarginContainer/VSplitContainer/VBoxContainer/ContinueButton" to="PauseMenu" method="_on_ContinueButton_pressed"] +[connection signal="pressed" from="PauseMenu/MarginContainer/VSplitContainer/VBoxContainer/ExitButton" to="PauseMenu" method="_on_ExitButton_pressed"] diff --git a/scenes/test_level.tscn b/scenes/test_level.tscn index 07c96ff..19eb5d0 100644 --- a/scenes/test_level.tscn +++ b/scenes/test_level.tscn @@ -1,83 +1,63 @@ -[gd_scene load_steps=16 format=2] +[gd_scene load_steps=10 format=2] -[ext_resource path="res://scenes/test_level.gd" type="Script" id=1] -[ext_resource path="res://menu/pause_menu.tscn" type="PackedScene" id=2] +[ext_resource path="res://scenes/base_track_level.tscn" type="PackedScene" id=1] [ext_resource path="res://icon.png" type="Texture" id=3] -[ext_resource path="res://scenes/track.gd" type="Script" id=4] -[ext_resource path="res://assets/fonts/kenney-future-narrow.ttf" type="DynamicFontData" id=5] -[ext_resource path="res://scenes/trackgui.gd" type="Script" id=6] -[sub_resource type="PlaneMesh" id=1] +[sub_resource type="PlaneMesh" id=11] -[sub_resource type="SpatialMaterial" id=2] +[sub_resource type="SpatialMaterial" id=12] albedo_texture = ExtResource( 3 ) -[sub_resource type="ConcavePolygonShape" id=3] +[sub_resource type="ConcavePolygonShape" id=13] data = PoolVector3Array( 1, 0, 1, -1, 0, 1, 1, 0, -1, -1, 0, 1, -1, 0, -1, 1, 0, -1 ) -[sub_resource type="SpatialMaterial" id=9] -flags_transparent = true -albedo_color = Color( 0.0470588, 0.956863, 0.921569, 0.439216 ) - -[sub_resource type="Curve3D" id=4] +[sub_resource type="Curve3D" id=14] _data = { "points": PoolVector3Array( 9.79904, 0, 18.6319, -9.79904, 0, -18.6319, -31.895, 0, 7.96057, 0, 0, 0, 0, 0, 0, -57.093, 0, -13.8155, -7.43263, 0, 17.8593, 7.43263, 0, -17.8593, -58.3374, 0, -41.6578, -15.1113, 0, 9.06681, 15.1113, 0, -9.06681, -37.8981, 0, -68.1249, -14.7755, 0, 2.35069, 14.7755, 0, -2.35069, 4.94635, 7.23662, -84.5424, -17.7978, 0, -2.68641, 17.7978, 0, 2.68641, 61.5006, 0, -91.6313, 0.67157, 0, -25.5212, -0.67157, 0, 25.5212, 97.0961, 0, -69.1323, 2.68643, 0, -7.38771, -2.68643, 0, 7.38771, 78.6267, 0, -42.2678, -8.73099, 0, -17.4619, 8.73099, 0, 17.4619, 66.0252, 8.78723, -14.4988, 0, 0, 0, 0, 0, 0, 95.7529, 0, -1.6352, 0, 0, 0, 0, 0, 0, 139.408, 0, 1.05125, -20.1485, 0, -13.7681, 20.1485, 0, 13.7681, 185.413, 0, 3.4019, 0, 0, 0, 0, 0, 0, 201.868, 0, 23.2145, 0.335724, 0, -17.462, -0.335724, 0, 17.462, 210.21, 5.87604, 64.836, 3.97235, -0.0415859, -7.46809, -3.97235, 0.0415859, 7.46809, 201.532, 0, 95.7487, 0, 0, 0, 0, 0, 0, 183.063, 0, 103.472, 14.7754, 0, 11.0815, -14.7754, 0, -11.0815, 157.877, 0, 103.472, -7.25508, 0, 9.91405, 7.25508, 0, -9.91405, 162.578, 0, 79.2942, 8.24519, 0, 4.16077, -8.24519, 0, -4.16077, 159.22, 0, 35.3035, 0, 0, 0, 0, 0, 0, 109.521, 0, 55.4519, 13.9191, 0, -4.46759, -13.9191, 0, 4.46759, 61.5006, 0, 84.6671, 0, 0, 0, 0, 0, 0, 19.5493, 3.78882, 91.2156, 12.2019, 0, 6.94766, -12.2019, 0, -6.94766, -14.7275, 0, 82.6522, 6.66099, 0.313545, 7.53158, -6.66099, -0.313545, -7.53158, -22.7176, 8.46592, 50.9225, 2.76307, 0.531036, 4.97682, -2.76307, -0.531036, -4.97682, -31.895, 0, 7.96057 ), "tilts": PoolRealArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) } -[sub_resource type="OpenSimplexNoise" id=5] +[sub_resource type="OpenSimplexNoise" id=15] seed = -8 octaves = 9 period = 10.0 persistence = 0.49 lacunarity = 2.04 -[sub_resource type="NoiseTexture" id=6] +[sub_resource type="NoiseTexture" id=10] flags = 39 seamless = true -noise = SubResource( 5 ) +noise = SubResource( 15 ) noise_offset = Vector2( -1, -1 ) -[sub_resource type="SpatialMaterial" id=7] +[sub_resource type="SpatialMaterial" id=16] albedo_color = Color( 0.4, 0.301961, 0.00784314, 1 ) -albedo_texture = SubResource( 6 ) +albedo_texture = SubResource( 10 ) -[sub_resource type="DynamicFont" id=8] -size = 36 -outline_size = 2 -outline_color = Color( 1, 1, 1, 0.317647 ) -font_data = ExtResource( 5 ) +[node name="Spatial" instance=ExtResource( 1 )] -[node name="Spatial" type="Spatial"] -script = ExtResource( 1 ) +[node name="PlayerSpawnLocation" parent="." index="1"] +transform = Transform( -0.951412, 0, -0.307921, 0, 1, 0, 0.307921, 0, -0.951412, -26.0175, 5.60708, 25.9637 ) -[node name="PauseMenu" parent="." instance=ExtResource( 2 )] -visible = true +[node name="Track" parent="." index="2"] +track_path = NodePath("../Path") -[node name="PlayerSpawnLocation" type="Position3D" parent="."] -transform = Transform( -0.577573, 0, -0.816339, 0, 1, 0, 0.816339, 0, -0.577573, -28.4356, 7.65286, 30.9025 ) - -[node name="StaticBody" type="StaticBody" parent="."] +[node name="StaticBody" type="StaticBody" parent="." index="3"] transform = Transform( 99.9785, 0, 0, 0, 99.9785, 0, 0, 0, 99.9785, 0, 0, 0 ) -[node name="MeshInstance" type="MeshInstance" parent="StaticBody"] +[node name="MeshInstance" type="MeshInstance" parent="StaticBody" index="0"] transform = Transform( 6.13726, 0, 0, 0, 6.13726, 0, 0, 0, 6.13726, 0, 0, 0 ) -mesh = SubResource( 1 ) -material/0 = SubResource( 2 ) +mesh = SubResource( 11 ) +material/0 = SubResource( 12 ) -[node name="CollisionShape" type="CollisionShape" parent="StaticBody"] +[node name="CollisionShape" type="CollisionShape" parent="StaticBody" index="1"] transform = Transform( 6.13726, 0, 0, 0, 6.13726, 0, 0, 0, 6.13726, 0, 0, 0 ) -shape = SubResource( 3 ) +shape = SubResource( 13 ) -[node name="Track" type="Spatial" parent="."] -script = ExtResource( 4 ) -track_path = NodePath("Path") -debug_material = SubResource( 9 ) +[node name="Path" type="Path" parent="." index="4"] +curve = SubResource( 14 ) -[node name="Path" type="Path" parent="Track"] -curve = SubResource( 4 ) - -[node name="Road" type="CSGPolygon" parent="Track/Path"] +[node name="Road" type="CSGPolygon" parent="Path" index="0"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.381588, 0.85226, -0.386032 ) use_collision = true invert_faces = true @@ -92,9 +72,9 @@ path_local = false path_continuous_u = false path_u_distance = 1.0 path_joined = true -material = SubResource( 7 ) +material = SubResource( 16 ) -[node name="Slope" type="CSGPolygon" parent="Track/Path"] +[node name="Slope" type="CSGPolygon" parent="Path" index="1"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.131294, 0.632256, -0.0876541 ) use_collision = true polygon = PoolVector2Array( -12, -10, -10, -0.1, -3, 0, 3, 0, 10, -0.1, 12, -15 ) @@ -108,103 +88,3 @@ path_local = true path_continuous_u = true path_u_distance = 1.0 path_joined = true - -[node name="Checkpoints" type="Spatial" parent="Track"] - -[node name="TrackGUI" type="MarginContainer" parent="."] -anchor_right = 1.0 -anchor_bottom = 1.0 -margin_left = 20.0 -margin_top = 20.0 -margin_right = -20.0 -margin_bottom = -20.0 -script = ExtResource( 6 ) -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="VBoxContainer" type="VBoxContainer" parent="TrackGUI"] -margin_right = 984.0 -margin_bottom = 560.0 - -[node name="HBoxContainer" type="HBoxContainer" parent="TrackGUI/VBoxContainer"] -margin_right = 984.0 -margin_bottom = 41.0 - -[node name="TimeLabel" type="Label" parent="TrackGUI/VBoxContainer/HBoxContainer"] -margin_right = 289.0 -margin_bottom = 41.0 -size_flags_horizontal = 3 -size_flags_vertical = 0 -custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) -custom_fonts/font = SubResource( 8 ) -text = "Current lap -" -align = 1 -valign = 1 - -[node name="TimeValue" type="Label" parent="TrackGUI/VBoxContainer/HBoxContainer"] -margin_left = 297.0 -margin_right = 489.0 -margin_bottom = 41.0 -size_flags_horizontal = 3 -size_flags_vertical = 0 -custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) -custom_fonts/font = SubResource( 8 ) -text = "12:23.245" -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="Divider" type="Label" parent="TrackGUI/VBoxContainer/HBoxContainer"] -margin_left = 497.0 -margin_right = 562.0 -margin_bottom = 41.0 -size_flags_horizontal = 3 -size_flags_vertical = 0 -custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) -custom_fonts/font = SubResource( 8 ) -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="BestTimeLabel" type="Label" parent="TrackGUI/VBoxContainer/HBoxContainer"] -margin_left = 570.0 -margin_right = 784.0 -margin_bottom = 41.0 -size_flags_horizontal = 3 -size_flags_vertical = 0 -custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) -custom_fonts/font = SubResource( 8 ) -text = "Best Lap -" - -[node name="BestTimeValue" type="Label" parent="TrackGUI/VBoxContainer/HBoxContainer"] -margin_left = 792.0 -margin_right = 984.0 -margin_bottom = 41.0 -size_flags_horizontal = 3 -size_flags_vertical = 0 -custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) -custom_fonts/font = SubResource( 8 ) -text = "01:23.256" -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="WrongWayLabel" type="Label" parent="TrackGUI/VBoxContainer"] -visible = false -margin_top = 49.0 -margin_right = 984.0 -margin_bottom = 90.0 -size_flags_horizontal = 3 -size_flags_vertical = 0 -custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) -custom_fonts/font = SubResource( 8 ) -text = "Wrong Way! Turn Around!" -align = 1 -__meta__ = { -"_edit_use_anchors_": false -} - -[connection signal="lap_complete" from="Track" to="TrackGUI" method="_on_lap_complete"] -[connection signal="time_updated" from="Track" to="TrackGUI" method="_on_time_updated"] -[connection signal="wrong_way" from="Track" to="TrackGUI" method="_on_wrong_way_detected"] diff --git a/scenes/trackgui.tscn b/scenes/trackgui.tscn new file mode 100644 index 0000000..e5d56d4 --- /dev/null +++ b/scenes/trackgui.tscn @@ -0,0 +1,104 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://assets/fonts/kenney-future-narrow.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://scenes/trackgui.gd" type="Script" id=2] + +[sub_resource type="DynamicFont" id=1] +size = 36 +outline_size = 2 +outline_color = Color( 1, 1, 1, 0.317647 ) +font_data = ExtResource( 1 ) + +[node name="TrackGUI" type="MarginContainer"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 20.0 +margin_top = 20.0 +margin_right = -20.0 +margin_bottom = -20.0 +script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +margin_right = 984.0 +margin_bottom = 560.0 + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +margin_right = 984.0 +margin_bottom = 41.0 + +[node name="TimeLabel" type="Label" parent="VBoxContainer/HBoxContainer"] +margin_right = 289.0 +margin_bottom = 41.0 +size_flags_horizontal = 3 +size_flags_vertical = 0 +custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) +custom_fonts/font = SubResource( 1 ) +text = "Current lap -" +align = 1 +valign = 1 + +[node name="TimeValue" type="Label" parent="VBoxContainer/HBoxContainer"] +margin_left = 297.0 +margin_right = 489.0 +margin_bottom = 41.0 +size_flags_horizontal = 3 +size_flags_vertical = 0 +custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) +custom_fonts/font = SubResource( 1 ) +text = "12:23.245" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Divider" type="Label" parent="VBoxContainer/HBoxContainer"] +margin_left = 497.0 +margin_right = 562.0 +margin_bottom = 41.0 +size_flags_horizontal = 3 +size_flags_vertical = 0 +custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) +custom_fonts/font = SubResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="BestTimeLabel" type="Label" parent="VBoxContainer/HBoxContainer"] +margin_left = 570.0 +margin_right = 784.0 +margin_bottom = 41.0 +size_flags_horizontal = 3 +size_flags_vertical = 0 +custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) +custom_fonts/font = SubResource( 1 ) +text = "Best Lap -" + +[node name="BestTimeValue" type="Label" parent="VBoxContainer/HBoxContainer"] +margin_left = 792.0 +margin_right = 984.0 +margin_bottom = 41.0 +size_flags_horizontal = 3 +size_flags_vertical = 0 +custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) +custom_fonts/font = SubResource( 1 ) +text = "01:23.256" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="WrongWayLabel" type="Label" parent="VBoxContainer"] +visible = false +margin_top = 49.0 +margin_right = 984.0 +margin_bottom = 90.0 +size_flags_horizontal = 3 +size_flags_vertical = 0 +custom_colors/font_color = Color( 0.482353, 0, 0, 1 ) +custom_fonts/font = SubResource( 1 ) +text = "Wrong Way! Turn Around!" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/scenes/track.gd b/scenes/tracks/track.gd similarity index 100% rename from scenes/track.gd rename to scenes/tracks/track.gd diff --git a/scenes/tracks/track.tscn b/scenes/tracks/track.tscn new file mode 100644 index 0000000..88b7403 --- /dev/null +++ b/scenes/tracks/track.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://scenes/tracks/track.gd" type="Script" id=1] +[ext_resource path="res://scenes/trackgui.tscn" type="PackedScene" id=2] + +[sub_resource type="SpatialMaterial" id=7] +flags_transparent = true +albedo_color = Color( 0.0470588, 0.956863, 0.921569, 0.439216 ) + +[node name="Track" type="Spatial"] +script = ExtResource( 1 ) +debug_material = SubResource( 7 ) + +[node name="Checkpoints" type="Spatial" parent="."] + +[node name="TrackGUI" parent="." instance=ExtResource( 2 )] + +[connection signal="lap_complete" from="." to="TrackGUI" method="_on_lap_complete"] +[connection signal="time_updated" from="." to="TrackGUI" method="_on_time_updated"] +[connection signal="wrong_way" from="." to="TrackGUI" method="_on_wrong_way_detected"]