diff --git a/DungeonShooting_Godot/src/framework/common/Utils.cs b/DungeonShooting_Godot/src/framework/common/Utils.cs
index 4302194..dd91a38 100644
--- a/DungeonShooting_Godot/src/framework/common/Utils.cs
+++ b/DungeonShooting_Godot/src/framework/common/Utils.cs
@@ -369,6 +369,33 @@
}
///
+ /// 计算Vector2点所占用的区域
+ ///
+ public static Rect2I CalcRect(IEnumerable cells)
+ {
+ //单位: 像素
+ var canvasXStart = int.MaxValue;
+ var canvasYStart = int.MaxValue;
+ var canvasXEnd = int.MinValue;
+ var canvasYEnd = int.MinValue;
+
+ foreach (var pos in cells)
+ {
+ canvasXStart = Mathf.Min(pos.X, canvasXStart);
+ canvasYStart = Mathf.Min(pos.Y, canvasYStart);
+ canvasXEnd = Mathf.Max(pos.X + 1, canvasXEnd);
+ canvasYEnd = Mathf.Max(pos.Y + 1, canvasYEnd);
+ }
+
+ return new Rect2I(
+ canvasXStart,
+ canvasYStart,
+ canvasXEnd - canvasXStart,
+ canvasYEnd - canvasYStart
+ );
+ }
+
+ ///
/// 计算TileSet Cell所占用的区域
///
public static Rect2I CalcTileRect(IEnumerable cells)
diff --git a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs
index 3e9aa7c..505a8ab 100644
--- a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs
+++ b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs
@@ -583,26 +583,26 @@
nextRoomDoor.ConnectRoom = roomInfo;
nextRoomDoor.ConnectDoor = roomDoor;
- // //先寻找直通门
- // if (Random.RandomBoolean())
- // {s
- // //直行通道, 优先纵轴
- // if (TryConnectVerticalDoor(roomInfo, roomDoor, nextRoomInfo, nextRoomDoor)
- // || TryConnectHorizontalDoor(roomInfo, roomDoor, nextRoomInfo, nextRoomDoor))
- // {
- // return true;
- // }
- // }
- // else
- // {
- // //直行通道, 优先横轴
- // if (TryConnectHorizontalDoor(roomInfo, roomDoor, nextRoomInfo, nextRoomDoor)
- // || TryConnectVerticalDoor(roomInfo, roomDoor, nextRoomInfo, nextRoomDoor))
- // {
- // return true;
- // }
- // }
-
+ //先寻找直通门
+ if (Random.RandomBoolean())
+ {
+ //直行通道, 优先纵轴
+ if (TryConnectVerticalDoor(roomInfo, roomDoor, nextRoomInfo, nextRoomDoor)
+ || TryConnectHorizontalDoor(roomInfo, roomDoor, nextRoomInfo, nextRoomDoor))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ //直行通道, 优先横轴
+ if (TryConnectHorizontalDoor(roomInfo, roomDoor, nextRoomInfo, nextRoomDoor)
+ || TryConnectVerticalDoor(roomInfo, roomDoor, nextRoomInfo, nextRoomDoor))
+ {
+ return true;
+ }
+ }
+
//包含1个拐角的通道
return TryConnectCrossDoor(roomInfo, roomDoor, nextRoomInfo, nextRoomDoor);
//包含2个拐角的通道 (后面再开发)
@@ -638,7 +638,9 @@
roomDoor.OriginPosition = new Vector2I(x, roomInfo.GetVerticalDoorEnd());
nextRoomDoor.OriginPosition = new Vector2I(x, nextRoomInfo.GetVerticalDoorStart());
- for (var i = roomInfo.GetVerticalDoorEnd() - 1; i < nextRoomInfo.GetVerticalDoorStart() + 1; i++)
+ var sv = roomInfo.GetVerticalDoorEnd() - 1;
+ var ev = nextRoomInfo.GetVerticalDoorStart() + 1;
+ for (var i = sv; i < ev; i++)
{
floorCell.Add(new Vector2I(x + 1, i));
floorCell.Add(new Vector2I(x + 2, i));
@@ -650,8 +652,10 @@
nextRoomDoor.Direction = DoorDirection.S;
roomDoor.OriginPosition = new Vector2I(x, roomInfo.GetVerticalDoorStart());
nextRoomDoor.OriginPosition = new Vector2I(x, nextRoomInfo.GetVerticalDoorEnd());
-
- for (var i = nextRoomInfo.GetVerticalDoorEnd() - 1; i < roomInfo.GetVerticalDoorStart() + 1; i++)
+
+ var sv = nextRoomInfo.GetVerticalDoorEnd() - 1;
+ var ev = roomInfo.GetVerticalDoorStart() + 1;
+ for (var i = sv; i < ev; i++)
{
floorCell.Add(new Vector2I(x + 1, i));
floorCell.Add(new Vector2I(x + 2, i));
@@ -672,6 +676,8 @@
roomDoor.FloorCell = floorCell;
nextRoomDoor.FloorCell = floorCell;
+ roomDoor.FloorRect = Utils.CalcRect(floorCell);;
+ nextRoomDoor.FloorRect = roomDoor.FloorRect;
return true;
}
}
@@ -708,8 +714,10 @@
nextRoomDoor.Direction = DoorDirection.W;
roomDoor.OriginPosition = new Vector2I(roomInfo.GetHorizontalDoorEnd(), y);
nextRoomDoor.OriginPosition = new Vector2I(nextRoomInfo.GetHorizontalDoorStart(), y);
-
- for (var i = roomInfo.GetHorizontalDoorEnd() - 1; i < nextRoomInfo.GetHorizontalDoorStart() + 1; i++)
+
+ var sv = roomInfo.GetHorizontalDoorEnd() - 1;
+ var ev = nextRoomInfo.GetHorizontalDoorStart() + 1;
+ for (var i = sv; i < ev; i++)
{
floorCell.Add(new Vector2I(i, y + 2));
}
@@ -720,8 +728,10 @@
nextRoomDoor.Direction = DoorDirection.E;
roomDoor.OriginPosition = new Vector2I(roomInfo.GetHorizontalDoorStart(), y);
nextRoomDoor.OriginPosition = new Vector2I(nextRoomInfo.GetHorizontalDoorEnd(), y);
-
- for (var i = nextRoomInfo.GetHorizontalDoorEnd() - 1; i < roomInfo.GetHorizontalDoorStart() + 1; i++)
+
+ var sv = nextRoomInfo.GetHorizontalDoorEnd() - 1;
+ var ev = roomInfo.GetHorizontalDoorStart() + 1;
+ for (var i = sv; i < ev; i++)
{
floorCell.Add(new Vector2I(i, y + 2));
}
@@ -741,6 +751,8 @@
roomDoor.FloorCell = floorCell;
nextRoomDoor.FloorCell = floorCell;
+ roomDoor.FloorRect = Utils.CalcRect(floorCell);;
+ nextRoomDoor.FloorRect = roomDoor.FloorRect;
return true;
}
}
@@ -1022,6 +1034,8 @@
roomDoor.FloorCell = floorCell;
nextRoomDoor.FloorCell = floorCell;
+ roomDoor.FloorRect = Utils.CalcRect(floorCell);
+ nextRoomDoor.FloorRect = roomDoor.FloorRect;
return true;
}
@@ -1063,6 +1077,8 @@
roomDoor.FloorCell = floorCell;
nextRoomDoor.FloorCell = floorCell;
+ roomDoor.FloorRect = Utils.CalcRect(floorCell);
+ nextRoomDoor.FloorRect = roomDoor.FloorRect;
return true;
}
@@ -1105,6 +1121,8 @@
roomDoor.FloorCell = floorCell;
nextRoomDoor.FloorCell = floorCell;
+ roomDoor.FloorRect = Utils.CalcRect(floorCell);
+ nextRoomDoor.FloorRect = roomDoor.FloorRect;
return true;
}
@@ -1147,6 +1165,8 @@
roomDoor.FloorCell = floorCell;
nextRoomDoor.FloorCell = floorCell;
+ roomDoor.FloorRect = Utils.CalcRect(floorCell);
+ nextRoomDoor.FloorRect = roomDoor.FloorRect;
return true;
}
@@ -1189,6 +1209,8 @@
roomDoor.FloorCell = floorCell;
nextRoomDoor.FloorCell = floorCell;
+ roomDoor.FloorRect = Utils.CalcRect(floorCell);
+ nextRoomDoor.FloorRect = roomDoor.FloorRect;
return true;
}
@@ -1231,6 +1253,8 @@
roomDoor.FloorCell = floorCell;
nextRoomDoor.FloorCell = floorCell;
+ roomDoor.FloorRect = Utils.CalcRect(floorCell);
+ nextRoomDoor.FloorRect = roomDoor.FloorRect;
return true;
}
@@ -1273,6 +1297,8 @@
roomDoor.FloorCell = floorCell;
nextRoomDoor.FloorCell = floorCell;
+ roomDoor.FloorRect = Utils.CalcRect(floorCell);
+ nextRoomDoor.FloorRect = roomDoor.FloorRect;
return true;
}
@@ -1315,6 +1341,8 @@
roomDoor.FloorCell = floorCell;
nextRoomDoor.FloorCell = floorCell;
+ roomDoor.FloorRect = Utils.CalcRect(floorCell);
+ nextRoomDoor.FloorRect = roomDoor.FloorRect;
return true;
}
diff --git a/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs b/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs
index 108302c..fdc459f 100644
--- a/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs
+++ b/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs
@@ -174,43 +174,24 @@
if (doorInfo.FloorCell != null)
{
yield return 0;
+
+ //创建image, 这里留两个像素宽高用于描边
+ var image = Image.Create(doorInfo.FloorRect.Size.X, doorInfo.FloorRect.Size.Y, false, Image.Format.Rgba8);
+ //image.Fill(new Color(0, 1, 0, 0.2f));
+ //填充像素点
foreach (var p in doorInfo.FloorCell)
{
- _tileRoot.SetCell(MapLayer.AutoAisleFloorLayer, p, config.Floor.SourceId, config.Floor.AutoTileCoords);
+ //_tileRoot.SetCell(MapLayer.AutoAisleFloorLayer, p, config.Floor.SourceId, config.Floor.AutoTileCoords);
+ _tileRoot.SetCell(MapLayer.CustomTopLayer, p, config.Auto_000_010_000.SourceId, config.Auto_000_010_000.AutoTileCoords);
+ image.SetPixel(p.X - doorInfo.FloorRect.Position.X, p.Y - doorInfo.FloorRect.Position.Y, new Color(1, 1, 1, 0.5882353F));
}
+ //创建texture
+ var imageTexture = ImageTexture.CreateFromImage(image);
+ doorInfo.AislePreviewTexture = imageTexture;
+ doorInfo.ConnectDoor.AislePreviewTexture = imageTexture;
+
+ _tempAisleFloorGrid.Clear();
}
-
- //先计算范围
- var x = int.MaxValue;
- var y = int.MaxValue;
- var x2 = int.MinValue;
- var y2 = int.MinValue;
- _tempAisleFloorGrid.ForEach((gx, gy, data) =>
- {
- x = Mathf.Min(x, gx);
- x2 = Mathf.Max(x2, gx);
- y = Mathf.Min(y, gy);
- y2 = Mathf.Max(y2, gy);
- return true;
- });
- //创建image, 这里留两个像素宽高用于描边
- var image = Image.Create(x2 - x + 3, y2 - y + 3, false, Image.Format.Rgba8);
- //image.Fill(new Color(0, 1, 0, 0.2f));
- //填充像素点
- _tempAisleFloorGrid.ForEach((gx, gy, data) =>
- {
- var posX = gx - x + 1;
- var posY = gy - y + 1;
- //image.SetPixel(posX, posY, new Color(1, 0, 0, 0.5882353F));
- image.SetPixel(posX, posY, new Color(0, 0, 0, 0.5882353F));
- return true;
- });
- //创建texture
- var imageTexture = ImageTexture.CreateFromImage(image);
- doorInfo.AislePreviewTexture = imageTexture;
- doorInfo.ConnectDoor.AislePreviewTexture = imageTexture;
-
- _tempAisleFloorGrid.Clear();
}
}
diff --git a/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs b/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs
index 29a0c87..189b004 100644
--- a/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs
+++ b/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs
@@ -46,7 +46,7 @@
public HashSet FloorCell;
///
- /// 地板所占的矩形, 单位: 格
+ /// 地板所占的矩形, 单位: 格, 使用时不需要加上 OriginPosition
///
public Rect2I FloorRect;
diff --git a/DungeonShooting_Godot/src/game/room/DungeonManager.cs b/DungeonShooting_Godot/src/game/room/DungeonManager.cs
index 9f11cbc..8f7d569 100644
--- a/DungeonShooting_Godot/src/game/room/DungeonManager.cs
+++ b/DungeonShooting_Godot/src/game/room/DungeonManager.cs
@@ -605,96 +605,20 @@
//aisleSprite.Centered = false;
aisleSprite.Texture = doorInfo.AislePreviewTexture;
//调整过道预览位置
-
- if (!doorInfo.HasCross) //不含交叉点
+ if (doorInfo.Direction == DoorDirection.N || doorInfo.Direction == DoorDirection.S ||
+ doorInfo.ConnectDoor.Direction == DoorDirection.N || doorInfo.ConnectDoor.Direction == DoorDirection.S)
{
- if (doorInfo.Direction == DoorDirection.N)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(0, doorInfo.AislePreviewTexture.GetHeight() - 2);
- }
- else if (doorInfo.Direction == DoorDirection.S)
- {
- aisleSprite.Position = doorInfo.OriginPosition;
- }
- else if (doorInfo.Direction == DoorDirection.E)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(1, -1);
- }
- else if (doorInfo.Direction == DoorDirection.W)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(doorInfo.AislePreviewTexture.GetWidth() - 1, -1);
- }
+ aisleSprite.Position = doorInfo.FloorRect.Position + new Vector2I(0, 1);
}
- else //包含交叉点
+ else
{
- if (doorInfo.Direction == DoorDirection.S)
- {
- if (doorInfo.ConnectDoor.Direction == DoorDirection.E)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(doorInfo.AislePreviewTexture.GetWidth() - 4, 1);
- }
- else if (doorInfo.ConnectDoor.Direction == DoorDirection.W)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(0, 1);
- }
- else
- {
- aisleSprite.Position = doorInfo.OriginPosition;
- }
- }
- else if (doorInfo.Direction == DoorDirection.N)
- {
- if (doorInfo.ConnectDoor.Direction == DoorDirection.W)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(0, doorInfo.AislePreviewTexture.GetHeight() - 1);
- }
- else if (doorInfo.ConnectDoor.Direction == DoorDirection.E)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(doorInfo.AislePreviewTexture.GetWidth() - 4, doorInfo.AislePreviewTexture.GetHeight() - 1);
- }
- else
- {
- aisleSprite.Position = doorInfo.OriginPosition;
- }
- }
- else if (doorInfo.Direction == DoorDirection.W)
- {
- if (doorInfo.ConnectDoor.Direction == DoorDirection.N)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(doorInfo.AislePreviewTexture.GetWidth() - 1, 0);
- }
- else if (doorInfo.ConnectDoor.Direction == DoorDirection.S)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(doorInfo.AislePreviewTexture.GetWidth() - 1, doorInfo.AislePreviewTexture.GetHeight() - 4);
- }
- else
- {
- aisleSprite.Position = doorInfo.OriginPosition;
- }
- }
- else if (doorInfo.Direction == DoorDirection.E)
- {
- if (doorInfo.ConnectDoor.Direction == DoorDirection.S)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(1, doorInfo.AislePreviewTexture.GetHeight() - 4);
- }
- else if (doorInfo.ConnectDoor.Direction == DoorDirection.N)
- {
- aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(1, 0);
- }
- else
- {
- aisleSprite.Position = doorInfo.OriginPosition;
- }
- }
-
- aisleSprite.Position += new Vector2(0, 1);
+ aisleSprite.Position = doorInfo.FloorRect.Position;
}
- var aisleSpriteMaterial = ResourceManager.Load(ResourcePath.resource_material_Outline2_tres, false);
- aisleSpriteMaterial.SetShaderParameter("outline_color", new Color(1, 1, 1, 0.9f));
- aisleSpriteMaterial.SetShaderParameter("scale", 0.5f);
- aisleSprite.Material = aisleSpriteMaterial;
+ // var aisleSpriteMaterial = ResourceManager.Load(ResourcePath.resource_material_Outline2_tres, false);
+ // aisleSpriteMaterial.SetShaderParameter("outline_color", new Color(1, 1, 1, 0.9f));
+ // aisleSpriteMaterial.SetShaderParameter("scale", 0.5f);
+ // aisleSprite.Material = aisleSpriteMaterial;
doorInfo.AislePreviewSprite = aisleSprite;
doorInfo.ConnectDoor.AislePreviewSprite = aisleSprite;
}