diff --git a/DungeonShooting_Godot/prefab/role/Enemy.tscn b/DungeonShooting_Godot/prefab/role/Enemy.tscn
index 6a76c2e..7185ae3 100644
--- a/DungeonShooting_Godot/prefab/role/Enemy.tscn
+++ b/DungeonShooting_Godot/prefab/role/Enemy.tscn
@@ -86,8 +86,8 @@
radius = 4.0
[node name="Enemy" instance=ExtResource( 1 )]
-CollisionLayer = 16
-CollisionMask = 25
+collision_layer = 16
+collision_mask = 1
[node name="ShadowSprite" parent="." index="0"]
material = SubResource( 1 )
diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn
index 31fab4d..ced91c4 100644
--- a/DungeonShooting_Godot/prefab/role/Player.tscn
+++ b/DungeonShooting_Godot/prefab/role/Player.tscn
@@ -86,6 +86,8 @@
radius = 4.0
[node name="Player" instance=ExtResource( 1 )]
+collision_layer = 8
+collision_mask = 1
[node name="ShadowSprite" parent="." index="0"]
material = SubResource( 1 )
diff --git a/DungeonShooting_Godot/prefab/weapon/bullet/Bullet.tscn b/DungeonShooting_Godot/prefab/weapon/bullet/Bullet.tscn
index d2ad542..92cdf1f 100644
--- a/DungeonShooting_Godot/prefab/weapon/bullet/Bullet.tscn
+++ b/DungeonShooting_Godot/prefab/weapon/bullet/Bullet.tscn
@@ -29,7 +29,7 @@
[node name="Bullet" type="Node"]
script = ExtResource( 1 )
-CollisionMask = 1
+collision_mask = 1
[node name="ShadowSprite" type="Sprite" parent="."]
material = SubResource( 3 )
diff --git a/DungeonShooting_Godot/scene/Room.tscn b/DungeonShooting_Godot/scene/Room.tscn
index 483f170..12df33d 100644
--- a/DungeonShooting_Godot/scene/Room.tscn
+++ b/DungeonShooting_Godot/scene/Room.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=6 format=2]
+[gd_scene load_steps=12 format=2]
[ext_resource path="res://resource/sprite/environment/itch-io-DungeonTileset4/16x16 dungeon ii wall reconfig v04 spritesheet.png" type="Texture" id=1]
[ext_resource path="res://src/game/room/RoomManager.cs" type="Script" id=3]
@@ -8,12 +8,30 @@
background_mode = 4
glow_enabled = true
+[sub_resource type="ConvexPolygonShape2D" id=3]
+points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
+
+[sub_resource type="ConvexPolygonShape2D" id=4]
+points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
+
+[sub_resource type="ConvexPolygonShape2D" id=5]
+points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
+
+[sub_resource type="ConvexPolygonShape2D" id=6]
+points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
+
+[sub_resource type="ConvexPolygonShape2D" id=7]
+points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
+
+[sub_resource type="ConvexPolygonShape2D" id=8]
+points = PoolVector2Array( 0, 0, 16, 0, 16, 12, 0, 12 )
+
[sub_resource type="TileSet" id=2]
0/name = "16x16 dungeon ii wall reconfig v04 spritesheet.png 0"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
-0/region = Rect2( 0, 0, 64, 144 )
+0/region = Rect2( 0, 0, 256, 144 )
0/tile_mode = 2
0/autotile/icon_coordinate = Vector2( 0, 8 )
0/autotile/tile_size = Vector2( 16, 16 )
@@ -26,18 +44,55 @@
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
+0/shape = SubResource( 3 )
0/shape_one_way = false
-0/shape_one_way_margin = 0.0
-0/shapes = [ ]
+0/shape_one_way_margin = 1.0
+0/shapes = [ {
+"autotile_coord": Vector2( 1, 3 ),
+"one_way": false,
+"one_way_margin": 1.0,
+"shape": SubResource( 3 ),
+"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
+}, {
+"autotile_coord": Vector2( 11, 2 ),
+"one_way": false,
+"one_way_margin": 1.0,
+"shape": SubResource( 4 ),
+"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
+}, {
+"autotile_coord": Vector2( 13, 2 ),
+"one_way": false,
+"one_way_margin": 1.0,
+"shape": SubResource( 5 ),
+"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
+}, {
+"autotile_coord": Vector2( 3, 3 ),
+"one_way": false,
+"one_way_margin": 1.0,
+"shape": SubResource( 6 ),
+"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
+}, {
+"autotile_coord": Vector2( 2, 2 ),
+"one_way": false,
+"one_way_margin": 1.0,
+"shape": SubResource( 7 ),
+"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
+}, {
+"autotile_coord": Vector2( 2, 7 ),
+"one_way": false,
+"one_way_margin": 1.0,
+"shape": SubResource( 8 ),
+"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
+} ]
0/z_index = 0
[node name="Room" type="Navigation2D"]
script = ExtResource( 3 )
ObjectRootPath = NodePath("ObjectRoot")
YSortRootPath = NodePath("SortRoot")
-TopTilePath = NodePath("SortRoot/MiddleTileMap/TopTileMap")
-MiddleTilePath = NodePath("SortRoot/MiddleTileMap")
-FloorTilePath = NodePath("SortRoot/MiddleTileMap/FloorTileMap")
+TopTilePath = NodePath("SortRoot/MapRoot/TopTileMap")
+MiddleTilePath = NodePath("SortRoot/MapRoot/MiddleTileMap")
+FloorTilePath = NodePath("SortRoot/MapRoot/FloorTileMap")
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 1 )
@@ -53,22 +108,29 @@
[node name="SortRoot" type="YSort" parent="."]
-[node name="MiddleTileMap" type="TileMap" parent="SortRoot"]
+[node name="MapRoot" type="Node2D" parent="SortRoot"]
+
+[node name="TopTileMap" type="TileMap" parent="SortRoot/MapRoot"]
+z_index = 10
+tile_set = SubResource( 2 )
+cell_size = Vector2( 16, 16 )
+collision_mask = 0
+bake_navigation = true
+format = 1
+
+[node name="MiddleTileMap" type="TileMap" parent="SortRoot/MapRoot"]
+tile_set = SubResource( 2 )
cell_size = Vector2( 16, 16 )
cell_tile_origin = 2
cell_y_sort = true
+collision_mask = 0
bake_navigation = true
format = 1
-[node name="TopTileMap" type="TileMap" parent="SortRoot/MiddleTileMap"]
-z_index = 10
-cell_size = Vector2( 16, 16 )
-bake_navigation = true
-format = 1
-
-[node name="FloorTileMap" type="TileMap" parent="SortRoot/MiddleTileMap"]
+[node name="FloorTileMap" type="TileMap" parent="SortRoot/MapRoot"]
z_index = -10
tile_set = SubResource( 2 )
cell_size = Vector2( 16, 16 )
+collision_mask = 0
bake_navigation = true
format = 1
diff --git a/DungeonShooting_Godot/src/game/room/AutoTileConfig.cs b/DungeonShooting_Godot/src/game/room/AutoTileConfig.cs
new file mode 100644
index 0000000..7c49573
--- /dev/null
+++ b/DungeonShooting_Godot/src/game/room/AutoTileConfig.cs
@@ -0,0 +1,18 @@
+
+using Godot;
+
+///
+/// 房间图块配置信息
+///
+public class AutoTileConfig
+{
+ public TileCellInfo LT = new TileCellInfo(0, new Vector2(3, 3));
+ public TileCellInfo LB = new TileCellInfo(0, new Vector2(11, 2));
+ public TileCellInfo RT = new TileCellInfo(0, new Vector2(1, 3));
+ public TileCellInfo RB = new TileCellInfo(0, new Vector2(13, 2));
+ public TileCellInfo R = new TileCellInfo(0, new Vector2(1, 3));
+ public TileCellInfo L = new TileCellInfo(0, new Vector2(3, 3));
+ public TileCellInfo T = new TileCellInfo(0, new Vector2(2, 7));
+ public TileCellInfo B = new TileCellInfo(0, new Vector2(2, 2));
+ public TileCellInfo In = new TileCellInfo(0, new Vector2(0, 8));
+}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/room/DungeonTileManager.cs b/DungeonShooting_Godot/src/game/room/DungeonTileManager.cs
index 427f2e6..d762d4e 100644
--- a/DungeonShooting_Godot/src/game/room/DungeonTileManager.cs
+++ b/DungeonShooting_Godot/src/game/room/DungeonTileManager.cs
@@ -1,22 +1,35 @@
-using System;
using Godot;
public static class DungeonTileManager
{
- public static void AutoFillRoomTile(TileMap floor, TileMap middle, TileMap top, RoomInfo roomInfo)
+ public static void AutoFillRoomTile(TileMap floor, TileMap middle, TileMap top, AutoTileConfig config,
+ RoomInfo roomInfo)
{
foreach (var info in roomInfo.Next)
{
- AutoFillRoomTile(floor, middle, top, info);
+ AutoFillRoomTile(floor, middle, top, config, info);
}
//铺房间
- FillRect(floor, 0, roomInfo.Position, roomInfo.Size);
+ FillRect(floor, config.In, roomInfo.Position + Vector2.One, roomInfo.Size - new Vector2(2, 2));
+
+ FillRect(top, config.LT, roomInfo.Position, Vector2.One);
+ FillRect(top, config.L, roomInfo.Position + new Vector2(0, 1), new Vector2(1, roomInfo.Size.y - 2));
+ FillRect(top, config.LB, roomInfo.Position + new Vector2(0, roomInfo.Size.y - 1), new Vector2(1, 1));
+ FillRect(top, config.B, roomInfo.Position + new Vector2(1, roomInfo.Size.y - 1),
+ new Vector2(roomInfo.Size.x - 2, 1));
+ FillRect(top, config.RB, roomInfo.Position + new Vector2(roomInfo.Size.x - 1, roomInfo.Size.y - 1),
+ Vector2.One);
+ FillRect(top, config.R, roomInfo.Position + new Vector2(roomInfo.Size.x - 1, 1),
+ new Vector2(1, roomInfo.Size.y - 2));
+ FillRect(top, config.RT, roomInfo.Position + new Vector2(roomInfo.Size.x - 1, 0), Vector2.One);
+ FillRect(middle, config.T, roomInfo.Position + Vector2.Right, new Vector2(roomInfo.Size.x - 2, 1));
+
//铺过道
foreach (var doorInfo in roomInfo.Doors)
{
- if (doorInfo.ConnectRoom.Id < roomInfo.Id)
+ if (doorInfo.ConnectRoom.Id > roomInfo.Id)
{
//普通的直线连接
if (!doorInfo.HasCross)
@@ -39,7 +52,35 @@
rect.Size = new Vector2(rect.Size.x, GenerateDungeon.CorridorWidth);
}
- FillRect(floor, 0, rect.Position, rect.Size);
+
+ if (dir == 0) //横向
+ {
+ FillRect(floor, config.In, rect.Position + new Vector2(0, 1), rect.Size - new Vector2(0, 2));
+ FillRect(middle, config.T, rect.Position, new Vector2(rect.Size.x, 1));
+ FillRect(top, config.B, rect.Position + new Vector2(0, rect.Size.y - 1), new Vector2(rect.Size.x, 1));
+
+ //左
+ ClearRect(top, rect.Position + new Vector2(-1, 1), new Vector2(1, rect.Size.y - 2));
+ FillRect(floor, config.In, rect.Position + new Vector2(-1, 1), new Vector2(1, rect.Size.y - 2));
+
+ //又
+ ClearRect(top, rect.Position + new Vector2(rect.Size.x, 1), new Vector2(1, rect.Size.y - 2));
+ FillRect(floor, config.In, rect.Position + new Vector2(rect.Size.x, 1), new Vector2(1, rect.Size.y - 2));
+ }
+ else //纵向
+ {
+ FillRect(floor, config.In, rect.Position + new Vector2(1, 0), rect.Size - new Vector2(2, 0));
+ FillRect(top, config.L, rect.Position, new Vector2(1, rect.Size.y));
+ FillRect(top, config.R, rect.Position + new Vector2(rect.Size.x - 1, 0), new Vector2(1, rect.Size.y));
+
+ //上
+ ClearRect(top, rect.Position + new Vector2(1, -1), new Vector2(rect.Size.x - 2, 1));
+ FillRect(floor, config.In, rect.Position + new Vector2(1, -1), new Vector2(rect.Size.x - 2, 1));
+
+ //下
+ ClearRect(middle, rect.Position + new Vector2(1, rect.Size.y), new Vector2(rect.Size.x - 2, 1));
+ FillRect(floor, config.In, rect.Position + new Vector2(1, rect.Size.y), new Vector2(rect.Size.x - 2, 1));
+ }
}
else //带交叉点
{
@@ -134,22 +175,36 @@
break;
}
- FillRect(floor, 0, rect.Position, rect.Size);
- FillRect(floor, 0, rect2.Position, rect2.Size);
- FillRect(floor, 0, doorInfo.Cross, new Vector2(GenerateDungeon.CorridorWidth, GenerateDungeon.CorridorWidth));
+ FillRect(floor, config.In, rect.Position, rect.Size);
+ FillRect(floor, config.In, rect2.Position, rect2.Size);
+ FillRect(floor, config.In, doorInfo.Cross, new Vector2(GenerateDungeon.CorridorWidth, GenerateDungeon.CorridorWidth));
+
+
}
}
}
}
- private static void FillRect(TileMap tileMap, int index, Vector2 pos, Vector2 size)
+ private static void FillRect(TileMap tileMap, TileCellInfo info, 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, index, false, false, false, new Vector2(0, 8));
+ tileMap.SetCell((int)pos.x + i, (int)pos.y + j, info.Id, false, false, false, info.AutotileCoord);
}
}
}
+
+ private static void ClearRect(TileMap tileMap, 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);
+ }
+ }
+ }
+
}
\ 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 a7f5591..591c41b 100644
--- a/DungeonShooting_Godot/src/game/room/RoomManager.cs
+++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs
@@ -35,6 +35,8 @@
//导航区域数据
private List _polygonDataList = new List();
+
+ private AutoTileConfig _autoTileConfig;
public TileMap FloorTileMap { get; private set; }
public TileMap MiddleTileMap { get; private set; }
@@ -79,8 +81,10 @@
//生成地牢房间
_generateDungeon = new GenerateDungeon();
_generateDungeon.Generate();
+
//填充地牢
- DungeonTileManager.AutoFillRoomTile(FloorTileMap, MiddleTileMap, TopTileMap, _generateDungeon.StartRoom);
+ _autoTileConfig = new AutoTileConfig();
+ DungeonTileManager.AutoFillRoomTile(FloorTileMap, MiddleTileMap, TopTileMap, _autoTileConfig, _generateDungeon.StartRoom);
FloorTileMap.UpdateDirtyQuadrants();
MiddleTileMap.UpdateDirtyQuadrants();
TopTileMap.UpdateDirtyQuadrants();
@@ -89,7 +93,7 @@
var nowTicks = DateTime.Now.Ticks;
//生成寻路网格
- GenerateNavigationPolygon();
+ //GenerateNavigationPolygon();
GD.Print("计算NavigationPolygon用时: " + (DateTime.Now.Ticks - nowTicks) / 10000 + "毫秒");
var polygon = new NavigationPolygon();
diff --git a/DungeonShooting_Godot/src/game/room/TileCellInfo.cs b/DungeonShooting_Godot/src/game/room/TileCellInfo.cs
index 4ddecca..b606e79 100644
--- a/DungeonShooting_Godot/src/game/room/TileCellInfo.cs
+++ b/DungeonShooting_Godot/src/game/room/TileCellInfo.cs
@@ -1,6 +1,9 @@
using Godot;
+///
+/// 地图cell属性信息
+///
public class TileCellInfo
{
public TileCellInfo(int id, Vector2? autotileCoord)
@@ -9,6 +12,13 @@
AutotileCoord = autotileCoord;
}
+ ///
+ /// 在TileSet中的图块id
+ ///
public int Id;
+
+ ///
+ /// 如果是图块集, 该属性就表示在图块集的位置
+ ///
public Vector2? AutotileCoord;
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/room/TileConfig.cs b/DungeonShooting_Godot/src/game/room/TileConfig.cs
deleted file mode 100644
index 88aecd4..0000000
--- a/DungeonShooting_Godot/src/game/room/TileConfig.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-
-using Godot;
-
-///
-/// 房间图块配置信息
-///
-public class TileConfig
-{
-
-}
\ No newline at end of file