diff options
-rw-r--r-- | Assets/road.png | bin | 0 -> 252 bytes | |||
-rw-r--r-- | Assets/road.png.import | 34 | ||||
-rw-r--r-- | Levels/Level1.tscn | 18 | ||||
-rw-r--r-- | Levels/Level2.tscn | 16 | ||||
-rw-r--r-- | Levels/Level3.tscn | 16 | ||||
-rw-r--r-- | Levels/Level_test_2.tscn | 18 | ||||
-rw-r--r-- | Levels/Tut01.tscn | 16 | ||||
-rw-r--r-- | Levels/Tut02.tscn | 19 | ||||
-rw-r--r-- | Levels/Tut03.tscn | 18 | ||||
-rw-r--r-- | Scripts/Road.gd | 86 | ||||
-rw-r--r-- | Scripts/drawing.gd | 3 |
11 files changed, 217 insertions, 27 deletions
diff --git a/Assets/road.png b/Assets/road.png Binary files differnew file mode 100644 index 0000000..5acc2e9 --- /dev/null +++ b/Assets/road.png diff --git a/Assets/road.png.import b/Assets/road.png.import new file mode 100644 index 0000000..52c0241 --- /dev/null +++ b/Assets/road.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://x8c4q8wv8u4o" +path="res://.godot/imported/road.png-c3c47e2cc8c90beae2ad5c8a3bb2c3ca.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/road.png" +dest_files=["res://.godot/imported/road.png-c3c47e2cc8c90beae2ad5c8a3bb2c3ca.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +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=1 diff --git a/Levels/Level1.tscn b/Levels/Level1.tscn index 3bd097a..74ffae4 100644 --- a/Levels/Level1.tscn +++ b/Levels/Level1.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://b7nxnsf8dirqk"] +[gd_scene load_steps=15 format=3 uid="uid://b7nxnsf8dirqk"] [ext_resource type="Script" path="res://Scripts/scene_control.gd" id="1_jvdy8"] [ext_resource type="PackedScene" uid="uid://c8r6i3bu37ogu" path="res://Nodes/ui.tscn" id="2_2bp3f"] @@ -8,6 +8,8 @@ [ext_resource type="Script" path="res://Scripts/drawing.gd" id="6_yls5q"] [ext_resource type="Texture2D" uid="uid://dg3v488vx0oj6" path="res://Assets/checkpoint.png" id="7_e50r0"] [ext_resource type="PackedScene" uid="uid://wkfai2lvnp7n" path="res://Nodes/checkpoint.tscn" id="8_mrrls"] +[ext_resource type="Texture2D" uid="uid://x8c4q8wv8u4o" path="res://Assets/road.png" id="8_yjlto"] +[ext_resource type="Script" path="res://Scripts/Road.gd" id="9_3mco4"] [ext_resource type="TileSet" uid="uid://cl8153posdeim" path="res://Assets/grass_tile_set.tres" id="9_m86ct"] [sub_resource type="CircleShape2D" id="CircleShape2D_qhju2"] @@ -52,9 +54,6 @@ z_index = 3 [node name="DrawNode" type="Node2D" parent="."] script = ExtResource("6_yls5q") -[node name="TrackLine" type="Line2D" parent="DrawNode"] -default_color = Color(0.870588, 0.870588, 0.870588, 0.431373) - [node name="TrackPath" type="Path2D" parent="DrawNode"] curve = SubResource("Curve2D_0exre") @@ -70,6 +69,17 @@ texture = ExtResource("7_e50r0") wait_time = 0.2 one_shot = true +[node name="TrackLine" type="Line2D" parent="DrawNode"] +texture_repeat = 2 +width = 70.0 +texture = ExtResource("8_yjlto") +texture_mode = 1 +script = ExtResource("9_3mco4") + +[node name="LeftBorder" type="Line2D" parent="DrawNode/TrackLine"] + +[node name="RightBorder" type="Line2D" parent="DrawNode/TrackLine"] + [node name="Checkpoints" type="Node" parent="."] [node name="Checkpoint" parent="Checkpoints" instance=ExtResource("8_mrrls")] diff --git a/Levels/Level2.tscn b/Levels/Level2.tscn index 812749e..fd2e379 100644 --- a/Levels/Level2.tscn +++ b/Levels/Level2.tscn @@ -6,8 +6,10 @@ [ext_resource type="Texture2D" uid="uid://cxhterify3l" path="res://Assets/Images/goal.png" id="4_euu0i"] [ext_resource type="PackedScene" uid="uid://c1mvbh2fwqtkb" path="res://Nodes/car.tscn" id="5_5co3o"] [ext_resource type="Script" path="res://Scripts/drawing.gd" id="6_hv33l"] +[ext_resource type="Texture2D" uid="uid://bcn7tgs6a4fm7" path="res://Assets/road.png" id="7_k0xyq"] [ext_resource type="TileSet" uid="uid://cl8153posdeim" path="res://Assets/grass_tile_set.tres" id="7_lgn1k"] [ext_resource type="PackedScene" uid="uid://wkfai2lvnp7n" path="res://Nodes/checkpoint.tscn" id="7_vm5ky"] +[ext_resource type="Script" path="res://Scripts/Road.gd" id="8_ni64o"] [sub_resource type="CircleShape2D" id="CircleShape2D_6g88q"] radius = 17.0 @@ -49,15 +51,23 @@ shape = SubResource("CircleShape2D_6g88q") [node name="DrawNode" type="Node2D" parent="."] script = ExtResource("6_hv33l") -[node name="TrackLine" type="Line2D" parent="DrawNode"] -default_color = Color(0.870588, 0.870588, 0.870588, 0.431373) - [node name="TrackPath" type="Path2D" parent="DrawNode"] curve = SubResource("Curve2D_0exre") [node name="TrackFollower" type="PathFollow2D" parent="DrawNode/TrackPath"] loop = false +[node name="TrackLine" type="Line2D" parent="DrawNode"] +texture_repeat = 2 +width = 70.0 +texture = ExtResource("7_k0xyq") +texture_mode = 1 +script = ExtResource("8_ni64o") + +[node name="LeftBorder" type="Line2D" parent="DrawNode/TrackLine"] + +[node name="RightBorder" type="Line2D" parent="DrawNode/TrackLine"] + [node name="Checkpoints" type="Node" parent="."] [node name="Checkpoint" parent="Checkpoints" instance=ExtResource("7_vm5ky")] diff --git a/Levels/Level3.tscn b/Levels/Level3.tscn index 689ec11..73cdd37 100644 --- a/Levels/Level3.tscn +++ b/Levels/Level3.tscn @@ -7,7 +7,9 @@ [ext_resource type="PackedScene" uid="uid://c1mvbh2fwqtkb" path="res://Nodes/car.tscn" id="5_ja277"] [ext_resource type="Script" path="res://Scripts/drawing.gd" id="6_c7w7m"] [ext_resource type="TileSet" uid="uid://cl8153posdeim" path="res://Assets/grass_tile_set.tres" id="7_2rtyp"] +[ext_resource type="Texture2D" uid="uid://bcn7tgs6a4fm7" path="res://Assets/road.png" id="7_7isac"] [ext_resource type="PackedScene" uid="uid://wkfai2lvnp7n" path="res://Nodes/checkpoint.tscn" id="7_c20c2"] +[ext_resource type="Script" path="res://Scripts/Road.gd" id="8_itqp7"] [sub_resource type="CircleShape2D" id="CircleShape2D_6g88q"] radius = 17.0 @@ -50,15 +52,23 @@ shape = SubResource("CircleShape2D_6g88q") [node name="DrawNode" type="Node2D" parent="."] script = ExtResource("6_c7w7m") -[node name="TrackLine" type="Line2D" parent="DrawNode"] -default_color = Color(0.870588, 0.870588, 0.870588, 0.431373) - [node name="TrackPath" type="Path2D" parent="DrawNode"] curve = SubResource("Curve2D_0exre") [node name="TrackFollower" type="PathFollow2D" parent="DrawNode/TrackPath"] loop = false +[node name="TrackLine" type="Line2D" parent="DrawNode"] +texture_repeat = 2 +width = 70.0 +texture = ExtResource("7_7isac") +texture_mode = 1 +script = ExtResource("8_itqp7") + +[node name="LeftBorder" type="Line2D" parent="DrawNode/TrackLine"] + +[node name="RightBorder" type="Line2D" parent="DrawNode/TrackLine"] + [node name="Checkpoints" type="Node" parent="."] [node name="Checkpoint" parent="Checkpoints" instance=ExtResource("7_c20c2")] diff --git a/Levels/Level_test_2.tscn b/Levels/Level_test_2.tscn index 350663f..2698b31 100644 --- a/Levels/Level_test_2.tscn +++ b/Levels/Level_test_2.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=11 format=3 uid="uid://b7nxnsf8dirqk"] +[gd_scene load_steps=13 format=3 uid="uid://b7nxnsf8dirqk"] [ext_resource type="Script" path="res://Scripts/scene_control.gd" id="1_amd1r"] [ext_resource type="PackedScene" uid="uid://c8r6i3bu37ogu" path="res://Nodes/ui.tscn" id="2_veexm"] [ext_resource type="Texture2D" uid="uid://cxhterify3l" path="res://Assets/Images/goal.png" id="3_4pkmo"] [ext_resource type="PackedScene" uid="uid://c1mvbh2fwqtkb" path="res://Nodes/car.tscn" id="5_vbxx6"] +[ext_resource type="Texture2D" uid="uid://bcn7tgs6a4fm7" path="res://Assets/road.png" id="6_5wji0"] [ext_resource type="Script" path="res://Scripts/drawing.gd" id="6_6cnd6"] +[ext_resource type="Script" path="res://Scripts/Road.gd" id="7_53orf"] [ext_resource type="Texture2D" uid="uid://bsadcfl3o65wb" path="res://Assets/Images/start.png" id="7_oyh3d"] [ext_resource type="PackedScene" uid="uid://wkfai2lvnp7n" path="res://Nodes/checkpoint.tscn" id="8_8dt61"] [ext_resource type="TileSet" uid="uid://cl8153posdeim" path="res://Assets/grass_tile_set.tres" id="8_dcy0l"] @@ -33,15 +35,23 @@ shape = SubResource("CircleShape2D_6g88q") [node name="DrawNode" type="Node2D" parent="."] script = ExtResource("6_6cnd6") -[node name="TrackLine" type="Line2D" parent="DrawNode"] -default_color = Color(0.870588, 0.870588, 0.870588, 0.431373) - [node name="TrackPath" type="Path2D" parent="DrawNode"] curve = SubResource("Curve2D_0exre") [node name="TrackFollower" type="PathFollow2D" parent="DrawNode/TrackPath"] loop = false +[node name="TrackLine" type="Line2D" parent="DrawNode"] +texture_repeat = 2 +width = 70.0 +texture = ExtResource("6_5wji0") +texture_mode = 1 +script = ExtResource("7_53orf") + +[node name="LeftBorder" type="Line2D" parent="DrawNode/TrackLine"] + +[node name="RightBorder" type="Line2D" parent="DrawNode/TrackLine"] + [node name="Checkpoints" type="Node" parent="."] [node name="Checkpoint" parent="Checkpoints" instance=ExtResource("8_8dt61")] diff --git a/Levels/Tut01.tscn b/Levels/Tut01.tscn index 8cb12d0..ab2a1e1 100644 --- a/Levels/Tut01.tscn +++ b/Levels/Tut01.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://bp56skqd5gqub"] +[gd_scene load_steps=13 format=3 uid="uid://bp56skqd5gqub"] [ext_resource type="Script" path="res://Scripts/scene_control.gd" id="1_lcu5v"] [ext_resource type="PackedScene" uid="uid://c8r6i3bu37ogu" path="res://Nodes/ui.tscn" id="2_44idh"] @@ -6,6 +6,8 @@ [ext_resource type="Texture2D" uid="uid://cxhterify3l" path="res://Assets/Images/goal.png" id="4_mfiv7"] [ext_resource type="PackedScene" uid="uid://c1mvbh2fwqtkb" path="res://Nodes/car.tscn" id="5_mi6tb"] [ext_resource type="Script" path="res://Scripts/drawing.gd" id="6_0pqvb"] +[ext_resource type="Script" path="res://Scripts/Road.gd" id="7_d0og5"] +[ext_resource type="Texture2D" uid="uid://bcn7tgs6a4fm7" path="res://Assets/road.png" id="7_w2gmt"] [ext_resource type="TileSet" uid="uid://cl8153posdeim" path="res://Assets/grass_tile_set.tres" id="8_wphs7"] [sub_resource type="CircleShape2D" id="CircleShape2D_6g88q"] @@ -53,9 +55,15 @@ z_index = 3 script = ExtResource("6_0pqvb") [node name="TrackLine" type="Line2D" parent="DrawNode"] -z_index = 1 -points = PackedVector2Array(1636, 177) -default_color = Color(0.870588, 0.870588, 0.870588, 0.431373) +texture_repeat = 2 +width = 70.0 +texture = ExtResource("7_w2gmt") +texture_mode = 1 +script = ExtResource("7_d0og5") + +[node name="LeftBorder" type="Line2D" parent="DrawNode/TrackLine"] + +[node name="RightBorder" type="Line2D" parent="DrawNode/TrackLine"] [node name="TrackPath" type="Path2D" parent="DrawNode"] curve = SubResource("Curve2D_0exre") diff --git a/Levels/Tut02.tscn b/Levels/Tut02.tscn index 2d95719..6cfb2eb 100644 --- a/Levels/Tut02.tscn +++ b/Levels/Tut02.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://ccgojoehaouv0"] +[gd_scene load_steps=13 format=3 uid="uid://ccgojoehaouv0"] [ext_resource type="Script" path="res://Scripts/scene_control.gd" id="1_77i7n"] [ext_resource type="PackedScene" uid="uid://c8r6i3bu37ogu" path="res://Nodes/ui.tscn" id="2_wchsl"] @@ -6,6 +6,8 @@ [ext_resource type="Texture2D" uid="uid://cxhterify3l" path="res://Assets/Images/goal.png" id="4_yklwl"] [ext_resource type="PackedScene" uid="uid://c1mvbh2fwqtkb" path="res://Nodes/car.tscn" id="5_h0kjy"] [ext_resource type="Script" path="res://Scripts/drawing.gd" id="6_0m5bn"] +[ext_resource type="Texture2D" uid="uid://bcn7tgs6a4fm7" path="res://Assets/road.png" id="7_iioy2"] +[ext_resource type="Script" path="res://Scripts/Road.gd" id="8_1xa7f"] [ext_resource type="TileSet" uid="uid://cl8153posdeim" path="res://Assets/grass_tile_set.tres" id="8_a1rvy"] [sub_resource type="CircleShape2D" id="CircleShape2D_6g88q"] @@ -49,16 +51,23 @@ z_index = 3 [node name="DrawNode" type="Node2D" parent="."] script = ExtResource("6_0m5bn") -[node name="TrackLine" type="Line2D" parent="DrawNode"] -z_index = 1 -default_color = Color(0.870588, 0.870588, 0.870588, 0.431373) - [node name="TrackPath" type="Path2D" parent="DrawNode"] curve = SubResource("Curve2D_0exre") [node name="TrackFollower" type="PathFollow2D" parent="DrawNode/TrackPath"] loop = false +[node name="TrackLine" type="Line2D" parent="DrawNode"] +texture_repeat = 2 +width = 70.0 +texture = ExtResource("7_iioy2") +texture_mode = 1 +script = ExtResource("8_1xa7f") + +[node name="LeftBorder" type="Line2D" parent="DrawNode/TrackLine"] + +[node name="RightBorder" type="Line2D" parent="DrawNode/TrackLine"] + [node name="Checkpoints" type="Node" parent="."] [node name="Control" type="Control" parent="."] diff --git a/Levels/Tut03.tscn b/Levels/Tut03.tscn index a64f3de..8f45c64 100644 --- a/Levels/Tut03.tscn +++ b/Levels/Tut03.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://ceoxn74ev4wui"] +[gd_scene load_steps=14 format=3 uid="uid://ceoxn74ev4wui"] [ext_resource type="Script" path="res://Scripts/scene_control.gd" id="1_6ktyo"] [ext_resource type="PackedScene" uid="uid://c8r6i3bu37ogu" path="res://Nodes/ui.tscn" id="2_cbrmn"] @@ -6,8 +6,10 @@ [ext_resource type="Texture2D" uid="uid://cxhterify3l" path="res://Assets/Images/goal.png" id="4_a601a"] [ext_resource type="PackedScene" uid="uid://c1mvbh2fwqtkb" path="res://Nodes/car.tscn" id="5_hgfxg"] [ext_resource type="Script" path="res://Scripts/drawing.gd" id="6_uikm8"] +[ext_resource type="Texture2D" uid="uid://bcn7tgs6a4fm7" path="res://Assets/road.png" id="7_wag28"] [ext_resource type="TileSet" uid="uid://cl8153posdeim" path="res://Assets/grass_tile_set.tres" id="8_1mcey"] [ext_resource type="PackedScene" uid="uid://wkfai2lvnp7n" path="res://Nodes/checkpoint.tscn" id="8_7nfp6"] +[ext_resource type="Script" path="res://Scripts/Road.gd" id="8_st1kl"] [sub_resource type="CircleShape2D" id="CircleShape2D_6g88q"] radius = 17.0 @@ -48,15 +50,23 @@ z_index = 3 [node name="DrawNode" type="Node2D" parent="."] script = ExtResource("6_uikm8") -[node name="TrackLine" type="Line2D" parent="DrawNode"] -default_color = Color(0.870588, 0.870588, 0.870588, 0.431373) - [node name="TrackPath" type="Path2D" parent="DrawNode"] curve = SubResource("Curve2D_0exre") [node name="TrackFollower" type="PathFollow2D" parent="DrawNode/TrackPath"] loop = false +[node name="TrackLine" type="Line2D" parent="DrawNode"] +texture_repeat = 2 +width = 70.0 +texture = ExtResource("7_wag28") +texture_mode = 1 +script = ExtResource("8_st1kl") + +[node name="LeftBorder" type="Line2D" parent="DrawNode/TrackLine"] + +[node name="RightBorder" type="Line2D" parent="DrawNode/TrackLine"] + [node name="Checkpoints" type="Node" parent="."] [node name="Checkpoint" parent="Checkpoints" instance=ExtResource("8_7nfp6")] diff --git a/Scripts/Road.gd b/Scripts/Road.gd new file mode 100644 index 0000000..db60c7d --- /dev/null +++ b/Scripts/Road.gd @@ -0,0 +1,86 @@ +extends Line2D + +var epsilon = 2 + +@onready var leftBorder = $LeftBorder +@onready var rightBorder = $RightBorder + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func simplify(): + points = simplify_rec(points, epsilon) + +func simplify_rec(pointArray: PackedVector2Array, epsilon: float): + var dmax = 0 + var index = -1 + if pointArray.size() < 3: + return pointArray + var end = pointArray.size() - 1 + for i in range(1, end-1): + var d = find_perpendicular_distance(pointArray[i], pointArray[0], pointArray[end]) + if d > dmax: + index = i + dmax = d + + if dmax > epsilon: + var recResults1 = simplify_rec(pointArray.slice(0, index), epsilon) + var recResults2 = simplify_rec(pointArray.slice(index, end), epsilon) + recResults1.append_array(recResults2) + return recResults1 + else: + return [pointArray[0], pointArray[end]] + +func find_perpendicular_distance(p: Vector2, p1: Vector2, p2: Vector2): + var result + var slope + var intercept + if p1.x == p2.x: + result = p.x - p1.x + else: + slope = (p2.y - p1.y) / (p2.x - p1.x) + intercept = p1.y - (slope * p1.x) + result = abs(slope * p.x - p.y + intercept) / sqrt(pow(slope, 2) + 1) + + return result + +func get_bisector(left_side: bool, p2: Vector2, p1: Vector2 = p2, p3: Vector2 = p2): + var v1 = (p2 - p1).normalized() + var v2 = (p2 - p3).normalized() + var normal + if v1 == -v2: + normal = v2.rotated(-PI/2) + else: + normal = (v1 + v2).normalized() + if v2.rotated(-PI/2).dot(v1) < 0: + normal = -normal + + if left_side: + normal = -normal + return normal + + +func draw_borders(): + for pointIndex in range(0, points.size() - 1): + var normal + if pointIndex == 0: + continue + elif pointIndex == points.size() -1: + continue + #normal = Vector2.ZERO + else: + normal = get_bisector(true, points[pointIndex], points[pointIndex-1], points[pointIndex+1]) + + var point = points[pointIndex] + (normal*50) + leftBorder.add_point(point) + point = points[pointIndex] - (normal*50) + rightBorder.add_point(point) + +func clear_borders(): + leftBorder.clear_points() + rightBorder.clear_points() diff --git a/Scripts/drawing.gd b/Scripts/drawing.gd index 832c42d..e99d4a0 100644 --- a/Scripts/drawing.gd +++ b/Scripts/drawing.gd @@ -16,6 +16,8 @@ func start_drawing(): func _end_drawing(): drawing = false + line.simplify() + line.draw_borders() owner.set_driving(true) @@ -30,4 +32,5 @@ func _input(event): func reset(): line.clear_points() + line.clear_borders() path.curve.clear_points() |