diff --git a/project.godot b/project.godot index 4f53925..ea54c46 100644 --- a/project.godot +++ b/project.godot @@ -21,6 +21,10 @@ window/size/viewport_width=1920 window/size/viewport_height=1080 window/stretch/mode="viewport" +[file_customization] + +folder_colors={} + [input] move_right={ @@ -49,6 +53,11 @@ grab={ ] } +[layer_names] + +2d_physics/layer_1="impact" +2d_physics/layer_2="freinage" + [rendering] renderer/rendering_method="gl_compatibility" diff --git a/scenes/pathFollow.gd b/scenes/pathFollow.gd index bef730a..6ee8c1a 100644 --- a/scenes/pathFollow.gd +++ b/scenes/pathFollow.gd @@ -12,4 +12,5 @@ func _process(delta: float) -> void: progress += car.speed * delta if progress_ratio > 1: progress_ratio = progress_ratio - 1 - car.moveTo(position); + if progress_ratio > 0: + car.moveTo(position); diff --git a/scenes/sta6114.tmp b/scenes/sta6114.tmp new file mode 100644 index 0000000..e358060 --- /dev/null +++ b/scenes/sta6114.tmp @@ -0,0 +1,76 @@ +[gd_scene load_steps=10 format=3 uid="uid://b4ydi1vv8dvwr"] + +[ext_resource type="PackedScene" uid="uid://d1oqt6sbjvopi" path="res://maps/world.tscn" id="1_6vs81"] +[ext_resource type="PackedScene" uid="uid://vclpg4e4ql54" path="res://caracters/player/player.tscn" id="2_5x6b5"] +[ext_resource type="PackedScene" uid="uid://cl201baro5y5" path="res://vehicules/npc_car.tscn" id="3_yuakw"] +[ext_resource type="PackedScene" uid="uid://bt1p311rn1h6q" path="res://vehicules/car.tscn" id="4_bqm78"] +[ext_resource type="PackedScene" uid="uid://drwmmg2b6nlih" path="res://urban_furnitures/facing_south/high_road_sign.tscn" id="5_3rm0b"] +[ext_resource type="PackedScene" uid="uid://c6nlrmhu8362v" path="res://urban_furnitures/facing_south/high_semaphore.tscn" id="6_xgcq1"] +[ext_resource type="PackedScene" uid="uid://bmunphhwcsl3a" path="res://urban_furnitures/facing_north/high_semaphore.tscn" id="7_5gfx2"] + +[sub_resource type="Curve2D" id="Curve2D_shblg"] +_data = { +"points": PackedVector2Array(0, 0, 0, 0, -285, 193, -110.06, 94.1858, 110.06, -94.1858, 52, 134, -159.798, 75.137, 159.798, -75.137, 204, 13, -116.409, -28.5732, 116.409, 28.5732, 2206, -11, -93.6567, -28.0441, 93.6567, 28.0441, 2387, 165, -119.584, 76.7244, 119.584, -76.7244, 2750, 126, 108.472, 48.6803, -108.472, -48.6803, 2737, -309, 122.23, -57.1464, -122.23, 57.1464, 2340, -323, 76.1953, -36.5102, -76.1953, 36.5102, 2167, -129, 107.414, 77.2535, -107.414, -77.2535, 158, -148, 57.4153, 72.8272, -57.4153, -72.8272, 39, -293, 113.137, -95.6951, -113.137, 95.6951, -405, -291, -94.7149, -70.9039, 94.7149, 70.9039, -413, 128, 0, 0, 0, 0, -286, 193, 0, 0, 0, 0, -285, 193) +} +point_count = 15 + +[sub_resource type="Curve2D" id="Curve2D_nircx"] +_data = { +"points": PackedVector2Array(0, 0, 0, 0, 803, 1569, 0, 0, 0, 0, 910, 1573, 0, 0, 0, 0, 913, 1368, 0, 0, 0, 0, 1926, 1371, 0, 0, 0, 0, 1931, 342, 0, 0, 0, 0, 2082, 333, 0, 0, 0, 0, 2060, -140, 0, 0, 0, 0, 1718, -143, 0, 0, 0, 0, 1649, 73, 0, 0, 0, 0, 899, 51, 0, 0, 0, 0, 904, -1165, 0, 0, 0, 0, -890, -1162, 0, 0, 0, 0, -886, -119, 0, 0, 0, 0, -1062, -106, 0, 0, 0, 0, -1076, 268, 0, 0, 0, 0, -630, 271, 0, 0, 0, 0, -616, 161, 0, 0, 0, 0, 858, 167, 0, 0, 0, 0, 806, 1560) +} +point_count = 19 + +[node name="scene1" type="Node2D"] + +[node name="monde" parent="." instance=ExtResource("1_6vs81")] + +[node name="movibles" type="Node2D" parent="."] + +[node name="player" parent="movibles" instance=ExtResource("2_5x6b5")] +position = Vector2(87, 74) + +[node name="cars" type="Node" parent="movibles"] + +[node name="Path2D" type="Path2D" parent="movibles/cars"] +position = Vector2(-664, 181) +curve = SubResource("Curve2D_shblg") + +[node name="voiture_pnj" parent="movibles/cars/Path2D" node_paths=PackedStringArray("car") instance=ExtResource("3_yuakw")] +position = Vector2(-285, 193) +car = NodePath("../Car") +speed = 0.2 +distanceMax = 200 + +[node name="Car" parent="movibles/cars/Path2D" instance=ExtResource("4_bqm78")] +position = Vector2(-287, 196) +speed = 500 + +[node name="Path2D2" type="Path2D" parent="movibles/cars"] +curve = SubResource("Curve2D_nircx") + +[node name="voiture_pnj" parent="movibles/cars/Path2D2" node_paths=PackedStringArray("car") instance=ExtResource("3_yuakw")] +position = Vector2(803, 1569) +car = NodePath("../Car") +speed = 0.1 +distanceMax = 150 + +[node name="Car" parent="movibles/cars/Path2D2" instance=ExtResource("4_bqm78")] +position = Vector2(803, 1558) +speed = 400 + +[node name="statics" type="Node2D" parent="."] +position = Vector2(690, -8) + +[node name="roadSign1" parent="statics" instance=ExtResource("5_3rm0b")] +position = Vector2(-1538, 118) + +[node name="roadSign2" parent="statics" instance=ExtResource("5_3rm0b")] +position = Vector2(9, -1201) + +[node name="Sempahore" parent="." node_paths=PackedStringArray("dependantSemaphore") instance=ExtResource("6_xgcq1")] +position = Vector2(160, -14) +dependantSemaphore = NodePath("../Semaphore2") + +[node name="Semaphore2" parent="." instance=ExtResource("7_5gfx2")] +position = Vector2(-94, 258) +hasOwnTimerEnabled = false diff --git a/scenes/sta748D.tmp b/scenes/sta748D.tmp new file mode 100644 index 0000000..e358060 --- /dev/null +++ b/scenes/sta748D.tmp @@ -0,0 +1,76 @@ +[gd_scene load_steps=10 format=3 uid="uid://b4ydi1vv8dvwr"] + +[ext_resource type="PackedScene" uid="uid://d1oqt6sbjvopi" path="res://maps/world.tscn" id="1_6vs81"] +[ext_resource type="PackedScene" uid="uid://vclpg4e4ql54" path="res://caracters/player/player.tscn" id="2_5x6b5"] +[ext_resource type="PackedScene" uid="uid://cl201baro5y5" path="res://vehicules/npc_car.tscn" id="3_yuakw"] +[ext_resource type="PackedScene" uid="uid://bt1p311rn1h6q" path="res://vehicules/car.tscn" id="4_bqm78"] +[ext_resource type="PackedScene" uid="uid://drwmmg2b6nlih" path="res://urban_furnitures/facing_south/high_road_sign.tscn" id="5_3rm0b"] +[ext_resource type="PackedScene" uid="uid://c6nlrmhu8362v" path="res://urban_furnitures/facing_south/high_semaphore.tscn" id="6_xgcq1"] +[ext_resource type="PackedScene" uid="uid://bmunphhwcsl3a" path="res://urban_furnitures/facing_north/high_semaphore.tscn" id="7_5gfx2"] + +[sub_resource type="Curve2D" id="Curve2D_shblg"] +_data = { +"points": PackedVector2Array(0, 0, 0, 0, -285, 193, -110.06, 94.1858, 110.06, -94.1858, 52, 134, -159.798, 75.137, 159.798, -75.137, 204, 13, -116.409, -28.5732, 116.409, 28.5732, 2206, -11, -93.6567, -28.0441, 93.6567, 28.0441, 2387, 165, -119.584, 76.7244, 119.584, -76.7244, 2750, 126, 108.472, 48.6803, -108.472, -48.6803, 2737, -309, 122.23, -57.1464, -122.23, 57.1464, 2340, -323, 76.1953, -36.5102, -76.1953, 36.5102, 2167, -129, 107.414, 77.2535, -107.414, -77.2535, 158, -148, 57.4153, 72.8272, -57.4153, -72.8272, 39, -293, 113.137, -95.6951, -113.137, 95.6951, -405, -291, -94.7149, -70.9039, 94.7149, 70.9039, -413, 128, 0, 0, 0, 0, -286, 193, 0, 0, 0, 0, -285, 193) +} +point_count = 15 + +[sub_resource type="Curve2D" id="Curve2D_nircx"] +_data = { +"points": PackedVector2Array(0, 0, 0, 0, 803, 1569, 0, 0, 0, 0, 910, 1573, 0, 0, 0, 0, 913, 1368, 0, 0, 0, 0, 1926, 1371, 0, 0, 0, 0, 1931, 342, 0, 0, 0, 0, 2082, 333, 0, 0, 0, 0, 2060, -140, 0, 0, 0, 0, 1718, -143, 0, 0, 0, 0, 1649, 73, 0, 0, 0, 0, 899, 51, 0, 0, 0, 0, 904, -1165, 0, 0, 0, 0, -890, -1162, 0, 0, 0, 0, -886, -119, 0, 0, 0, 0, -1062, -106, 0, 0, 0, 0, -1076, 268, 0, 0, 0, 0, -630, 271, 0, 0, 0, 0, -616, 161, 0, 0, 0, 0, 858, 167, 0, 0, 0, 0, 806, 1560) +} +point_count = 19 + +[node name="scene1" type="Node2D"] + +[node name="monde" parent="." instance=ExtResource("1_6vs81")] + +[node name="movibles" type="Node2D" parent="."] + +[node name="player" parent="movibles" instance=ExtResource("2_5x6b5")] +position = Vector2(87, 74) + +[node name="cars" type="Node" parent="movibles"] + +[node name="Path2D" type="Path2D" parent="movibles/cars"] +position = Vector2(-664, 181) +curve = SubResource("Curve2D_shblg") + +[node name="voiture_pnj" parent="movibles/cars/Path2D" node_paths=PackedStringArray("car") instance=ExtResource("3_yuakw")] +position = Vector2(-285, 193) +car = NodePath("../Car") +speed = 0.2 +distanceMax = 200 + +[node name="Car" parent="movibles/cars/Path2D" instance=ExtResource("4_bqm78")] +position = Vector2(-287, 196) +speed = 500 + +[node name="Path2D2" type="Path2D" parent="movibles/cars"] +curve = SubResource("Curve2D_nircx") + +[node name="voiture_pnj" parent="movibles/cars/Path2D2" node_paths=PackedStringArray("car") instance=ExtResource("3_yuakw")] +position = Vector2(803, 1569) +car = NodePath("../Car") +speed = 0.1 +distanceMax = 150 + +[node name="Car" parent="movibles/cars/Path2D2" instance=ExtResource("4_bqm78")] +position = Vector2(803, 1558) +speed = 400 + +[node name="statics" type="Node2D" parent="."] +position = Vector2(690, -8) + +[node name="roadSign1" parent="statics" instance=ExtResource("5_3rm0b")] +position = Vector2(-1538, 118) + +[node name="roadSign2" parent="statics" instance=ExtResource("5_3rm0b")] +position = Vector2(9, -1201) + +[node name="Sempahore" parent="." node_paths=PackedStringArray("dependantSemaphore") instance=ExtResource("6_xgcq1")] +position = Vector2(160, -14) +dependantSemaphore = NodePath("../Semaphore2") + +[node name="Semaphore2" parent="." instance=ExtResource("7_5gfx2")] +position = Vector2(-94, 258) +hasOwnTimerEnabled = false diff --git a/scenes/start.tscn b/scenes/start.tscn index 90c8556..ff4c596 100644 --- a/scenes/start.tscn +++ b/scenes/start.tscn @@ -1,22 +1,28 @@ -[gd_scene load_steps=8 format=3 uid="uid://b4ydi1vv8dvwr"] +[gd_scene load_steps=12 format=3 uid="uid://b4ydi1vv8dvwr"] [ext_resource type="PackedScene" uid="uid://d1oqt6sbjvopi" path="res://maps/world.tscn" id="1_6vs81"] [ext_resource type="PackedScene" uid="uid://vclpg4e4ql54" path="res://caracters/player/player.tscn" id="2_5x6b5"] [ext_resource type="PackedScene" uid="uid://cl201baro5y5" path="res://vehicules/npc_car.tscn" id="3_yuakw"] [ext_resource type="PackedScene" uid="uid://bt1p311rn1h6q" path="res://vehicules/car.tscn" id="4_bqm78"] -[ext_resource type="PackedScene" uid="uid://drwmmg2b6nlih" path="res://urban_furnitures/high_road_sign.tscn" id="5_3rm0b"] +[ext_resource type="PackedScene" uid="uid://drwmmg2b6nlih" path="res://urban_furnitures/facing_south/high_road_sign.tscn" id="5_3rm0b"] +[ext_resource type="PackedScene" uid="uid://c6nlrmhu8362v" path="res://urban_furnitures/facing_south/high_semaphore.tscn" id="6_xgcq1"] +[ext_resource type="PackedScene" uid="uid://bmunphhwcsl3a" path="res://urban_furnitures/facing_north/high_semaphore.tscn" id="7_5gfx2"] +[ext_resource type="PackedScene" uid="uid://dpyadhlqawviq" path="res://vehicules/brakeZone.tscn" id="8_q1enh"] [sub_resource type="Curve2D" id="Curve2D_shblg"] _data = { -"points": PackedVector2Array(0, 0, 0, 0, -285, 193, -110.06, 94.1858, 110.06, -94.1858, 52, 134, -159.798, 75.137, 159.798, -75.137, 204, 13, -116.409, -28.5732, 116.409, 28.5732, 2206, -11, -93.6567, -28.0441, 93.6567, 28.0441, 2387, 165, -119.584, 76.7244, 119.584, -76.7244, 2750, 126, 108.472, 48.6803, -108.472, -48.6803, 2737, -309, 122.23, -57.1464, -122.23, 57.1464, 2340, -323, 76.1953, -36.5102, -76.1953, 36.5102, 2167, -129, 107.414, 77.2535, -107.414, -77.2535, 158, -148, 57.4153, 72.8272, -57.4153, -72.8272, 39, -293, 113.137, -95.6951, -113.137, 95.6951, -405, -291, -94.7149, -70.9039, 94.7149, 70.9039, -413, 128, 0, 0, 0, 0, -286, 193, 0, 0, 0, 0, -285, 193) +"points": PackedVector2Array(0, 0, 0, 0, -285, 193, -72.1029, 112.165, 72.1029, -112.165, 62, 108, -92.8736, 1.22052, 92.8736, -1.22052, 220, -16, -72.4586, -10.5935, 72.4586, 10.5935, 2206, -11, -122.624, -4.07119, 122.624, 4.07119, 2387, 165, -98.6077, 103.694, 98.6077, -103.694, 2759, 110, 117.462, 37.6927, -117.462, -37.6927, 2715, -276, 114.239, -35.1712, -114.239, 35.1712, 2384, -293, 50.2246, -13.5362, -50.2246, 13.5362, 2209, -126, 61.4659, 8.33138, -61.4659, -8.33138, 133, -135, 40.4345, 62.8385, -40.4345, -62.8385, 40, -272, 50.2081, -75.7177, -50.2081, 75.7177, -399, -242, -67.7454, -78.8949, 67.7454, 78.8949, -399, 107, 0, 0, 0, 0, -286, 193, 0, 0, 0, 0, -285, 193) } point_count = 15 [sub_resource type="Curve2D" id="Curve2D_nircx"] _data = { -"points": PackedVector2Array(0, 0, 0, 0, 803, 1569, 0, 0, 0, 0, 910, 1573, 0, 0, 0, 0, 913, 1368, 0, 0, 0, 0, 1926, 1371, 0, 0, 0, 0, 1931, 342, 0, 0, 0, 0, 2082, 333, 0, 0, 0, 0, 2060, -140, 0, 0, 0, 0, 1718, -143, 0, 0, 0, 0, 1649, 73, 0, 0, 0, 0, 899, 51, 0, 0, 0, 0, 904, -1165, 0, 0, 0, 0, -890, -1162, 0, 0, 0, 0, -886, -119, 0, 0, 0, 0, -1062, -106, 0, 0, 0, 0, -1076, 268, 0, 0, 0, 0, -630, 271, 0, 0, 0, 0, -616, 161, 0, 0, 0, 0, 858, 167, 0, 0, 0, 0, 806, 1560) +"points": PackedVector2Array(0, 0, 0, 0, 803, 1569, 0, 0, 0, 0, 910, 1573, 0, 0, 0, 0, 913, 1368, 0, 0, 0, 0, 1926, 1371, 0, 0, 0, 0, 1931, 342, 0, 0, 0, 0, 2082, 333, 0, 0, 0, 0, 2060, -140, 0, 0, 0, 0, 1718, -143, 0, 0, 0, 0, 1649, 73, 0, 0, 0, 0, 912.469, 60.5339, 0, 0, 0, 0, 848, 58, 0, 0, 0, 0, 873, -21, 0, 0, 0, 0, 904, -1165, 0, 0, 0, 0, -890, -1162, 0, 0, 0, 0, -886, -119, 0, 0, 0, 0, -1062, -106, 0, 0, 0, 0, -1076, 268, 0, 0, 0, 0, -630, 271, 0, 0, 0, 0, -616, 161, 0, 0, 0, 0, 858, 167, 0, 0, 0, 0, 806, 238, 0, 0, 0, 0, 806, 1560) } -point_count = 19 +point_count = 22 + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_tmewa"] +size = Vector2(79, 94) [node name="scene1" type="Node2D"] @@ -60,7 +66,25 @@ speed = 400 position = Vector2(690, -8) [node name="roadSign1" parent="statics" instance=ExtResource("5_3rm0b")] -position = Vector2(5, 2) +position = Vector2(-1538, 118) [node name="roadSign2" parent="statics" instance=ExtResource("5_3rm0b")] -position = Vector2(-1158, 4) +position = Vector2(9, -1201) + +[node name="Sempahore" parent="." node_paths=PackedStringArray("dependantSemaphore") instance=ExtResource("6_xgcq1")] +position = Vector2(160, -14) +dependantSemaphore = NodePath("../Semaphore2") + +[node name="Semaphore2" parent="." instance=ExtResource("7_5gfx2")] +position = Vector2(-94, 258) +hasOwnTimerEnabled = false + +[node name="brakeZones" type="Node2D" parent="."] + +[node name="Area2D" parent="brakeZones" instance=ExtResource("8_q1enh")] +position = Vector2(1016, 59) +fullStop = false + +[node name="CollisionShape2D" type="CollisionShape2D" parent="brakeZones/Area2D"] +position = Vector2(-9.5, 6) +shape = SubResource("RectangleShape2D_tmewa") diff --git a/urban_furnitures/facing_north/high_semaphore.tscn b/urban_furnitures/facing_north/high_semaphore.tscn new file mode 100644 index 0000000..7e20e9f --- /dev/null +++ b/urban_furnitures/facing_north/high_semaphore.tscn @@ -0,0 +1,73 @@ +[gd_scene load_steps=8 format=4 uid="uid://bmunphhwcsl3a"] + +[ext_resource type="Script" path="res://urban_furnitures/high_semaphore.gd" id="2_nih7h"] +[ext_resource type="TileSet" uid="uid://ckj00wy20rkfx" path="res://assest/tilesets/exterieur.tres" id="3_ulyk6"] +[ext_resource type="PackedScene" uid="uid://brh7cqaxc13ie" path="res://zindex/ZIndexControler.tscn" id="4_k52t8"] +[ext_resource type="PackedScene" uid="uid://dpyadhlqawviq" path="res://vehicules/brakeZone.tscn" id="5_o0gjx"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_4c8ro"] +radius = 15.0 + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_36vt6"] +size = Vector2(20, 3) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_y0214"] +size = Vector2(200, 95.5) + +[node name="Node2D" type="Node2D"] +script = ExtResource("2_nih7h") + +[node name="Sempahore" type="StaticBody2D" parent="."] + +[node name="abovePart" type="TileMapLayer" parent="Sempahore"] +z_index = 2000 +tile_map_data = PackedByteArray("AAAAAPv/BAAXAH0AAAAAAPz/BAAXAH4AAAABAPv/BAAYAH0AAAABAPz/BAAYAH4AAAACAPv/BAAZAH0AAAACAPz/BAAZAH4AAAA=") +tile_set = ExtResource("3_ulyk6") + +[node name="red" type="TileMapLayer" parent="Sempahore/abovePart"] +z_index = 2000 +tile_map_data = PackedByteArray("AAABAPv/BAAKAIgAAAABAPz/BAAKAIkAAAACAPv/BAALAIgAAAACAPz/BAALAIkAAAA=") +tile_set = ExtResource("3_ulyk6") + +[node name="yellow" type="TileMapLayer" parent="Sempahore/abovePart"] +z_index = 2000 +tile_map_data = PackedByteArray("AAABAPv/BAAKAIgAAAABAPz/BAAKAIkAAAACAPv/BAALAIgAAAACAPz/BAALAIkAAAA=") +tile_set = ExtResource("3_ulyk6") + +[node name="green" type="TileMapLayer" parent="Sempahore/abovePart"] +z_index = 2000 +tile_map_data = PackedByteArray("AAABAPv/BAAKAIgAAAABAPz/BAAKAIkAAAACAPv/BAALAIgAAAACAPz/BAALAIkAAAA=") +tile_set = ExtResource("3_ulyk6") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Sempahore"] +position = Vector2(20, -15) +shape = SubResource("CircleShape2D_4c8ro") + +[node name="pylon" type="TileMapLayer" parent="Sempahore"] +tile_map_data = PackedByteArray("AAAAAP3/BAATAH8AAAAAAP7/BAATAIAAAAAAAP//BAATAIEAAAA=") +tile_set = ExtResource("3_ulyk6") + +[node name="ZIndexControler" parent="Sempahore" instance=ExtResource("4_k52t8")] +position = Vector2(-2, 6) + +[node name="ShapeCast2D" type="ShapeCast2D" parent="Sempahore/ZIndexControler"] +position = Vector2(21, -15) +shape = SubResource("RectangleShape2D_36vt6") +target_position = Vector2(-2, -125) + +[node name="Timer" type="Timer" parent="."] +wait_time = 5.0 +one_shot = true +autostart = true + +[node name="Label" type="Label" parent="."] +offset_right = 40.0 +offset_bottom = 23.0 + +[node name="brakeZone" parent="." instance=ExtResource("5_o0gjx")] + +[node name="CollisionShape2D2" type="CollisionShape2D" parent="brakeZone"] +position = Vector2(-75, -75.25) +shape = SubResource("RectangleShape2D_y0214") + +[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] diff --git a/urban_furnitures/high_road_sign.tscn b/urban_furnitures/facing_south/high_road_sign.tscn similarity index 78% rename from urban_furnitures/high_road_sign.tscn rename to urban_furnitures/facing_south/high_road_sign.tscn index 7b7dc1c..fdd4110 100644 --- a/urban_furnitures/high_road_sign.tscn +++ b/urban_furnitures/facing_south/high_road_sign.tscn @@ -13,12 +13,18 @@ size = Vector2(20, 3) [node name="toit" type="TileMapLayer" parent="."] z_index = 2000 -tile_map_data = PackedByteArray("AAD9//3/BAAQAH8AAAD+//z/BAARAH4AAAD+//3/BAARAH8AAAD///v/BAASAH0AAAD///z/BAASAH4AAAD///3/BAASAH8AAAAAAPv/BAATAH0AAAAAAPz/BAATAH4AAAA=") +tile_map_data = PackedByteArray("AAD9//3/BAAQAH8AAAD+//z/BAARAH4AAAD///v/BAASAH0AAAD///z/BAASAH4AAAD///3/BAASAH8AAAAAAPv/BAATAH0AAAAAAPz/BAATAH4AAAD+//3/BAARAH8AAAA=") tile_set = ExtResource("1_7l72r") [node name="TileMapLayer2" type="TileMapLayer" parent="toit"] z_index = 2000 -tile_map_data = PackedByteArray("AAD+//3/BAAUAH0AAAD+//7/BAAUAH4AAAA=") +tile_map_data = PackedByteArray("AAD+//3/BAALAH0AAAD+//7/BAALAH4AAAA=") +tile_set = ExtResource("1_7l72r") + +[node name="TileMapLayer3" type="TileMapLayer" parent="toit"] +z_index = 2000 +position = Vector2(48, -27) +tile_map_data = PackedByteArray("AAD+//3/BAAVAH0AAAD+//7/BAAVAH4AAAA=") tile_set = ExtResource("1_7l72r") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] diff --git a/urban_furnitures/facing_south/high_semaphore.tscn b/urban_furnitures/facing_south/high_semaphore.tscn new file mode 100644 index 0000000..933d423 --- /dev/null +++ b/urban_furnitures/facing_south/high_semaphore.tscn @@ -0,0 +1,69 @@ +[gd_scene load_steps=8 format=4 uid="uid://c6nlrmhu8362v"] + +[ext_resource type="Script" path="res://urban_furnitures/high_semaphore.gd" id="1_1ufoq"] +[ext_resource type="TileSet" uid="uid://ckj00wy20rkfx" path="res://assest/tilesets/exterieur.tres" id="1_03yma"] +[ext_resource type="PackedScene" uid="uid://brh7cqaxc13ie" path="res://zindex/ZIndexControler.tscn" id="2_hhwk3"] +[ext_resource type="PackedScene" uid="uid://dpyadhlqawviq" path="res://vehicules/brakeZone.tscn" id="4_j5rhp"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_4c8ro"] +radius = 15.0 + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_36vt6"] +size = Vector2(20, 3) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_4glgt"] +size = Vector2(200, 102) + +[node name="Node2D" type="Node2D"] +script = ExtResource("1_1ufoq") + +[node name="Sempahore" type="StaticBody2D" parent="."] + +[node name="abovePart" type="TileMapLayer" parent="Sempahore"] +z_index = 2000 +tile_map_data = PackedByteArray("AAD9//3/BAAQAH8AAAD+//z/BAARAH4AAAD+//3/BAARAH8AAAD///v/BAASAH0AAAD///z/BAASAH4AAAD///3/BAASAH8AAAAAAPv/BAATAH0AAAAAAPz/BAATAH4AAAA=") +tile_set = ExtResource("1_03yma") + +[node name="red" type="TileMapLayer" parent="Sempahore/abovePart"] +z_index = 2000 +tile_map_data = PackedByteArray("AAD+//3/BAAOAH0AAAD+//7/BAAOAH4AAAD///3/BAAPAH0AAAA=") +tile_set = ExtResource("1_03yma") + +[node name="yellow" type="TileMapLayer" parent="Sempahore/abovePart"] +z_index = 2000 +tile_map_data = PackedByteArray("AAD+//3/BAAOAH8AAAD+//7/BAAOAIAAAAD///3/BAAPAH8AAAA=") +tile_set = ExtResource("1_03yma") + +[node name="green" type="TileMapLayer" parent="Sempahore/abovePart"] +z_index = 2000 +tile_map_data = PackedByteArray("AAD+//3/BAAOAIEAAAD+//7/BAAOAIIAAAD///3/BAAPAIEAAAA=") +tile_set = ExtResource("1_03yma") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Sempahore"] +position = Vector2(20, -15) +shape = SubResource("CircleShape2D_4c8ro") + +[node name="pylon" type="TileMapLayer" parent="Sempahore"] +tile_map_data = PackedByteArray("AAAAAP3/BAATAH8AAAAAAP7/BAATAIAAAAAAAP//BAATAIEAAAA=") +tile_set = ExtResource("1_03yma") + +[node name="ZIndexControler" parent="Sempahore" instance=ExtResource("2_hhwk3")] +position = Vector2(-2, 6) + +[node name="ShapeCast2D" type="ShapeCast2D" parent="Sempahore/ZIndexControler"] +position = Vector2(21, -15) +shape = SubResource("RectangleShape2D_36vt6") +target_position = Vector2(-2, -125) + +[node name="brakeZone" parent="." instance=ExtResource("4_j5rhp")] + +[node name="CollisionShape2D3" type="CollisionShape2D" parent="brakeZone"] +position = Vector2(110, 66) +shape = SubResource("RectangleShape2D_4glgt") + +[node name="Timer" type="Timer" parent="."] +wait_time = 5.0 +one_shot = true +autostart = true + +[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] diff --git a/urban_furnitures/high_semaphore.gd b/urban_furnitures/high_semaphore.gd new file mode 100644 index 0000000..3711d8d --- /dev/null +++ b/urban_furnitures/high_semaphore.gd @@ -0,0 +1,29 @@ +extends Node2D +class_name LightSemaphore + +@export var dependantSemaphore : LightSemaphore = null +@export var hasOwnTimerEnabled = true +@onready var lights := [$Sempahore/abovePart/green, $Sempahore/abovePart/yellow, $Sempahore/abovePart/red ]; +var light = 0; + +func _ready() -> void: + $brakeZone.get_child(1).disabled = !light; + +func change_light(): + light += 1; + if light > 2: + light = 0; + $brakeZone.get_child(1).disabled = !light; + for i in range (lights.size()): + lights[i].visible = i == light + +func _on_timer_timeout() -> void: + if hasOwnTimerEnabled: + if light == 0: + $Timer.wait_time = 1; + else: + $Timer.wait_time = 5; + $Timer.start() + change_light(); + if dependantSemaphore: + dependantSemaphore.change_light(); diff --git a/vehicules/brakeZone.tscn b/vehicules/brakeZone.tscn new file mode 100644 index 0000000..fdb8903 --- /dev/null +++ b/vehicules/brakeZone.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=2 format=3 uid="uid://dpyadhlqawviq"] + +[ext_resource type="Script" path="res://vehicules/brake_zone.gd" id="1_bbbt2"] + +[node name="BrakeZone" type="Area2D"] +collision_layer = 2 +collision_mask = 3 +script = ExtResource("1_bbbt2") + +[node name="Label" type="Label" parent="."] +offset_right = 40.0 +offset_bottom = 23.0 + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] +[connection signal="body_exited" from="." to="." method="_on_body_exited"] diff --git a/vehicules/brake_zone.gd b/vehicules/brake_zone.gd new file mode 100644 index 0000000..4397397 --- /dev/null +++ b/vehicules/brake_zone.gd @@ -0,0 +1,14 @@ +extends Node2D + +@export var fullStop: bool = true + +func _on_body_entered(body: Node2D) -> void: + $Label.text = str(body)+ " " + "body entered " + if body.has_method("brake"): + (body as Car).brake(fullStop) + + +func _on_body_exited(body: Node2D) -> void: + $Label.text = str(body)+ " " + "body exited " + if body.has_method("accelerate"): + (body as Car).accelerate() diff --git a/vehicules/car.gd b/vehicules/car.gd index c5c4629..558694d 100644 --- a/vehicules/car.gd +++ b/vehicules/car.gd @@ -3,9 +3,15 @@ extends CharacterBody2D @export var debugLabel: Label @export var speed = 750 # How fast the car will move (pixels/sec). +@export var acceleration = speed / 100 +@export var slowZoneSpeed = 300 +var current_speed = speed; @onready var animation_tree := $AnimationTree @onready var state_machine := animation_tree.get("parameters/driving/playback") as AnimationNodeStateMachinePlayback +var brakePedal = false; +var fullStop = false; + var last_facing_direction = Vector2(0,-1) # facing north var targetPosition = null @@ -19,13 +25,26 @@ func updateFacingDirectionInAnimationTree(): # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: + if brakePedal: + if fullStop: + current_speed = max(0, current_speed - acceleration) + else: + current_speed = max(slowZoneSpeed, current_speed - acceleration) + else: + current_speed = min(current_speed + acceleration, speed) $ZIndexControler/ShapeCast2D.enabled = !$CollisionHorizontal.disabled if (targetPosition != null): - velocity = (targetPosition - position) * speed * delta; + velocity = (targetPosition - position) * current_speed * delta; move_and_slide() if velocity: last_facing_direction = velocity.normalized() - updateFacingDirectionInAnimationTree() + +func brake(needsToStop : bool): + brakePedal = true; + fullStop = needsToStop; + +func accelerate(): + brakePedal = false; diff --git a/vehicules/car.tscn b/vehicules/car.tscn index 39a01de..acb6e7e 100644 --- a/vehicules/car.tscn +++ b/vehicules/car.tscn @@ -550,9 +550,10 @@ radius = 31.0 height = 186.0 [sub_resource type="RectangleShape2D" id="RectangleShape2D_yiphh"] -size = Vector2(240, 15) +size = Vector2(200, 15) [node name="Car" type="CharacterBody2D" node_paths=PackedStringArray("debugLabel")] +collision_mask = 3 motion_mode = 1 script = ExtResource("1_vkq5y") debugLabel = NodePath("Label") @@ -600,4 +601,4 @@ offset_bottom = -19.0 [node name="ShapeCast2D" type="ShapeCast2D" parent="ZIndexControler"] position = Vector2(1, -13) shape = SubResource("RectangleShape2D_yiphh") -target_position = Vector2(0, -46) +target_position = Vector2(1, -32) diff --git a/zindex/z_index_controler.gd b/zindex/z_index_controler.gd index 99c44fd..6a03541 100644 --- a/zindex/z_index_controler.gd +++ b/zindex/z_index_controler.gd @@ -12,7 +12,7 @@ func _process(delta: float) -> void: var hasManipulatedZIndex = false if $ShapeCast2D.is_colliding(): var nbCollisions = $ShapeCast2D.get_collision_count() - for n in range(8): + for n in range(nbCollisions): var colider = $ShapeCast2D.get_collider(n) as Node2D if colider != null and colider != get_parent(): (get_parent() as Node2D).z_index = colider.z_index+1