diff --git a/project.godot b/project.godot index 300e742..43cce65 100644 --- a/project.godot +++ b/project.godot @@ -29,3 +29,7 @@ window/stretch/mode="canvas_items" 2d_physics/layer_2="walldetection" 2d_physics/layer_3="Marking" 2d_physics/layer_4="Layer 4" + +[rendering] + +textures/canvas_textures/default_texture_repeat=1 diff --git a/scenes/map_04.tscn b/scenes/map_04.tscn new file mode 100644 index 0000000..b02a6dd --- /dev/null +++ b/scenes/map_04.tscn @@ -0,0 +1,294 @@ +[gd_scene load_steps=17 format=4 uid="uid://dji2ku3464aus"] + +[ext_resource type="Texture2D" uid="uid://bu05e161cb61k" path="res://sprites/background/spritesheet_bg.png" id="1_m3cjb"] +[ext_resource type="TileSet" uid="uid://beswbm12qkkxk" path="res://sprites/spritesheet_road/bg_road.tres" id="2_u1rh5"] +[ext_resource type="TileSet" uid="uid://buu8w8n61kbxf" path="res://sprites/spritesheet_road/markings.tres" id="3_xmt4t"] +[ext_resource type="Texture2D" uid="uid://cvkrjllwsen6r" path="res://sprites/htrohr/ht_rohr.png" id="4_46p8j"] +[ext_resource type="Texture2D" uid="uid://dpuhee0x5ekud" path="res://sprites/background/spritesheet_scenery.png" id="5_unub2"] +[ext_resource type="Script" path="res://scripts/line2d_to_collisionpolygon.gd" id="6_50nf2"] +[ext_resource type="Texture2D" uid="uid://bal4r8rnh38dx" path="res://sprites/htrohr/ht_rohr_fitting.png" id="6_lu60n"] +[ext_resource type="Texture2D" uid="uid://b0h14qq3jgbcw" path="res://sprites/htrohr/weights.png" id="7_7xqft"] + +[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_qbu02"] +texture = ExtResource("1_m3cjb") +texture_region_size = Vector2i(256, 256) +0:0/0 = 0 +1:0/0 = 0 +2:0/0 = 0 +3:0/0 = 0 +4:0/0 = 0 +5:0/0 = 0 +6:0/0 = 0 +7:0/0 = 0 +0:1/0 = 0 +1:1/0 = 0 +2:1/0 = 0 +3:1/0 = 0 +4:1/0 = 0 +5:1/0 = 0 +6:1/0 = 0 +7:1/0 = 0 +0:2/0 = 0 +1:2/0 = 0 +2:2/0 = 0 +3:2/0 = 0 +4:2/0 = 0 +5:2/0 = 0 +6:2/0 = 0 +7:2/0 = 0 +0:3/0 = 0 +1:3/0 = 0 +2:3/0 = 0 +3:3/0 = 0 +4:3/0 = 0 +5:3/0 = 0 +6:3/0 = 0 +7:3/0 = 0 + +[sub_resource type="TileSet" id="TileSet_5knbn"] +tile_size = Vector2i(256, 256) +sources/1 = SubResource("TileSetAtlasSource_qbu02") + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_daqun"] +size = Vector2(23, 222) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_dltky"] +size = Vector2(19, 108) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_uys5r"] +size = Vector2(20, 126) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_82iti"] +size = Vector2(20, 231) + +[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_hclam"] +texture = ExtResource("5_unub2") +texture_region_size = Vector2i(128, 128) +2:0/0 = 0 +3:0/0 = 0 +6:0/0 = 0 +7:0/0 = 0 +8:0/0 = 0 +9:0/0 = 0 +10:0/0 = 0 +11:0/0 = 0 +12:0/0 = 0 +13:0/0 = 0 +14:0/0 = 0 +15:0/0 = 0 +2:1/0 = 0 +3:1/0 = 0 +6:1/0 = 0 +7:1/0 = 0 +8:1/0 = 0 +9:1/0 = 0 +10:1/0 = 0 +11:1/0 = 0 +12:1/0 = 0 +13:1/0 = 0 +14:1/0 = 0 +15:1/0 = 0 +0:2/0 = 0 +1:2/0 = 0 +2:2/0 = 0 +3:2/0 = 0 +4:2/0 = 0 +5:2/0 = 0 +6:2/0 = 0 +7:2/0 = 0 +8:2/0 = 0 +9:2/0 = 0 +10:2/0 = 0 +11:2/0 = 0 +12:2/0 = 0 +13:2/0 = 0 +14:2/0 = 0 +15:2/0 = 0 +0:3/0 = 0 +1:3/0 = 0 +2:3/0 = 0 +3:3/0 = 0 +4:3/0 = 0 +5:3/0 = 0 +6:3/0 = 0 +7:3/0 = 0 +8:3/0 = 0 +9:3/0 = 0 +10:3/0 = 0 +11:3/0 = 0 +12:3/0 = 0 +13:3/0 = 0 +14:3/0 = 0 +15:3/0 = 0 +0:4/0 = 0 +1:4/0 = 0 +2:4/0 = 0 +3:4/0 = 0 +4:4/0 = 0 +5:4/0 = 0 +6:4/0 = 0 +7:4/0 = 0 +8:4/0 = 0 +9:4/0 = 0 +10:4/0 = 0 +11:4/0 = 0 +12:4/0 = 0 +13:4/0 = 0 +14:4/0 = 0 +15:4/0 = 0 +0:5/0 = 0 +1:5/0 = 0 +2:5/0 = 0 +3:5/0 = 0 +4:5/0 = 0 +5:5/0 = 0 +6:5/0 = 0 +7:5/0 = 0 +8:5/0 = 0 +9:5/0 = 0 +10:5/0 = 0 +11:5/0 = 0 +12:5/0 = 0 +13:5/0 = 0 +14:5/0 = 0 +15:5/0 = 0 +0:6/0 = 0 +1:6/0 = 0 +2:6/0 = 0 +3:6/0 = 0 +4:6/0 = 0 +5:6/0 = 0 +6:6/0 = 0 +7:6/0 = 0 +8:6/0 = 0 +9:6/0 = 0 +10:6/0 = 0 +11:6/0 = 0 +12:6/0 = 0 +13:6/0 = 0 +14:6/0 = 0 +15:6/0 = 0 +0:7/0 = 0 +1:7/0 = 0 +2:7/0 = 0 +3:7/0 = 0 +4:7/0 = 0 +5:7/0 = 0 +6:7/0 = 0 +7:7/0 = 0 +8:7/0 = 0 +9:7/0 = 0 +10:7/0 = 0 +11:7/0 = 0 +12:7/0 = 0 +13:7/0 = 0 +14:7/0 = 0 +15:7/0 = 0 +0:0/size_in_atlas = Vector2i(2, 2) +0:0/0 = 0 +4:0/size_in_atlas = Vector2i(2, 2) +4:0/0 = 0 + +[sub_resource type="TileSet" id="TileSet_s6rw7"] +tile_size = Vector2i(128, 128) +sources/0 = SubResource("TileSetAtlasSource_hclam") + +[node name="Map" type="Node"] + +[node name="Background" type="TileMapLayer" parent="."] +tile_map_data = PackedByteArray("AAD+/wEAAQAAAAAAAAD+/wAAAQAAAAAAAAD+////AQAAAAAAAAD+//7/AQABAAAAAAD///7/AQAAAAAAAAD///3/AQAAAAAAAAAAAP3/AQAAAAAAAAD+//3/AQABAAAAAAABAP3/AQAAAAAAAAACAP3/AQAAAAAAAAADAP3/AQABAAAAAAADAP7/AQAAAAAAAAAEAP7/AQAAAAAAAAACAP7/AQAAAAAAAAABAP7/AQAAAAAAAAAAAP7/AQAAAAAAAAAAAP//AQAAAAAAAAD/////AQAAAAAAAAABAP//AQAAAAAAAAACAP//AQAAAAAAAAADAP//AQAAAAAAAAAEAP//AQAAAAAAAAAEAAAAAQAAAAAAAAADAAAAAQABAAAAAAACAAAAAQAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAD//wAAAQAAAAAAAAD//wEAAQAAAAAAAAAAAAEAAQAAAAAAAAABAAEAAQAAAAAAAAACAAEAAQAAAAAAAAADAAEAAQAAAAAAAAAEAAEAAQABAAAAAAAEAP3/AQABAAAAAAA=") +tile_set = SubResource("TileSet_5knbn") +collision_enabled = false + +[node name="road_bg" type="TileMapLayer" parent="."] +tile_set = ExtResource("2_u1rh5") + +[node name="road_bg2" type="TileMapLayer" parent="."] +tile_set = ExtResource("2_u1rh5") + +[node name="road_bg_fixes" type="TileMapLayer" parent="."] +tile_set = ExtResource("2_u1rh5") + +[node name="markings" type="TileMapLayer" parent="."] +z_index = 1 +tile_map_data = PackedByteArray("AAAAAAAAAQAAAAAAAFAAAP//AQAAAAAAAHA=") +tile_set = ExtResource("3_xmt4t") + +[node name="Line2D" type="Line2D" parent="."] +z_index = 1 +texture_filter = 1 +points = PackedVector2Array(-137, 119, 353, 120, 429, 83, 498, 39, 621, 8, 744, 1, 859, -10, 935, -52, 935, -178, 888, -246, 825, -299, 471, -448, 256, -445, 121, -532, -32, -502, -250, -181, -308, -42, -260, 59, -146, 119, -147, 136) +width = 8.0 +texture = ExtResource("4_46p8j") +texture_mode = 1 +script = ExtResource("6_50nf2") + +[node name="road_r" type="StaticBody2D" parent="Line2D"] +collision_layer = 3 + +[node name="fitting" type="Sprite2D" parent="Line2D"] +texture_filter = 1 +position = Vector2(259, 120) +texture = ExtResource("6_lu60n") + +[node name="weight" type="Sprite2D" parent="Line2D"] +texture = ExtResource("7_7xqft") +region_enabled = true +region_rect = Rect2(32, 0, 32, 32) + +[node name="Line2D2" type="Line2D" parent="."] +z_index = 1 +points = PackedVector2Array(-97, -109, 236, -111, 298, -107, 370, -83, 452, -64, 517, -82, 661, -85, 745, -98, 784, -149, 784, -228, 466, -384, 295, -358, 207, -356, 143, -399, 106, -433, 58, -433, -177, -159, -203, -92, -176, -55, -80, -127) +width = 6.0 +texture = ExtResource("4_46p8j") +texture_mode = 1 +script = ExtResource("6_50nf2") + +[node name="road_l" type="StaticBody2D" parent="Line2D2"] +collision_layer = 3 + +[node name="fitting" type="Sprite2D" parent="Line2D2"] +texture_filter = 1 +position = Vector2(259, 120) +texture = ExtResource("6_lu60n") + +[node name="weight" type="Sprite2D" parent="Line2D2"] +texture = ExtResource("7_7xqft") +region_enabled = true +region_rect = Rect2(32, 0, 32, 32) + +[node name="area_finish" type="Area2D" parent="."] +collision_layer = 4 +collision_mask = 4 + +[node name="CollisionShape2D_Fin" type="CollisionShape2D" parent="area_finish"] +position = Vector2(89.5, -1) +shape = SubResource("RectangleShape2D_daqun") + +[node name="area_cp0" type="Area2D" parent="."] +collision_layer = 4 +collision_mask = 4 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="area_cp0"] +position = Vector2(536, -25) +shape = SubResource("RectangleShape2D_dltky") + +[node name="area_cp1" type="Area2D" parent="."] +collision_layer = 4 +collision_mask = 4 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="area_cp1"] +position = Vector2(364, -411) +shape = SubResource("RectangleShape2D_uys5r") + +[node name="area_cp2" type="Area2D" parent="."] +collision_layer = 4 +collision_mask = 4 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="area_cp2"] +position = Vector2(-123, -283) +shape = SubResource("RectangleShape2D_82iti") + +[node name="scenery" type="TileMapLayer" parent="."] +z_index = 20 +tile_set = SubResource("TileSet_s6rw7") diff --git a/scenes/menu.tscn b/scenes/menu.tscn index 470590e..1c264da 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -127,6 +127,11 @@ layout_mode = 2 toggle_mode = true icon = ExtResource("7_5f67q") +[node name="btn_map_04" type="Button" parent="MenuDisplay/map_container"] +layout_mode = 2 +toggle_mode = true +icon = ExtResource("3_p822h") + [node name="rounds_selection" type="OptionButton" parent="MenuDisplay"] offset_left = 690.0 offset_top = 556.0 diff --git a/scripts/line2d_to_collisionpolygon.gd b/scripts/line2d_to_collisionpolygon.gd new file mode 100644 index 0000000..ed9a8d2 --- /dev/null +++ b/scripts/line2d_to_collisionpolygon.gd @@ -0,0 +1,131 @@ +extends Line2D + +const END_FITTING_DISTANCE=1 #fitting distance from end of pipe +const CORNER_FITTING_DISTANCE=4 #fitting of last pipe before a corner piece +const CORNER_NEXT_FITTING_DISTANCE=8 #fitting after corner + +const PIPE_MAX_LENGTH=2*55 #1m=55,172px + +const WEIGHT_DISTANCE_FROM_PIPE=9 +const WEIGHT_RANDOM_OFFSET=0 +const WEIGHT_DISTANCE_MIN=0.5*55 +const WEIGHT_DISTANCE_MAX=4*55 +const MIN_WEIGHT_DISTANCE_FROM_CORNER=20 + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + #var staticbody=get_child(0) #get road collision object (StaticBody2D) + var rightborder=true + var staticbody:StaticBody2D=$road_r + if staticbody==null: + staticbody=$road_l + rightborder=false #is left border + + addCaps($fitting) + addWeights($weight,rightborder) + + + + var line_poly=Geometry2D.offset_polyline(points,width/2) + + for poly in line_poly: + var col = CollisionPolygon2D.new() + col.polygon=poly + staticbody.add_child(col) + + + +func addCaps(fitting:Sprite2D) -> void: + if fitting==null: + return + + var lastp:Vector2 + var skipfirst=true + for p:Vector2 in points: + if skipfirst: + lastp=p + skipfirst=false + continue #skip first + + var line_angle=(p-lastp).angle() + + #print("Point="+str(p)+" lastp="+str(lastp)) + #Add end fitting + var fitting_distance_from_end=CORNER_FITTING_DISTANCE + if points.find(p)==points.size()-1: + fitting_distance_from_end=END_FITTING_DISTANCE + var line_end_fitting_point=p + (lastp-p).normalized()*fitting_distance_from_end + + + var newfitting:Sprite2D=fitting.duplicate() + newfitting.transform=Transform2D(line_angle,line_end_fitting_point) + add_child(newfitting) + + + #Add corner fitting (beginning of pipe) + if points.find(lastp)!=0: #if this pipe segment is not the first + var line_corner_fitting_point=lastp + (p-lastp).normalized()*CORNER_NEXT_FITTING_DISTANCE + var newcornerfitting:Sprite2D=fitting.duplicate() + newcornerfitting.transform=Transform2D(line_angle,line_corner_fitting_point) + add_child(newcornerfitting) + + #add intermediate fittings + while (p-lastp).length()>PIPE_MAX_LENGTH: + var line_end_intfitting_point=lastp + (p-lastp).normalized()*PIPE_MAX_LENGTH + lastp=line_end_intfitting_point #update + + var newintfitting:Sprite2D=fitting.duplicate() + newintfitting.transform=Transform2D(line_angle,line_end_intfitting_point) + add_child(newintfitting) + + + lastp=p + + fitting.queue_free() #remote original fitting + + +func addWeights(weight:Sprite2D,rightborder:bool) -> void: + if weight==null: + return + + print("Add weights, rightboarder="+str(rightborder)) + var lengthWithoutSupport=0 + var lastp:Vector2 + var skipfirst=true + for p:Vector2 in points: + if skipfirst: + lastp=p + skipfirst=false + continue #skip first + + var line_angle=(p-lastp).angle() + + lengthWithoutSupport+=(p-lastp).length() + while lengthWithoutSupport>WEIGHT_DISTANCE_MAX: + var line_weight_point=lastp + (p-lastp).normalized()*min(randf_range(WEIGHT_DISTANCE_MIN,WEIGHT_DISTANCE_MAX),(p-lastp).length()-MIN_WEIGHT_DISTANCE_FROM_CORNER) + var newweight:Sprite2D=weight.duplicate() + + if newweight.region_enabled: + + var countTextures=newweight.texture.get_size().x/newweight.region_rect.size.x + print("countTextures="+str(countTextures)) + newweight.region_rect.position.x=newweight.region_rect.size.x*randi_range(0,countTextures-1) + print(" using pos="+str(newweight.region_rect.position)) + + newweight.transform=Transform2D(0,line_weight_point+(Vector2.ONE*WEIGHT_DISTANCE_FROM_PIPE).rotated(line_angle+(90 if rightborder else -90))+Vector2(randf_range(-WEIGHT_RANDOM_OFFSET,WEIGHT_RANDOM_OFFSET),randf_range(-WEIGHT_RANDOM_OFFSET,WEIGHT_RANDOM_OFFSET))) + + if rad_to_deg(line_angle)<-90 or rad_to_deg(line_angle)>90: + newweight.z_index=-1 #put behind + else: + newweight.z_index=1 #put in front + if not rightborder: + newweight.z_index*=-1 #flip for other side + + add_child(newweight) + lastp=line_weight_point #update + lengthWithoutSupport=(p-lastp).length() + + lastp=p + + weight.queue_free() diff --git a/sprites/htrohr/ht_rohr.png b/sprites/htrohr/ht_rohr.png new file mode 100644 index 0000000..03fd743 Binary files /dev/null and b/sprites/htrohr/ht_rohr.png differ diff --git a/sprites/htrohr/ht_rohr.png.import b/sprites/htrohr/ht_rohr.png.import new file mode 100644 index 0000000..d968941 --- /dev/null +++ b/sprites/htrohr/ht_rohr.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cvkrjllwsen6r" +path="res://.godot/imported/ht_rohr.png-2c4aa2233ed5c5f0ad051bfba014e2f4.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://sprites/htrohr/ht_rohr.png" +dest_files=["res://.godot/imported/ht_rohr.png-2c4aa2233ed5c5f0ad051bfba014e2f4.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/sprites/htrohr/ht_rohr_fitting.png b/sprites/htrohr/ht_rohr_fitting.png new file mode 100644 index 0000000..a8501bc Binary files /dev/null and b/sprites/htrohr/ht_rohr_fitting.png differ diff --git a/sprites/htrohr/ht_rohr_fitting.png.import b/sprites/htrohr/ht_rohr_fitting.png.import new file mode 100644 index 0000000..6a7be6c --- /dev/null +++ b/sprites/htrohr/ht_rohr_fitting.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bal4r8rnh38dx" +path="res://.godot/imported/ht_rohr_fitting.png-343af8694706a670d2c96cb76c440cf9.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://sprites/htrohr/ht_rohr_fitting.png" +dest_files=["res://.godot/imported/ht_rohr_fitting.png-343af8694706a670d2c96cb76c440cf9.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/sprites/htrohr/weights.png b/sprites/htrohr/weights.png new file mode 100644 index 0000000..65c86c4 Binary files /dev/null and b/sprites/htrohr/weights.png differ diff --git a/sprites/htrohr/weights.png.import b/sprites/htrohr/weights.png.import new file mode 100644 index 0000000..01dc727 --- /dev/null +++ b/sprites/htrohr/weights.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b0h14qq3jgbcw" +path="res://.godot/imported/weights.png-2da98438ecb97a452b053f13aac7a2a4.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://sprites/htrohr/weights.png" +dest_files=["res://.godot/imported/weights.png-2da98438ecb97a452b053f13aac7a2a4.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/sprites/htrohr/weights.xcf b/sprites/htrohr/weights.xcf new file mode 100644 index 0000000..bab8824 Binary files /dev/null and b/sprites/htrohr/weights.xcf differ