diff --git a/DungeonShooting_Godot/DungeonShooting.csproj b/DungeonShooting_Godot/DungeonShooting.csproj index 0d44898..d2f5fb2 100644 --- a/DungeonShooting_Godot/DungeonShooting.csproj +++ b/DungeonShooting_Godot/DungeonShooting.csproj @@ -1,4 +1,4 @@ - + net6.0 true diff --git a/DungeonShooting_Godot/DungeonShooting.csproj.old.5 b/DungeonShooting_Godot/DungeonShooting.csproj.old.5 new file mode 100644 index 0000000..0d44898 --- /dev/null +++ b/DungeonShooting_Godot/DungeonShooting.csproj.old.5 @@ -0,0 +1,6 @@ + + + net6.0 + true + + \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileset/TileSet1.tres b/DungeonShooting_Godot/resource/map/tileset/TileSet1.tres index 1beb8b1..2105e9f 100644 --- a/DungeonShooting_Godot/resource/map/tileset/TileSet1.tres +++ b/DungeonShooting_Godot/resource/map/tileset/TileSet1.tres @@ -118,12 +118,14 @@ 1:2/0/terrains_peering_bit/bottom_left_corner = 0 1:2/0/terrains_peering_bit/top_left_corner = 0 1:2/0/terrains_peering_bit/top_right_corner = 0 +1:2/0/custom_data_0 = 2 2:2/0 = 0 2:2/0/terrain_set = 0 2:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) 2:2/0/physics_layer_0/angular_velocity = 0.0 2:2/0/terrains_peering_bit/top_left_corner = 0 2:2/0/terrains_peering_bit/top_right_corner = 0 +2:2/0/custom_data_0 = 2 3:2/0 = 0 3:2/0/terrain_set = 0 3:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) @@ -131,6 +133,7 @@ 3:2/0/terrains_peering_bit/bottom_right_corner = 0 3:2/0/terrains_peering_bit/top_left_corner = 0 3:2/0/terrains_peering_bit/top_right_corner = 0 +3:2/0/custom_data_0 = 2 4:2/0 = 0 4:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) 4:2/0/physics_layer_0/angular_velocity = 0.0 @@ -157,6 +160,7 @@ 11:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) 11:2/0/physics_layer_0/angular_velocity = 0.0 11:2/0/terrains_peering_bit/top_right_corner = 0 +11:2/0/custom_data_0 = 2 12:2/0 = 0 12:2/0/terrain_set = 0 12:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) @@ -166,6 +170,7 @@ 13:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) 13:2/0/physics_layer_0/angular_velocity = 0.0 13:2/0/terrains_peering_bit/top_left_corner = 0 +13:2/0/custom_data_0 = 2 14:2/0 = 0 14:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) 14:2/0/physics_layer_0/angular_velocity = 0.0 @@ -181,6 +186,7 @@ 1:3/0/physics_layer_0/angular_velocity = 0.0 1:3/0/terrains_peering_bit/bottom_left_corner = 0 1:3/0/terrains_peering_bit/top_left_corner = 0 +1:3/0/custom_data_0 = 2 2:3/0 = 0 2:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) 2:3/0/physics_layer_0/angular_velocity = 0.0 @@ -190,6 +196,7 @@ 3:3/0/physics_layer_0/angular_velocity = 0.0 3:3/0/terrains_peering_bit/bottom_right_corner = 0 3:3/0/terrains_peering_bit/top_right_corner = 0 +3:3/0/custom_data_0 = 2 4:3/0 = 0 4:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) 4:3/0/physics_layer_0/angular_velocity = 0.0 @@ -234,6 +241,7 @@ 1:4/0/physics_layer_0/linear_velocity = Vector2(0, 0) 1:4/0/physics_layer_0/angular_velocity = 0.0 1:4/0/terrains_peering_bit/bottom_left_corner = 0 +1:4/0/custom_data_0 = 2 2:4/0 = 0 2:4/0/physics_layer_0/linear_velocity = Vector2(0, 0) 2:4/0/physics_layer_0/angular_velocity = 0.0 @@ -242,6 +250,7 @@ 3:4/0/physics_layer_0/linear_velocity = Vector2(0, 0) 3:4/0/physics_layer_0/angular_velocity = 0.0 3:4/0/terrains_peering_bit/bottom_right_corner = 0 +3:4/0/custom_data_0 = 2 4:4/0 = 0 4:4/0/physics_layer_0/linear_velocity = Vector2(0, 0) 4:4/0/physics_layer_0/angular_velocity = 0.0 @@ -393,15 +402,18 @@ 1:7/0/terrain_set = 0 1:7/0/physics_layer_0/linear_velocity = Vector2(0, 0) 1:7/0/physics_layer_0/angular_velocity = 0.0 +1:7/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) 1:7/0/terrains_peering_bit/bottom_right_corner = 0 1:7/0/terrains_peering_bit/bottom_left_corner = 0 1:7/0/terrains_peering_bit/top_left_corner = 0 +1:7/0/custom_data_0 = 1 2:7/0 = 0 2:7/0/terrain_set = 0 2:7/0/physics_layer_0/linear_velocity = Vector2(0, 0) 2:7/0/physics_layer_0/angular_velocity = 0.0 2:7/0/terrains_peering_bit/bottom_right_corner = 0 2:7/0/terrains_peering_bit/bottom_left_corner = 0 +2:7/0/custom_data_0 = 1 3:7/0 = 0 3:7/0/terrain_set = 0 3:7/0/physics_layer_0/linear_velocity = Vector2(0, 0) @@ -409,6 +421,7 @@ 3:7/0/terrains_peering_bit/bottom_right_corner = 0 3:7/0/terrains_peering_bit/bottom_left_corner = 0 3:7/0/terrains_peering_bit/top_right_corner = 0 +3:7/0/custom_data_0 = 1 4:7/0 = 0 4:7/0/physics_layer_0/linear_velocity = Vector2(0, 0) 4:7/0/physics_layer_0/angular_velocity = 0.0 @@ -602,4 +615,6 @@ terrain_set_0/mode = 1 terrain_set_0/terrain_0/name = "Terrain 0" terrain_set_0/terrain_0/color = Color(0.886275, 0.0980392, 0.0980392, 1) +custom_data_layer_0/name = "TileLayer" +custom_data_layer_0/type = 2 sources/0 = SubResource("TileSetAtlasSource_yvgyd") diff --git a/DungeonShooting_Godot/resource/theme/mainTheme.tres b/DungeonShooting_Godot/resource/theme/mainTheme.tres index a5dfe0e..cbaa476 100644 --- a/DungeonShooting_Godot/resource/theme/mainTheme.tres +++ b/DungeonShooting_Godot/resource/theme/mainTheme.tres @@ -352,7 +352,7 @@ [sub_resource type="ImageTexture" id="58"] -[sub_resource type="Image" id="Image_tux72"] +[sub_resource type="Image" id="Image_soqha"] data = { "data": PackedByteArray(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, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 1, 255, 255, 255, 39, 255, 255, 255, 67, 255, 255, 255, 67, 255, 255, 255, 39, 255, 255, 255, 1, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 39, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 39, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 66, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 66, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 66, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 66, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 39, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 39, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 1, 255, 255, 255, 39, 255, 255, 255, 67, 255, 255, 255, 67, 255, 255, 255, 39, 255, 255, 255, 1, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 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, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -362,7 +362,7 @@ } [sub_resource type="ImageTexture" id="60"] -image = SubResource("Image_tux72") +image = SubResource("Image_soqha") [sub_resource type="StyleBoxTexture" id="61"] content_margin_left = 2.0 @@ -372,7 +372,7 @@ texture = SubResource("60") region_rect = Rect2(0, 0, 12, 12) -[sub_resource type="Image" id="Image_s1x5h"] +[sub_resource type="Image" id="Image_tmvuf"] data = { "data": PackedByteArray(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, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 247, 247, 247, 0, 248, 248, 248, 0, 248, 248, 248, 0, 247, 247, 247, 0, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 191, 191, 191, 4, 247, 247, 247, 98, 248, 248, 248, 167, 248, 248, 248, 167, 247, 247, 247, 98, 191, 191, 191, 4, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 247, 247, 247, 0, 247, 247, 247, 97, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 247, 247, 247, 97, 247, 247, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 248, 248, 0, 248, 248, 248, 164, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 164, 248, 248, 248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 248, 248, 0, 248, 248, 248, 164, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 164, 248, 248, 248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 247, 247, 247, 0, 247, 247, 247, 97, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 247, 247, 247, 97, 247, 247, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 191, 191, 191, 4, 247, 247, 247, 98, 248, 248, 248, 167, 248, 248, 248, 167, 247, 247, 247, 98, 191, 191, 191, 4, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 247, 247, 247, 0, 248, 248, 248, 0, 248, 248, 248, 0, 247, 247, 247, 0, 191, 191, 191, 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, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -382,7 +382,7 @@ } [sub_resource type="ImageTexture" id="63"] -image = SubResource("Image_s1x5h") +image = SubResource("Image_tmvuf") [sub_resource type="StyleBoxTexture" id="64"] content_margin_left = 2.0 @@ -392,7 +392,7 @@ texture = SubResource("63") region_rect = Rect2(0, 0, 12, 12) -[sub_resource type="Image" id="Image_gl2nm"] +[sub_resource type="Image" id="Image_cmfvh"] data = { "data": PackedByteArray(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, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 127, 127, 127, 4, 173, 173, 173, 97, 173, 173, 173, 166, 173, 173, 173, 166, 173, 173, 173, 97, 127, 127, 127, 4, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 172, 172, 172, 0, 172, 172, 172, 96, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 172, 172, 172, 96, 172, 172, 172, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173, 173, 173, 0, 173, 173, 173, 163, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 163, 173, 173, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173, 173, 173, 0, 173, 173, 173, 163, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 163, 173, 173, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 172, 172, 172, 0, 172, 172, 172, 96, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 172, 172, 172, 96, 172, 172, 172, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 127, 127, 127, 4, 173, 173, 173, 97, 173, 173, 173, 166, 173, 173, 173, 166, 173, 173, 173, 97, 127, 127, 127, 4, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 127, 127, 127, 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, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -402,7 +402,7 @@ } [sub_resource type="ImageTexture" id="66"] -image = SubResource("Image_gl2nm") +image = SubResource("Image_cmfvh") [sub_resource type="StyleBoxTexture" id="67"] content_margin_left = 2.0 @@ -412,7 +412,7 @@ texture = SubResource("66") region_rect = Rect2(0, 0, 12, 12) -[sub_resource type="Image" id="Image_58qhl"] +[sub_resource type="Image" id="Image_nkbhm"] data = { "data": PackedByteArray(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, 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, 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, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 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, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 4, 255, 255, 255, 16, 255, 255, 255, 16, 255, 255, 255, 4, 255, 255, 255, 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, 255, 255, 255, 0, 255, 255, 255, 16, 255, 255, 255, 21, 255, 255, 255, 21, 255, 255, 255, 16, 255, 255, 255, 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, 255, 255, 255, 0, 255, 255, 255, 16, 255, 255, 255, 21, 255, 255, 255, 21, 255, 255, 255, 16, 255, 255, 255, 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, 255, 255, 255, 0, 255, 255, 255, 4, 255, 255, 255, 16, 255, 255, 255, 16, 255, 255, 255, 4, 255, 255, 255, 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, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 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, 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, 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, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -422,7 +422,7 @@ } [sub_resource type="ImageTexture" id="69"] -image = SubResource("Image_58qhl") +image = SubResource("Image_nkbhm") [sub_resource type="StyleBoxTexture" id="70"] content_margin_left = 0.0 @@ -446,7 +446,7 @@ content_margin_right = 4.0 content_margin_bottom = 4.0 -[sub_resource type="Image" id="Image_j2b5f"] +[sub_resource type="Image" id="Image_uft0g"] data = { "data": PackedByteArray(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, 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, 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, 0, 255, 255, 255, 0, 255, 255, 255, 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, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 76, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 76, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 76, 255, 255, 255, 228, 255, 255, 255, 188, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 188, 255, 255, 255, 228, 255, 255, 255, 76, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 18, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 187, 255, 255, 255, 17, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 187, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 18, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 185, 255, 255, 255, 17, 255, 255, 255, 17, 255, 255, 255, 186, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 190, 255, 255, 255, 229, 255, 255, 255, 185, 255, 255, 255, 185, 255, 255, 255, 229, 255, 255, 255, 189, 255, 255, 255, 19, 255, 255, 255, 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, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 191, 255, 255, 255, 229, 255, 255, 255, 229, 255, 255, 255, 190, 255, 255, 255, 19, 255, 255, 255, 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, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 17, 255, 255, 255, 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, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 187, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 187, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 18, 255, 255, 255, 19, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 186, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 185, 255, 255, 255, 229, 255, 255, 255, 189, 255, 255, 255, 19, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 189, 255, 255, 255, 229, 255, 255, 255, 185, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 76, 255, 255, 255, 229, 255, 255, 255, 190, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 190, 255, 255, 255, 229, 255, 255, 255, 76, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 77, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 77, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 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, 255, 255, 255, 0, 255, 255, 255, 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, 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, 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, 0, 0), "format": "RGBA8", @@ -456,7 +456,7 @@ } [sub_resource type="ImageTexture" id="56"] -image = SubResource("Image_j2b5f") +image = SubResource("Image_uft0g") [sub_resource type="StyleBoxFlat" id="57"] content_margin_left = 6.0 diff --git a/DungeonShooting_Godot/scene/Main.tscn b/DungeonShooting_Godot/scene/Main.tscn index 454b56d..0aaea00 100644 --- a/DungeonShooting_Godot/scene/Main.tscn +++ b/DungeonShooting_Godot/scene/Main.tscn @@ -24,7 +24,6 @@ [node name="Main" type="Node2D"] script = ExtResource("3") -Debug = true CursorPack = ExtResource("4") RoomPath = NodePath("ViewCanvas/SubViewportContainer/SubViewport/Room") ViewportPath = NodePath("ViewCanvas/SubViewportContainer/SubViewport") diff --git a/DungeonShooting_Godot/src/game/room/DungeonTile.cs b/DungeonShooting_Godot/src/game/room/DungeonTile.cs new file mode 100644 index 0000000..cc2f061 --- /dev/null +++ b/DungeonShooting_Godot/src/game/room/DungeonTile.cs @@ -0,0 +1,992 @@ + +using System; +using System.Collections.Generic; +using Godot; + +/// +/// 地牢地砖管理类, 提供一些操作 TileMap 和计算导航的接口 +/// +public class DungeonTile +{ + /// + /// TileMap 底板的层级 + /// + public const int FloorMapLayer = 0; + /// + /// TileMap 中层的层级 + /// + public const int MiddleMapLayer = 1; + /// + /// TileMap 上层的层级 + /// + public const int TopMapLayer = 2; + + /// + /// 配置层级的自定义数据名称 + /// + public const string CustomTileLayerName = "TileLayer"; + + //--------------------- 导航 ------------------------- + + //已经标记过的点 + private readonly HashSet _usePoints = new HashSet(); + + //导航区域数据 + private readonly List _polygonDataList = new List(); + + //---------------------------------------------------- + + private TileMap _tileRoot; + + public DungeonTile(TileMap tileRoot) + { + _tileRoot = tileRoot; + } + + /// + /// 根据 roomInfo 和 config 数据自动填充 tileMap 参数中的地图数据 + /// + public void AutoFillRoomTile(AutoTileConfig config, RoomInfo roomInfo) + { + foreach (var info in roomInfo.Next) + { + AutoFillRoomTile(config, info); + } + + //铺房间 + if (roomInfo.RoomSplit == null) + { + FillRect(FloorMapLayer, config.Ground, roomInfo.Position + Vector2.One, + roomInfo.Size - new Vector2(2, 2)); + + FillRect(TopMapLayer, config.IN_LT, roomInfo.Position, Vector2.One); + FillRect(TopMapLayer, config.L, roomInfo.Position + new Vector2(0, 1), + new Vector2(1, roomInfo.Size.Y - 2)); + FillRect(TopMapLayer, config.IN_LB, roomInfo.Position + new Vector2(0, roomInfo.Size.Y - 1), + new Vector2(1, 1)); + FillRect(TopMapLayer, config.B, roomInfo.Position + new Vector2(1, roomInfo.Size.Y - 1), + new Vector2(roomInfo.Size.X - 2, 1)); + FillRect(TopMapLayer, config.IN_RB, + roomInfo.Position + new Vector2(roomInfo.Size.X - 1, roomInfo.Size.Y - 1), + Vector2.One); + FillRect(TopMapLayer, config.R, roomInfo.Position + new Vector2(roomInfo.Size.X - 1, 1), + new Vector2(1, roomInfo.Size.Y - 2)); + FillRect(TopMapLayer, config.IN_RT, roomInfo.Position + new Vector2(roomInfo.Size.X - 1, 0), + Vector2.One); + FillRect(MiddleMapLayer, config.T, roomInfo.Position + Vector2.Right, + new Vector2(roomInfo.Size.X - 2, 1)); + } + else + { + var rectSize = roomInfo.RoomSplit.RoomInfo.Size; + var rectPos = roomInfo.RoomSplit.RoomInfo.Position; + var template = ResourceManager.Load(roomInfo.RoomSplit.ScenePath); + var tileInstance = template.Instantiate(); + for (int i = 0; i < rectSize.X; i++) + { + for (int j = 0; j < rectSize.Y; j++) + { + var coords = new Vector2I((int)(rectPos.X + i), (int)(rectPos.Y + j)); + var atlasCoords = tileInstance.GetCellAtlasCoords(0, coords); + if (atlasCoords.X != -1 && atlasCoords.Y != -1) + { + //获取自定义层级 + var layer = tileInstance.GetCellTileData(0, coords).GetCustomData(CustomTileLayerName) + .AsInt32(); + layer = Mathf.Clamp(layer, FloorMapLayer, TopMapLayer); + _tileRoot.SetCell(layer, new Vector2I(roomInfo.Position.X + i, roomInfo.Position.Y + j), + 1, atlasCoords); + } + } + } + + tileInstance.QueueFree(); + } + + //铺过道 + foreach (var doorInfo in roomInfo.Doors) + { + if (doorInfo.ConnectRoom.Id > roomInfo.Id) + { + //普通的直线连接 + var doorDir1 = doorInfo.Direction; + var doorDir2 = doorInfo.ConnectDoor.Direction; + if (!doorInfo.HasCross) + { + //方向, 0横向, 1纵向 + int dir = 0; + var rect = Utils.CalcRect( + doorInfo.OriginPosition.X, + doorInfo.OriginPosition.Y, + doorInfo.ConnectDoor.OriginPosition.X, + doorInfo.ConnectDoor.OriginPosition.Y + ); + if (doorDir1 == DoorDirection.N || doorDir1 == DoorDirection.S) + { + rect.Size = new Vector2(GenerateDungeon.CorridorWidth, rect.Size.Y); + dir = 1; + } + else + { + rect.Size = new Vector2(rect.Size.X, GenerateDungeon.CorridorWidth); + } + + if (dir == 0) //横向 + { + FullHorizontalGalleryWall(config, rect); + } + else //纵向 + { + FullVerticalGalleryWall(config, rect); + } + } + else //带交叉点 + { + //方向, 0横向, 1纵向 + int dir1 = 0; + int dir2 = 0; + + Rect2 rect; + Rect2 rect2; + + //计算范围 + switch (doorDir1) + { + case DoorDirection.E: //→ + rect = new Rect2( + doorInfo.OriginPosition.X, + doorInfo.OriginPosition.Y, + doorInfo.Cross.X - doorInfo.OriginPosition.X, + GenerateDungeon.CorridorWidth + ); + break; + case DoorDirection.W: //← + rect = new Rect2( + doorInfo.Cross.X + GenerateDungeon.CorridorWidth, + doorInfo.Cross.Y, + doorInfo.OriginPosition.X - (doorInfo.Cross.X + GenerateDungeon.CorridorWidth), + GenerateDungeon.CorridorWidth + ); + break; + case DoorDirection.S: //↓ + dir1 = 1; + rect = new Rect2( + doorInfo.OriginPosition.X, + doorInfo.OriginPosition.Y, + GenerateDungeon.CorridorWidth, + doorInfo.Cross.Y - doorInfo.OriginPosition.Y + ); + break; + case DoorDirection.N: //↑ + dir1 = 1; + rect = new Rect2( + doorInfo.Cross.X, + doorInfo.Cross.Y + GenerateDungeon.CorridorWidth, + GenerateDungeon.CorridorWidth, + doorInfo.OriginPosition.Y - (doorInfo.Cross.Y + GenerateDungeon.CorridorWidth) + ); + break; + default: + rect = new Rect2(); + break; + } + + switch (doorDir2) + { + case DoorDirection.E: //→ + rect2 = new Rect2( + doorInfo.ConnectDoor.OriginPosition.X, + doorInfo.ConnectDoor.OriginPosition.Y, + doorInfo.Cross.X - doorInfo.ConnectDoor.OriginPosition.X, + GenerateDungeon.CorridorWidth + ); + break; + case DoorDirection.W: //← + rect2 = new Rect2( + doorInfo.Cross.X + GenerateDungeon.CorridorWidth, + doorInfo.Cross.Y, + doorInfo.ConnectDoor.OriginPosition.X - + (doorInfo.Cross.X + GenerateDungeon.CorridorWidth), + GenerateDungeon.CorridorWidth + ); + break; + case DoorDirection.S: //↓ + dir2 = 1; + rect2 = new Rect2( + doorInfo.ConnectDoor.OriginPosition.X, + doorInfo.ConnectDoor.OriginPosition.Y, + GenerateDungeon.CorridorWidth, + doorInfo.Cross.Y - doorInfo.ConnectDoor.OriginPosition.Y + ); + break; + case DoorDirection.N: //↑ + dir2 = 1; + rect2 = new Rect2( + doorInfo.Cross.X, + doorInfo.Cross.Y + GenerateDungeon.CorridorWidth, + GenerateDungeon.CorridorWidth, + doorInfo.ConnectDoor.OriginPosition.Y - + (doorInfo.Cross.Y + GenerateDungeon.CorridorWidth) + ); + break; + default: + rect2 = new Rect2(); + break; + } + + FillRect(FloorMapLayer, config.Ground, doorInfo.Cross + Vector2.One, + new Vector2(GenerateDungeon.CorridorWidth - 2, GenerateDungeon.CorridorWidth - 2)); + + //墙壁 + if (dir1 == 0) + { + FullHorizontalGalleryWall(config, rect); + } + else + { + FullVerticalGalleryWall(config, rect); + } + + if (dir2 == 0) + { + FullHorizontalGalleryWall(config, rect2); + } + else + { + FullVerticalGalleryWall(config, rect2); + } + + if ((doorDir1 == DoorDirection.N && doorDir2 == DoorDirection.E) || //↑→ + (doorDir2 == DoorDirection.N && doorDir1 == DoorDirection.E)) + { + FillRect(TopMapLayer, config.OUT_RT, + doorInfo.Cross + new Vector2(0, GenerateDungeon.CorridorWidth - 1), + Vector2.One); + FillRect(TopMapLayer, config.IN_RT, doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 0), + Vector2.One); + FillRect(MiddleMapLayer, config.T, doorInfo.Cross, new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); + FillRect(TopMapLayer, config.R, doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 1), + new Vector2(1, GenerateDungeon.CorridorWidth - 1)); + } + else if ((doorDir1 == DoorDirection.E && doorDir2 == DoorDirection.S) || //→↓ + (doorDir2 == DoorDirection.E && doorDir1 == DoorDirection.S)) + { + FillRect(MiddleMapLayer, config.OUT_RB, doorInfo.Cross, Vector2.One); + FillRect(TopMapLayer, config.IN_RB, + doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, + GenerateDungeon.CorridorWidth - 1), + Vector2.One); + FillRect(TopMapLayer, config.R, doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 0), + new Vector2(1, GenerateDungeon.CorridorWidth - 1)); + FillRect(TopMapLayer, config.B, doorInfo.Cross + new Vector2(0, GenerateDungeon.CorridorWidth - 1), + new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); + } + else if ((doorDir1 == DoorDirection.S && doorDir2 == DoorDirection.W) || //↓← + (doorDir2 == DoorDirection.S && doorDir1 == DoorDirection.W)) + { + FillRect(MiddleMapLayer, config.OUT_LB, + doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 0), Vector2.One); + FillRect(TopMapLayer, config.IN_LB, doorInfo.Cross + new Vector2(0, GenerateDungeon.CorridorWidth - 1), + Vector2.One); + FillRect(TopMapLayer, config.L, doorInfo.Cross, new Vector2(1, GenerateDungeon.CorridorWidth - 1)); + FillRect(TopMapLayer, config.B, doorInfo.Cross + new Vector2(1, GenerateDungeon.CorridorWidth - 1), + new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); + } + else if ((doorDir1 == DoorDirection.W && doorDir2 == DoorDirection.N) || //←↑ + (doorDir2 == DoorDirection.W && doorDir1 == DoorDirection.N)) + { + FillRect(TopMapLayer, config.OUT_LT, + doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, + GenerateDungeon.CorridorWidth - 1), + Vector2.One); + FillRect(TopMapLayer, config.IN_LT, doorInfo.Cross, Vector2.One); + FillRect(MiddleMapLayer, config.T, doorInfo.Cross + new Vector2(1, 0), + new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); + FillRect(TopMapLayer, config.L, doorInfo.Cross + new Vector2(0, 1), + new Vector2(1, GenerateDungeon.CorridorWidth - 1)); + } + + //在房间墙上开洞 + switch (doorDir1) + { + case DoorDirection.E: //→ + ClearRect(TopMapLayer, doorInfo.OriginPosition + new Vector2(-1, 1), + new Vector2(1, rect.Size.Y - 2)); + FillRect(FloorMapLayer, config.Ground, doorInfo.OriginPosition + new Vector2(-1, 1), + new Vector2(1, rect.Size.Y - 2)); + break; + case DoorDirection.W: //← + ClearRect(TopMapLayer, doorInfo.OriginPosition + new Vector2(0, 1), + new Vector2(1, rect.Size.Y - 2)); + FillRect(FloorMapLayer, config.Ground, doorInfo.OriginPosition + new Vector2(0, 1), + new Vector2(1, rect.Size.Y - 2)); + break; + case DoorDirection.S: //↓ + ClearRect(TopMapLayer, doorInfo.OriginPosition + new Vector2(1, -1), + new Vector2(rect.Size.X - 2, 1)); + FillRect(FloorMapLayer, config.Ground, doorInfo.OriginPosition + new Vector2(1, -1), + new Vector2(rect.Size.X - 2, 1)); + break; + case DoorDirection.N: //↑ + ClearRect(MiddleMapLayer, doorInfo.OriginPosition + new Vector2(1, 2), + new Vector2(rect.Size.X - 2, 1)); + FillRect(FloorMapLayer, config.Ground, doorInfo.OriginPosition + new Vector2(1, 0), + new Vector2(rect.Size.X - 2, 1)); + break; + } + + switch (doorDir2) + { + case DoorDirection.E: //→ + ClearRect(TopMapLayer, doorInfo.ConnectDoor.OriginPosition + new Vector2(-1, 1), + new Vector2(1, rect2.Size.Y - 2)); + FillRect(FloorMapLayer, config.Ground, doorInfo.ConnectDoor.OriginPosition + new Vector2(-1, 1), + new Vector2(1, rect2.Size.Y - 2)); + break; + case DoorDirection.W: //← + ClearRect(TopMapLayer, doorInfo.ConnectDoor.OriginPosition + new Vector2(0, 1), + new Vector2(1, rect2.Size.Y - 2)); + FillRect(FloorMapLayer, config.Ground, doorInfo.ConnectDoor.OriginPosition + new Vector2(0, 1), + new Vector2(1, rect2.Size.Y - 2)); + break; + case DoorDirection.S: //↓ + ClearRect(TopMapLayer, doorInfo.ConnectDoor.OriginPosition + new Vector2(1, -1), + new Vector2(rect2.Size.X - 2, 1)); + FillRect(FloorMapLayer, config.Ground, doorInfo.ConnectDoor.OriginPosition + new Vector2(1, -1), + new Vector2(rect2.Size.X - 2, 1)); + break; + case DoorDirection.N: //↑ + ClearRect(MiddleMapLayer, doorInfo.ConnectDoor.OriginPosition + new Vector2(1, 0), + new Vector2(rect2.Size.X - 2, 1)); + FillRect(FloorMapLayer, config.Ground, doorInfo.ConnectDoor.OriginPosition + new Vector2(1, 0), + new Vector2(rect2.Size.X - 2, 1)); + break; + } + } + } + } + } + + //填充tile区域 + private void FillRect(int layer, TileCellInfo info, Vector2 pos, Vector2 size) + { + for (int i = 0; i < size.X; i++) + { + for (int j = 0; j < size.Y; j++) + { + _tileRoot.SetCell(layer, new Vector2I((int)pos.X + i, (int)pos.Y + j), 1, info.AutotileCoord); + } + } + } + + //清除tile区域 + private void ClearRect(int layer, Vector2 pos, Vector2 size) + { + for (int i = 0; i < size.X; i++) + { + for (int j = 0; j < size.Y; j++) + { + //tileMap.SetCell((int)pos.X + i, (int)pos.Y + j, -1); + _tileRoot.SetCell(layer, new Vector2I((int)pos.X + i, (int)pos.Y + j), -1); + } + } + } + + private void FullHorizontalGalleryWall(AutoTileConfig config, Rect2 rect) + { + FillRect(FloorMapLayer, config.Ground, rect.Position + new Vector2(0, 1), rect.Size - new Vector2(0, 2)); + FillRect(MiddleMapLayer, config.T, rect.Position, new Vector2(rect.Size.X, 1)); + FillRect(TopMapLayer, config.B, rect.Position + new Vector2(0, rect.Size.Y - 1), new Vector2(rect.Size.X, 1)); + //左 + ClearRect(TopMapLayer, rect.Position + new Vector2(-1, 1), new Vector2(1, rect.Size.Y - 2)); + FillRect(FloorMapLayer, config.Ground, rect.Position + new Vector2(-1, 1), new Vector2(1, rect.Size.Y - 2)); + //右 + ClearRect(TopMapLayer, rect.Position + new Vector2(rect.Size.X, 1), new Vector2(1, rect.Size.Y - 2)); + FillRect(FloorMapLayer, config.Ground, rect.Position + new Vector2(rect.Size.X, 1), new Vector2(1, rect.Size.Y - 2)); + } + + private void FullVerticalGalleryWall(AutoTileConfig config, Rect2 rect) + { + FillRect(FloorMapLayer, config.Ground, rect.Position + new Vector2(1, 0), rect.Size - new Vector2(2, 0)); + FillRect(TopMapLayer, config.L, rect.Position, new Vector2(1, rect.Size.Y)); + FillRect(TopMapLayer, config.R, rect.Position + new Vector2(rect.Size.X - 1, 0), new Vector2(1, rect.Size.Y)); + //上 + ClearRect(TopMapLayer, rect.Position + new Vector2(1, -1), new Vector2(rect.Size.X - 2, 1)); + FillRect(FloorMapLayer, config.Ground, rect.Position + new Vector2(1, -1), new Vector2(rect.Size.X - 2, 1)); + //下 + ClearRect(MiddleMapLayer, rect.Position + new Vector2(1, rect.Size.Y), new Vector2(rect.Size.X - 2, 1)); + FillRect(FloorMapLayer, config.Ground, rect.Position + new Vector2(1, rect.Size.Y), new Vector2(rect.Size.X - 2, 1)); + } + + /// + /// 计算网格区域, 并且赋值给 navigationPolygon + /// + public void GenerateNavigationPolygon(NavigationRegion2D navigationPolygon) + { + GenerateNavigationPolygon(); + var polygon = new NavigationPolygon(); + foreach (var polygonData in _polygonDataList) + { + polygon.AddOutline(polygonData.Points.ToArray()); + } + polygon.MakePolygonsFromOutlines(); + navigationPolygon.NavigationPolygon = polygon; + } + + /// + /// 获取导航点数据 + /// + public NavigationPolygonData[] GetPolygonData() + { + return _polygonDataList.ToArray(); + } + + /// + /// 返回指定位置的Tile是否为可以行走 + /// + public bool IsWayTile(int x, int y) + { + return _tileRoot.GetCellTileData(DungeonTile.FloorMapLayer, new Vector2I(x, y)) != null; + } + + /// + /// 返回指定坐标下对应的Tile是否为可以行走 + /// + public bool IsWayPosition(float x, float y) + { + var tileMapCellSize = _tileRoot.CellQuadrantSize; + return IsWayTile((int)(x / tileMapCellSize), (int)(y / tileMapCellSize)); + } + + /// + /// 自动生成导航区域 + /// + private void GenerateNavigationPolygon() + { + var size = new Vector2(_tileRoot.CellQuadrantSize, _tileRoot.CellQuadrantSize); + + var rect = _tileRoot.GetUsedRect(); + + var x = rect.Position.X; + var y = rect.Position.Y; + var w = rect.Size.X; + var h = rect.Size.Y; + + for (int j = y; j < h; j++) + { + for (int i = x; i < w; i++) + { + if (IsWayTile(i, j)) + { + if (!_usePoints.Contains(new Vector2(i, j))) + { + NavigationPolygonData polygonData = null; + + if (!IsWayTile(i, j - 1)) + { + polygonData = CalcOutline(i, j, _tileRoot, size); + } + else if (!IsWayTile(i, j + 1)) + { + polygonData = CalcInline(i, j, _tileRoot, size); + } + + if (polygonData != null) + { + _polygonDataList.Add(polygonData); + } + } + } + } + } + } + + //计算导航网格外轮廓 + private NavigationPolygonData CalcOutline(int i, int j, TileMap tileMap, Vector2 size) + { + var polygonData = new NavigationPolygonData(); + polygonData.Type = NavigationPolygonType.Out; + var points = polygonData.Points; + // 0:右, 1:下, 2:左, 3:上 + var dir = 0; + var offset = new Vector2(size.X * 0.5f, size.Y * 0.5f); + //找到路, 向右开始找边界 + var startPos = new Vector2(i, j); + + var tempI = i; + var tempJ = j; + + while (true) + { + switch (dir) + { + case 0: //右 + { + if (IsWayTile(tempI, tempJ - 1)) //先向上找 + { + dir = 3; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempJ--; + break; + } + else if (IsWayTile(tempI + 1, tempJ)) //再向右找 + { + if (points.Count == 0) + { + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + } + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + PutUsePoint(new Vector2(tempI, tempJ)); + tempI++; + break; + } + else if (IsWayTile(tempI, tempJ + 1)) //向下找 + { + dir = 1; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempJ++; + break; + } + + return null; + } + case 1: //下 + { + if (IsWayTile(tempI + 1, tempJ)) //先向右找 + { + dir = 0; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempI++; + break; + } + else if (IsWayTile(tempI, tempJ + 1)) //再向下找 + { + if (points.Count == 0) + { + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + } + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + PutUsePoint(new Vector2(tempI, tempJ)); + tempJ++; + break; + } + else if (IsWayTile(tempI - 1, tempJ)) //向左找 + { + dir = 2; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempI--; + break; + } + + return null; + } + case 2: //左 + { + if (IsWayTile(tempI, tempJ + 1)) //先向下找 + { + dir = 1; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempJ++; + break; + } + else if (IsWayTile(tempI - 1, tempJ)) //再向左找 + { + if (points.Count == 0) + { + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + } + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + PutUsePoint(new Vector2(tempI, tempJ)); + tempI--; + break; + } + else if (IsWayTile(tempI, tempJ - 1)) //向上找 + { + dir = 3; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempJ--; + break; + } + + return null; + } + case 3: //上 + { + if (IsWayTile(tempI - 1, tempJ)) //先向左找 + { + dir = 2; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempI--; + break; + } + else if (IsWayTile(tempI, tempJ - 1)) //再向上找 + { + if (points.Count == 0) + { + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + } + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + PutUsePoint(new Vector2(tempI, tempJ)); + tempJ--; + break; + } + else if (IsWayTile(tempI + 1, tempJ)) //向右找 + { + dir = 0; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempI++; + break; + } + + return null; + } + } + } + } + + //计算导航网格内轮廓 + private NavigationPolygonData CalcInline(int i, int j, TileMap tileMap, Vector2 size) + { + var polygonData = new NavigationPolygonData(); + polygonData.Type = NavigationPolygonType.In; + var points = polygonData.Points; + // 0:右, 1:下, 2:左, 3:上 + var dir = 0; + var offset = new Vector2(size.X * 0.5f, size.Y * 0.5f); + //找到路, 向右开始找边界 + var startPos = new Vector2(i - 1, j); + + var tempI = i; + var tempJ = j; + + while (true) + { + switch (dir) + { + case 0: //右 + { + if (IsWayTile(tempI, tempJ + 1)) //向下找 + { + dir = 1; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempJ++; + break; + } + else if (IsWayTile(tempI + 1, tempJ)) //再向右找 + { + if (points.Count == 0) + { + points.Add(new Vector2((tempI - 1) * size.X, tempJ * size.Y) + offset); + } + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + PutUsePoint(new Vector2(tempI, tempJ)); + tempI++; + break; + } + else if (IsWayTile(tempI, tempJ - 1)) //先向上找 + { + dir = 3; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempJ--; + break; + } + + return null; + } + case 1: //下 + { + if (IsWayTile(tempI - 1, tempJ)) //向左找 + { + dir = 2; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempI--; + break; + } + else if (IsWayTile(tempI, tempJ + 1)) //再向下找 + { + if (points.Count == 0) + { + points.Add(new Vector2((tempI - 1) * size.X, tempJ * size.Y) + offset); + } + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + PutUsePoint(new Vector2(tempI, tempJ)); + tempJ++; + break; + } + else if (IsWayTile(tempI + 1, tempJ)) //先向右找 + { + dir = 0; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempI++; + break; + } + + return null; + } + case 2: //左 + { + if (IsWayTile(tempI, tempJ - 1)) //向上找 + { + dir = 3; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempJ--; + break; + } + else if (IsWayTile(tempI - 1, tempJ)) //再向左找 + { + if (points.Count == 0) + { + points.Add(new Vector2((tempI - 1) * size.X, tempJ * size.Y) + offset); + } + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + PutUsePoint(new Vector2(tempI, tempJ)); + tempI--; + break; + } + else if (IsWayTile(tempI, tempJ + 1)) //先向下找 + { + dir = 1; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempJ++; + break; + } + + return null; + } + case 3: //上 + { + if (IsWayTile(tempI + 1, tempJ)) //向右找 + { + dir = 0; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempI++; + break; + } + else if (IsWayTile(tempI, tempJ - 1)) //再向上找 + { + if (points.Count == 0) + { + points.Add(new Vector2((tempI - 1) * size.X, tempJ * size.Y) + offset); + } + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + PutUsePoint(new Vector2(tempI, tempJ)); + tempJ--; + break; + } + else if (IsWayTile(tempI - 1, tempJ)) //先向左找 + { + dir = 2; + + var pos = new Vector2(tempI, tempJ); + if (points.Count > 1 && pos == startPos) + { + return polygonData; + } + + points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); + PutUsePoint(pos); + + tempI--; + break; + } + + return null; + } + } + } + } + + //记录导航网格中已经使用过的坐标 + private void PutUsePoint(Vector2 pos) + { + if (_usePoints.Contains(pos)) + { + throw new Exception("生成导航多边形发生错误! 点: " + pos + "发生交错!"); + } + + _usePoints.Add(pos); + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/room/DungeonTileManager.cs b/DungeonShooting_Godot/src/game/room/DungeonTileManager.cs deleted file mode 100644 index 4757d9e..0000000 --- a/DungeonShooting_Godot/src/game/room/DungeonTileManager.cs +++ /dev/null @@ -1,402 +0,0 @@ - -using System.Collections.Generic; -using Godot; - -public static class DungeonTileManager -{ - - private static readonly List FloorAtlasCoords = new List(new[] - { - new Vector2I(0, 8), - }); - - private static readonly List MiddleAtlasCoords = new List(new[] - { - new Vector2I(1, 7), - new Vector2I(2, 7), - new Vector2I(3, 7), - }); - - public static void AutoFillRoomTile(TileMap tileMap, int floorLayer, int middleLayer, int topLayer, - AutoTileConfig config, - RoomInfo roomInfo) - { - foreach (var info in roomInfo.Next) - { - AutoFillRoomTile(tileMap, floorLayer, middleLayer, topLayer, config, info); - } - - //铺房间 - if (roomInfo.RoomSplit == null) - { - FillRect(tileMap, floorLayer, config.Ground, roomInfo.Position + Vector2.One, - roomInfo.Size - new Vector2(2, 2)); - - FillRect(tileMap, topLayer, config.IN_LT, roomInfo.Position, Vector2.One); - FillRect(tileMap, topLayer, config.L, roomInfo.Position + new Vector2(0, 1), - new Vector2(1, roomInfo.Size.Y - 2)); - FillRect(tileMap, topLayer, config.IN_LB, roomInfo.Position + new Vector2(0, roomInfo.Size.Y - 1), - new Vector2(1, 1)); - FillRect(tileMap, topLayer, config.B, roomInfo.Position + new Vector2(1, roomInfo.Size.Y - 1), - new Vector2(roomInfo.Size.X - 2, 1)); - FillRect(tileMap, topLayer, config.IN_RB, - roomInfo.Position + new Vector2(roomInfo.Size.X - 1, roomInfo.Size.Y - 1), - Vector2.One); - FillRect(tileMap, topLayer, config.R, roomInfo.Position + new Vector2(roomInfo.Size.X - 1, 1), - new Vector2(1, roomInfo.Size.Y - 2)); - FillRect(tileMap, topLayer, config.IN_RT, roomInfo.Position + new Vector2(roomInfo.Size.X - 1, 0), - Vector2.One); - FillRect(tileMap, middleLayer, config.T, roomInfo.Position + Vector2.Right, - new Vector2(roomInfo.Size.X - 2, 1)); - } - else - { - var rectSize = roomInfo.RoomSplit.RoomInfo.Size; - var rectPos = roomInfo.RoomSplit.RoomInfo.Position; - var template = ResourceManager.Load(roomInfo.RoomSplit.ScenePath); - var tileInstance = template.Instantiate(); - for (int i = 0; i < rectSize.X; i++) - { - for (int j = 0; j < rectSize.Y; j++) - { - var atlasCoords = - tileInstance.GetCellAtlasCoords(0, new Vector2I((int)(rectPos.X + i), (int)(rectPos.Y + j))); - - //判断层级 - if (FloorAtlasCoords.Contains(atlasCoords)) - { - tileMap.SetCell(floorLayer, new Vector2I(roomInfo.Position.X + i, roomInfo.Position.Y + j), 1, - atlasCoords); - } - else if (MiddleAtlasCoords.Contains(atlasCoords)) - { - tileMap.SetCell(middleLayer, new Vector2I(roomInfo.Position.X + i, roomInfo.Position.Y + j), 1, - atlasCoords); - } - else - { - tileMap.SetCell(topLayer, new Vector2I(roomInfo.Position.X + i, roomInfo.Position.Y + j), 1, - atlasCoords); - } - } - } - - tileInstance.QueueFree(); - } - - //铺过道 - foreach (var doorInfo in roomInfo.Doors) - { - if (doorInfo.ConnectRoom.Id > roomInfo.Id) - { - //普通的直线连接 - var doorDir1 = doorInfo.Direction; - var doorDir2 = doorInfo.ConnectDoor.Direction; - if (!doorInfo.HasCross) - { - //方向, 0横向, 1纵向 - int dir = 0; - var rect = Utils.CalcRect( - doorInfo.OriginPosition.X, - doorInfo.OriginPosition.Y, - doorInfo.ConnectDoor.OriginPosition.X, - doorInfo.ConnectDoor.OriginPosition.Y - ); - if (doorDir1 == DoorDirection.N || doorDir1 == DoorDirection.S) - { - rect.Size = new Vector2(GenerateDungeon.CorridorWidth, rect.Size.Y); - dir = 1; - } - else - { - rect.Size = new Vector2(rect.Size.X, GenerateDungeon.CorridorWidth); - } - - if (dir == 0) //横向 - { - FullHorizontalGalleryWall(tileMap, floorLayer, middleLayer, topLayer, config, rect); - } - else //纵向 - { - FullVerticalGalleryWall(tileMap, floorLayer, middleLayer, topLayer, config, rect); - } - } - else //带交叉点 - { - //方向, 0横向, 1纵向 - int dir1 = 0; - int dir2 = 0; - - Rect2 rect; - Rect2 rect2; - - //计算范围 - switch (doorDir1) - { - case DoorDirection.E: //→ - rect = new Rect2( - doorInfo.OriginPosition.X, - doorInfo.OriginPosition.Y, - doorInfo.Cross.X - doorInfo.OriginPosition.X, - GenerateDungeon.CorridorWidth - ); - break; - case DoorDirection.W: //← - rect = new Rect2( - doorInfo.Cross.X + GenerateDungeon.CorridorWidth, - doorInfo.Cross.Y, - doorInfo.OriginPosition.X - (doorInfo.Cross.X + GenerateDungeon.CorridorWidth), - GenerateDungeon.CorridorWidth - ); - break; - case DoorDirection.S: //↓ - dir1 = 1; - rect = new Rect2( - doorInfo.OriginPosition.X, - doorInfo.OriginPosition.Y, - GenerateDungeon.CorridorWidth, - doorInfo.Cross.Y - doorInfo.OriginPosition.Y - ); - break; - case DoorDirection.N: //↑ - dir1 = 1; - rect = new Rect2( - doorInfo.Cross.X, - doorInfo.Cross.Y + GenerateDungeon.CorridorWidth, - GenerateDungeon.CorridorWidth, - doorInfo.OriginPosition.Y - (doorInfo.Cross.Y + GenerateDungeon.CorridorWidth) - ); - break; - default: - rect = new Rect2(); - break; - } - - switch (doorDir2) - { - case DoorDirection.E: //→ - rect2 = new Rect2( - doorInfo.ConnectDoor.OriginPosition.X, - doorInfo.ConnectDoor.OriginPosition.Y, - doorInfo.Cross.X - doorInfo.ConnectDoor.OriginPosition.X, - GenerateDungeon.CorridorWidth - ); - break; - case DoorDirection.W: //← - rect2 = new Rect2( - doorInfo.Cross.X + GenerateDungeon.CorridorWidth, - doorInfo.Cross.Y, - doorInfo.ConnectDoor.OriginPosition.X - - (doorInfo.Cross.X + GenerateDungeon.CorridorWidth), - GenerateDungeon.CorridorWidth - ); - break; - case DoorDirection.S: //↓ - dir2 = 1; - rect2 = new Rect2( - doorInfo.ConnectDoor.OriginPosition.X, - doorInfo.ConnectDoor.OriginPosition.Y, - GenerateDungeon.CorridorWidth, - doorInfo.Cross.Y - doorInfo.ConnectDoor.OriginPosition.Y - ); - break; - case DoorDirection.N: //↑ - dir2 = 1; - rect2 = new Rect2( - doorInfo.Cross.X, - doorInfo.Cross.Y + GenerateDungeon.CorridorWidth, - GenerateDungeon.CorridorWidth, - doorInfo.ConnectDoor.OriginPosition.Y - - (doorInfo.Cross.Y + GenerateDungeon.CorridorWidth) - ); - break; - default: - rect2 = new Rect2(); - break; - } - - FillRect(tileMap, floorLayer, config.Ground, doorInfo.Cross + Vector2.One, - new Vector2(GenerateDungeon.CorridorWidth - 2, GenerateDungeon.CorridorWidth - 2)); - - //墙壁 - if (dir1 == 0) - { - FullHorizontalGalleryWall(tileMap, floorLayer, middleLayer, topLayer, config, rect); - } - else - { - FullVerticalGalleryWall(tileMap, floorLayer, middleLayer, topLayer, config, rect); - } - - if (dir2 == 0) - { - FullHorizontalGalleryWall(tileMap, floorLayer, middleLayer, topLayer, config, rect2); - } - else - { - FullVerticalGalleryWall(tileMap, floorLayer, middleLayer, topLayer, config, rect2); - } - - if ((doorDir1 == DoorDirection.N && doorDir2 == DoorDirection.E) || //↑→ - (doorDir2 == DoorDirection.N && doorDir1 == DoorDirection.E)) - { - FillRect(tileMap, topLayer, config.OUT_RT, - doorInfo.Cross + new Vector2(0, GenerateDungeon.CorridorWidth - 1), - Vector2.One); - FillRect(tileMap, topLayer, config.IN_RT, doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 0), - Vector2.One); - FillRect(tileMap, middleLayer, config.T, doorInfo.Cross, new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); - FillRect(tileMap, topLayer, config.R, doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 1), - new Vector2(1, GenerateDungeon.CorridorWidth - 1)); - } - else if ((doorDir1 == DoorDirection.E && doorDir2 == DoorDirection.S) || //→↓ - (doorDir2 == DoorDirection.E && doorDir1 == DoorDirection.S)) - { - FillRect(tileMap, middleLayer, config.OUT_RB, doorInfo.Cross, Vector2.One); - FillRect(tileMap, topLayer, config.IN_RB, - doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, - GenerateDungeon.CorridorWidth - 1), - Vector2.One); - FillRect(tileMap, topLayer, config.R, doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 0), - new Vector2(1, GenerateDungeon.CorridorWidth - 1)); - FillRect(tileMap, topLayer, config.B, doorInfo.Cross + new Vector2(0, GenerateDungeon.CorridorWidth - 1), - new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); - } - else if ((doorDir1 == DoorDirection.S && doorDir2 == DoorDirection.W) || //↓← - (doorDir2 == DoorDirection.S && doorDir1 == DoorDirection.W)) - { - FillRect(tileMap, middleLayer, config.OUT_LB, - doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, 0), Vector2.One); - FillRect(tileMap, topLayer, config.IN_LB, doorInfo.Cross + new Vector2(0, GenerateDungeon.CorridorWidth - 1), - Vector2.One); - FillRect(tileMap, topLayer, config.L, doorInfo.Cross, new Vector2(1, GenerateDungeon.CorridorWidth - 1)); - FillRect(tileMap, topLayer, config.B, doorInfo.Cross + new Vector2(1, GenerateDungeon.CorridorWidth - 1), - new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); - } - else if ((doorDir1 == DoorDirection.W && doorDir2 == DoorDirection.N) || //←↑ - (doorDir2 == DoorDirection.W && doorDir1 == DoorDirection.N)) - { - FillRect(tileMap, topLayer, config.OUT_LT, - doorInfo.Cross + new Vector2(GenerateDungeon.CorridorWidth - 1, - GenerateDungeon.CorridorWidth - 1), - Vector2.One); - FillRect(tileMap, topLayer, config.IN_LT, doorInfo.Cross, Vector2.One); - FillRect(tileMap, middleLayer, config.T, doorInfo.Cross + new Vector2(1, 0), - new Vector2(GenerateDungeon.CorridorWidth - 1, 1)); - FillRect(tileMap, topLayer, config.L, doorInfo.Cross + new Vector2(0, 1), - new Vector2(1, GenerateDungeon.CorridorWidth - 1)); - } - - //在房间墙上开洞 - switch (doorDir1) - { - case DoorDirection.E: //→ - ClearRect(tileMap, topLayer, doorInfo.OriginPosition + new Vector2(-1, 1), - new Vector2(1, rect.Size.Y - 2)); - FillRect(tileMap, floorLayer, config.Ground, doorInfo.OriginPosition + new Vector2(-1, 1), - new Vector2(1, rect.Size.Y - 2)); - break; - case DoorDirection.W: //← - ClearRect(tileMap, topLayer, doorInfo.OriginPosition + new Vector2(0, 1), - new Vector2(1, rect.Size.Y - 2)); - FillRect(tileMap, floorLayer, config.Ground, doorInfo.OriginPosition + new Vector2(0, 1), - new Vector2(1, rect.Size.Y - 2)); - break; - case DoorDirection.S: //↓ - ClearRect(tileMap, topLayer, doorInfo.OriginPosition + new Vector2(1, -1), - new Vector2(rect.Size.X - 2, 1)); - FillRect(tileMap, floorLayer, config.Ground, doorInfo.OriginPosition + new Vector2(1, -1), - new Vector2(rect.Size.X - 2, 1)); - break; - case DoorDirection.N: //↑ - ClearRect(tileMap, middleLayer, doorInfo.OriginPosition + new Vector2(1, 2), - new Vector2(rect.Size.X - 2, 1)); - FillRect(tileMap, floorLayer, config.Ground, doorInfo.OriginPosition + new Vector2(1, 0), - new Vector2(rect.Size.X - 2, 1)); - break; - } - - switch (doorDir2) - { - case DoorDirection.E: //→ - ClearRect(tileMap, topLayer, doorInfo.ConnectDoor.OriginPosition + new Vector2(-1, 1), - new Vector2(1, rect2.Size.Y - 2)); - FillRect(tileMap, floorLayer, config.Ground, doorInfo.ConnectDoor.OriginPosition + new Vector2(-1, 1), - new Vector2(1, rect2.Size.Y - 2)); - break; - case DoorDirection.W: //← - ClearRect(tileMap, topLayer, doorInfo.ConnectDoor.OriginPosition + new Vector2(0, 1), - new Vector2(1, rect2.Size.Y - 2)); - FillRect(tileMap, floorLayer, config.Ground, doorInfo.ConnectDoor.OriginPosition + new Vector2(0, 1), - new Vector2(1, rect2.Size.Y - 2)); - break; - case DoorDirection.S: //↓ - ClearRect(tileMap, topLayer, doorInfo.ConnectDoor.OriginPosition + new Vector2(1, -1), - new Vector2(rect2.Size.X - 2, 1)); - FillRect(tileMap, floorLayer, config.Ground, doorInfo.ConnectDoor.OriginPosition + new Vector2(1, -1), - new Vector2(rect2.Size.X - 2, 1)); - break; - case DoorDirection.N: //↑ - ClearRect(tileMap, middleLayer, doorInfo.ConnectDoor.OriginPosition + new Vector2(1, 0), - new Vector2(rect2.Size.X - 2, 1)); - FillRect(tileMap, floorLayer, config.Ground, doorInfo.ConnectDoor.OriginPosition + new Vector2(1, 0), - new Vector2(rect2.Size.X - 2, 1)); - break; - } - } - } - } - } - - private static void FillRect(TileMap tileMap, int layer, TileCellInfo info, Vector2 pos, Vector2 size) - { - for (int i = 0; i < size.X; i++) - { - for (int j = 0; j < size.Y; j++) - { - tileMap.SetCell(layer, new Vector2I((int)pos.X + i, (int)pos.Y + j), 1, info.AutotileCoord); - } - } - } - - private static void ClearRect(TileMap tileMap, int layer, Vector2 pos, Vector2 size) - { - for (int i = 0; i < size.X; i++) - { - for (int j = 0; j < size.Y; j++) - { - //tileMap.SetCell((int)pos.X + i, (int)pos.Y + j, -1); - tileMap.SetCell(layer, new Vector2I((int)pos.X + i, (int)pos.Y + j), -1); - } - } - } - - private static void FullHorizontalGalleryWall(TileMap tileMap, int floorLayer, int middleLayer, int topLayer, - AutoTileConfig config, Rect2 rect) - { - FillRect(tileMap, floorLayer, config.Ground, rect.Position + new Vector2(0, 1), rect.Size - new Vector2(0, 2)); - FillRect(tileMap, middleLayer, config.T, rect.Position, new Vector2(rect.Size.X, 1)); - FillRect(tileMap, topLayer, config.B, rect.Position + new Vector2(0, rect.Size.Y - 1), new Vector2(rect.Size.X, 1)); - //左 - ClearRect(tileMap, topLayer, rect.Position + new Vector2(-1, 1), new Vector2(1, rect.Size.Y - 2)); - FillRect(tileMap, floorLayer, config.Ground, rect.Position + new Vector2(-1, 1), new Vector2(1, rect.Size.Y - 2)); - //右 - ClearRect(tileMap, topLayer, rect.Position + new Vector2(rect.Size.X, 1), new Vector2(1, rect.Size.Y - 2)); - FillRect(tileMap, floorLayer, config.Ground, rect.Position + new Vector2(rect.Size.X, 1), new Vector2(1, rect.Size.Y - 2)); - } - - private static void FullVerticalGalleryWall(TileMap tileMap, int floorLayer, int middleLayer, int topLayer, - AutoTileConfig config, Rect2 rect) - { - FillRect(tileMap, floorLayer, config.Ground, rect.Position + new Vector2(1, 0), rect.Size - new Vector2(2, 0)); - FillRect(tileMap, topLayer, config.L, rect.Position, new Vector2(1, rect.Size.Y)); - FillRect(tileMap, topLayer, config.R, rect.Position + new Vector2(rect.Size.X - 1, 0), new Vector2(1, rect.Size.Y)); - //上 - ClearRect(tileMap, topLayer, rect.Position + new Vector2(1, -1), new Vector2(rect.Size.X - 2, 1)); - FillRect(tileMap, floorLayer, config.Ground, rect.Position + new Vector2(1, -1), new Vector2(rect.Size.X - 2, 1)); - //下 - ClearRect(tileMap, middleLayer, rect.Position + new Vector2(1, rect.Size.Y), new Vector2(rect.Size.X - 2, 1)); - FillRect(tileMap, floorLayer, config.Ground, rect.Position + new Vector2(1, rect.Size.Y), new Vector2(rect.Size.X - 2, 1)); - } - -} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index e311196..cebe220 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -8,10 +8,6 @@ /// public partial class RoomManager : Node2D { - public const int FloorMapLayer = 0; - public const int MiddleMapLayer = 1; - public const int TopMapLayer = 2; - /// /// //对象根节点 /// @@ -37,12 +33,8 @@ /// public NavigationRegion2D NavigationPolygon { get; private set; } - //已经标记过的点 - private HashSet _usePoints = new HashSet(); - //导航区域数据 - private List _polygonDataList = new List(); - + private DungeonTile _dungeonTile; private AutoTileConfig _autoTileConfig; private Font _font; @@ -73,20 +65,14 @@ //填充地牢 _autoTileConfig = new AutoTileConfig(); - DungeonTileManager.AutoFillRoomTile(TileRoot, FloorMapLayer, MiddleMapLayer, TopMapLayer, _autoTileConfig, _generateDungeon.StartRoom); + _dungeonTile = new DungeonTile(TileRoot); + _dungeonTile.AutoFillRoomTile(_autoTileConfig, _generateDungeon.StartRoom); //根据房间数据创建填充 tiled var nowTicks = DateTime.Now.Ticks; //生成寻路网格 - GenerateNavigationPolygon(); - var polygon = new NavigationPolygon(); - foreach (var polygonData in _polygonDataList) - { - polygon.AddOutline(polygonData.Points.ToArray()); - } - polygon.MakePolygonsFromOutlines(); - NavigationPolygon.NavigationPolygon = polygon; + _dungeonTile.GenerateNavigationPolygon(NavigationPolygon); GD.Print("计算NavigationPolygon用时: " + (DateTime.Now.Ticks - nowTicks) / 10000 + "毫秒"); //播放bgm @@ -97,9 +83,9 @@ Player.PickUpWeapon(WeaponManager.GetGun("1004")); Player.PickUpWeapon(WeaponManager.GetGun("1003")); - // var enemy1 = new Enemy(); - // enemy1.PutDown(new Vector2(100, 100), RoomLayerEnum.YSortLayer); - // enemy1.PickUpWeapon(WeaponManager.GetGun("1001")); + var enemy1 = new Enemy(); + enemy1.PutDown(new Vector2(150, 150), RoomLayerEnum.YSortLayer); + enemy1.PickUpWeapon(WeaponManager.GetGun("1001")); // for (int i = 0; i < 10; i++) // { @@ -169,569 +155,22 @@ { if (GameApplication.Instance.Debug) { - //绘制ai寻路区域 - for (var i = 0; i < _polygonDataList.Count; i++) + if (_dungeonTile != null) { - var item = _polygonDataList[i]; - if (item.Points.Count >= 2) + //绘制ai寻路区域 + foreach (var item in _dungeonTile.GetPolygonData()) { - DrawPolyline(item.Points.Concat(new []{ item.Points[0] }).ToArray(), Colors.Red); - } - } - } - //绘制房间区域 - DrawRoomInfo(_generateDungeon.StartRoom); - } - - /// - /// 返回指定位置的Tile是否为可以行走 - /// - public bool IsWayTile(int x, int y) - { - return TileRoot.GetCellTileData(FloorMapLayer, new Vector2I(x, y)) != null; - } - - /// - /// 返回指定坐标下对应的Tile是否为可以行走 - /// - public bool IsWayPosition(float x, float y) - { - var tileMapCellSize = TileRoot.CellQuadrantSize; - return IsWayTile((int)(x / tileMapCellSize), (int)(y / tileMapCellSize)); - } - - /// - /// 自动生成导航区域 - /// - private void GenerateNavigationPolygon() - { - var size = new Vector2(TileRoot.CellQuadrantSize, TileRoot.CellQuadrantSize); - - var rect = TileRoot.GetUsedRect(); - - var x = rect.Position.X; - var y = rect.Position.Y; - var w = rect.Size.X; - var h = rect.Size.Y; - - for (int j = y; j < h; j++) - { - for (int i = x; i < w; i++) - { - if (IsWayTile(i, j)) - { - if (!_usePoints.Contains(new Vector2(i, j))) + if (item.Points.Count >= 2) { - NavigationPolygonData polygonData = null; - - if (!IsWayTile(i, j - 1)) - { - polygonData = CalcOutline(i, j, TileRoot, size); - } - else if (!IsWayTile(i, j + 1)) - { - polygonData = CalcInline(i, j, TileRoot, size); - } - - if (polygonData != null) - { - _polygonDataList.Add(polygonData); - } + DrawPolyline(item.Points.Concat(new []{ item.Points[0] }).ToArray(), Colors.Red); } } } - } - } - - //计算导航网格外轮廓 - private NavigationPolygonData CalcOutline(int i, int j, TileMap tileMap, Vector2 size) - { - var polygonData = new NavigationPolygonData(); - polygonData.Type = NavigationPolygonType.Out; - var points = polygonData.Points; - // 0:右, 1:下, 2:左, 3:上 - var dir = 0; - var offset = new Vector2(size.X * 0.5f, size.Y * 0.5f); - //找到路, 向右开始找边界 - var startPos = new Vector2(i, j); - - var tempI = i; - var tempJ = j; - - while (true) - { - switch (dir) - { - case 0: //右 - { - if (IsWayTile(tempI, tempJ - 1)) //先向上找 - { - dir = 3; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempJ--; - break; - } - else if (IsWayTile(tempI + 1, tempJ)) //再向右找 - { - if (points.Count == 0) - { - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - } - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - PutUsePoint(new Vector2(tempI, tempJ)); - tempI++; - break; - } - else if (IsWayTile(tempI, tempJ + 1)) //向下找 - { - dir = 1; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempJ++; - break; - } - - return null; - } - case 1: //下 - { - if (IsWayTile(tempI + 1, tempJ)) //先向右找 - { - dir = 0; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempI++; - break; - } - else if (IsWayTile(tempI, tempJ + 1)) //再向下找 - { - if (points.Count == 0) - { - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - } - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - PutUsePoint(new Vector2(tempI, tempJ)); - tempJ++; - break; - } - else if (IsWayTile(tempI - 1, tempJ)) //向左找 - { - dir = 2; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempI--; - break; - } - - return null; - } - case 2: //左 - { - if (IsWayTile(tempI, tempJ + 1)) //先向下找 - { - dir = 1; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempJ++; - break; - } - else if (IsWayTile(tempI - 1, tempJ)) //再向左找 - { - if (points.Count == 0) - { - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - } - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - PutUsePoint(new Vector2(tempI, tempJ)); - tempI--; - break; - } - else if (IsWayTile(tempI, tempJ - 1)) //向上找 - { - dir = 3; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempJ--; - break; - } - - return null; - } - case 3: //上 - { - if (IsWayTile(tempI - 1, tempJ)) //先向左找 - { - dir = 2; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempI--; - break; - } - else if (IsWayTile(tempI, tempJ - 1)) //再向上找 - { - if (points.Count == 0) - { - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - } - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - PutUsePoint(new Vector2(tempI, tempJ)); - tempJ--; - break; - } - else if (IsWayTile(tempI + 1, tempJ)) //向右找 - { - dir = 0; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempI++; - break; - } - - return null; - } - } + //绘制房间区域 + DrawRoomInfo(_generateDungeon.StartRoom); } } - //计算导航网格内轮廓 - private NavigationPolygonData CalcInline(int i, int j, TileMap tileMap, Vector2 size) - { - var polygonData = new NavigationPolygonData(); - polygonData.Type = NavigationPolygonType.In; - var points = polygonData.Points; - // 0:右, 1:下, 2:左, 3:上 - var dir = 0; - var offset = new Vector2(size.X * 0.5f, size.Y * 0.5f); - //找到路, 向右开始找边界 - var startPos = new Vector2(i - 1, j); - - var tempI = i; - var tempJ = j; - - while (true) - { - switch (dir) - { - case 0: //右 - { - if (IsWayTile(tempI, tempJ + 1)) //向下找 - { - dir = 1; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempJ++; - break; - } - else if (IsWayTile(tempI + 1, tempJ)) //再向右找 - { - if (points.Count == 0) - { - points.Add(new Vector2((tempI - 1) * size.X, tempJ * size.Y) + offset); - } - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - PutUsePoint(new Vector2(tempI, tempJ)); - tempI++; - break; - } - else if (IsWayTile(tempI, tempJ - 1)) //先向上找 - { - dir = 3; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempJ--; - break; - } - - return null; - } - case 1: //下 - { - if (IsWayTile(tempI - 1, tempJ)) //向左找 - { - dir = 2; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempI--; - break; - } - else if (IsWayTile(tempI, tempJ + 1)) //再向下找 - { - if (points.Count == 0) - { - points.Add(new Vector2((tempI - 1) * size.X, tempJ * size.Y) + offset); - } - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - PutUsePoint(new Vector2(tempI, tempJ)); - tempJ++; - break; - } - else if (IsWayTile(tempI + 1, tempJ)) //先向右找 - { - dir = 0; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempI++; - break; - } - - return null; - } - case 2: //左 - { - if (IsWayTile(tempI, tempJ - 1)) //向上找 - { - dir = 3; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempJ--; - break; - } - else if (IsWayTile(tempI - 1, tempJ)) //再向左找 - { - if (points.Count == 0) - { - points.Add(new Vector2((tempI - 1) * size.X, tempJ * size.Y) + offset); - } - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - PutUsePoint(new Vector2(tempI, tempJ)); - tempI--; - break; - } - else if (IsWayTile(tempI, tempJ + 1)) //先向下找 - { - dir = 1; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempJ++; - break; - } - - return null; - } - case 3: //上 - { - if (IsWayTile(tempI + 1, tempJ)) //向右找 - { - dir = 0; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempI++; - break; - } - else if (IsWayTile(tempI, tempJ - 1)) //再向上找 - { - if (points.Count == 0) - { - points.Add(new Vector2((tempI - 1) * size.X, tempJ * size.Y) + offset); - } - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - PutUsePoint(new Vector2(tempI, tempJ)); - tempJ--; - break; - } - else if (IsWayTile(tempI - 1, tempJ)) //先向左找 - { - dir = 2; - - var pos = new Vector2(tempI, tempJ); - if (points.Count > 1 && pos == startPos) - { - return polygonData; - } - - points.Add(new Vector2(tempI * size.X, tempJ * size.Y) + offset); - PutUsePoint(pos); - - tempI--; - break; - } - - return null; - } - } - } - } - - //记录导航网格中已经使用过的坐标 - private void PutUsePoint(Vector2 pos) - { - if (_usePoints.Contains(pos)) - { - throw new Exception("生成导航多边形发生错误! 点: " + pos + "发生交错!"); - } - - _usePoints.Add(pos); - } - //绘制房间区域, debug 用 private void DrawRoomInfo(RoomInfo room) {