diff --git a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs index fb2a11c..a8e5533 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonGenerator.cs @@ -63,8 +63,8 @@ //区域限制 private bool _enableLimitRange = true; - private int _rangeX = 150; - private int _rangeY = 150; + private int _rangeX = 120; + private int _rangeY = 120; //找房间失败次数, 过大则会关闭区域限制 private int _maxFailCount = 10; diff --git a/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs b/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs index f61a230..f283ca9 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonTileMap.cs @@ -28,6 +28,8 @@ //生成导航的结果 private GenerateNavigationResult _generateNavigationResult; + private InfiniteGrid _tempAisleFloorGrid = new InfiniteGrid(); + public DungeonTileMap(TileMap tileRoot) { _tileRoot = tileRoot; @@ -160,8 +162,7 @@ preinstallInfo = roomInfo.RoomSplit.Preinstall[index]; } } - - + var roomPreinstall = new RoomPreinstall(roomInfo, preinstallInfo); roomInfo.RoomPreinstall = roomPreinstall; //执行预处理操作 @@ -176,6 +177,7 @@ { continue; } + //普通的直线连接 var doorDir1 = doorInfo.Direction; var doorDir2 = doorInfo.ConnectDoor.Direction; @@ -367,6 +369,34 @@ break; } } + + //先计算范围 + 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); + }); + //创建image, 这里留两个像素宽高用于描边 + var image = Image.Create(x2 - x + 3, y2 - y + 3, false, Image.Format.Rgba8); + //填充像素点 + _tempAisleFloorGrid.ForEach((gx, gy, data) => + { + var posX = gx - x + 1; + var posY = gy - y + 1; + image.SetPixel(posX, posY, new Color(0, 0, 0, 0.5882353F)); + }); + //创建texture + var imageTexture = ImageTexture.CreateFromImage(image); + doorInfo.AislePreviewTexture = imageTexture; + doorInfo.ConnectDoor.AislePreviewTexture = imageTexture; + + _tempAisleFloorGrid.Clear(); } } @@ -454,7 +484,12 @@ { for (int j = 0; j < size.Y; j++) { - _tileRoot.SetCell(layer, new Vector2I((int)pos.X + i, (int)pos.Y + j), 0, info.AutoTileCoord); + var p = new Vector2I((int)pos.X + i, (int)pos.Y + j); + if (layer == GameConfig.AisleFloorMapLayer) + { + _tempAisleFloorGrid.Set(p, true); + } + _tileRoot.SetCell(layer, p, 0, info.AutoTileCoord); } } } @@ -466,7 +501,12 @@ { for (int j = 0; j < size.Y; j++) { - _tileRoot.SetCell(layer, new Vector2I((int)pos.X + i, (int)pos.Y + j), 0); + var p = new Vector2I((int)pos.X + i, (int)pos.Y + j); + if (layer == GameConfig.AisleFloorMapLayer) + { + _tempAisleFloorGrid.Remove(p.X, p.Y); + } + _tileRoot.SetCell(layer, p, 0); } } } diff --git a/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs b/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs index f14e276..f30411f 100644 --- a/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs +++ b/DungeonShooting_Godot/src/framework/map/room/RoomDoorInfo.cs @@ -55,11 +55,16 @@ public DoorNavigationInfo Navigation; /// - /// 连接的过使用的导航网格 + /// 连接过道使用的导航网格 /// public NavigationPolygonData AisleNavigation; /// + /// 连接过道使用预览纹理 + /// + public ImageTexture AislePreviewTexture; + + /// /// 门实例 /// public RoomDoor Door; @@ -278,5 +283,10 @@ { PreviewAisleFogMask.Destroy(); } + + if (AislePreviewTexture != null) + { + AislePreviewTexture.Dispose(); + } } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/ui/roomMap/RoomMapPanel.cs b/DungeonShooting_Godot/src/game/ui/roomMap/RoomMapPanel.cs index 587ae83..5329297 100644 --- a/DungeonShooting_Godot/src/game/ui/roomMap/RoomMapPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/roomMap/RoomMapPanel.cs @@ -37,6 +37,7 @@ var startRoom = GameApplication.Instance.DungeonManager.StartRoomInfo; startRoom.EachRoom(roomInfo => { + //房间区域 var sprite = new Sprite2D(); sprite.Centered = false; sprite.Texture = roomInfo.PreviewTexture; @@ -46,40 +47,102 @@ material.SetShaderParameter("scale", 0.5f); sprite.Material = material; S_Root.AddChild(sprite); - // //房间区域 - // var navigationPolygonData = roomInfo.RoomSplit.TileInfo.NavigationList[0]; - // var points = navigationPolygonData.GetPoints(); - // var newPoints = new Vector2[points.Length]; - // for (var i = 0; i < points.Length; i++) - // { - // newPoints[i] = roomInfo.ToGlobalPosition(points[i]); - // } - // - // var outline = new PolygonOutline(); - // outline.SetPoints(newPoints); - // S_Root.AddChild(outline); - // - // //过道 - // if (roomInfo.Doors != null) - // { - // foreach (var doorInfo in roomInfo.Doors) - // { - // if (doorInfo.IsForward) - // { - // var aislePoints = doorInfo.AisleNavigation.GetPoints(); - // // var newAislePoints = new Vector2[aislePoints.Length]; - // // for (var i = 0; i < aislePoints.Length; i++) - // // { - // // newAislePoints[i] = roomInfo.ToGlobalPosition(aislePoints[i]); - // // } - // - // var aisleOutline = new PolygonOutline(); - // aisleOutline.SetPoints(aislePoints); - // S_Root.AddChild(aisleOutline); - // } - // } - // } - // //roomInfo.Doors[0].Navigation.OpenNavigationData + + //过道 + if (roomInfo.Doors != null) + { + foreach (var doorInfo in roomInfo.Doors) + { + if (doorInfo.IsForward) + { + var aisleSprite = new Sprite2D(); + aisleSprite.Centered = false; + aisleSprite.Texture = doorInfo.AislePreviewTexture; + //调整过道预览位置 + + if (!doorInfo.HasCross) //不含交叉点 + { + if (doorInfo.Direction == DoorDirection.N) + { + aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(0, doorInfo.AislePreviewTexture.GetHeight() - 1); + } + else if (doorInfo.Direction == DoorDirection.S) + { + aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(0, 1); + } + else if (doorInfo.Direction == DoorDirection.E) + { + aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(1, 0); + } + else if (doorInfo.Direction == DoorDirection.W) + { + aisleSprite.Position = doorInfo.OriginPosition - new Vector2I(doorInfo.AislePreviewTexture.GetWidth() - 1, 0); + } + } + 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 + { + 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 + { + 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; + } + } + } + + var aisleSpriteMaterial = ResourceManager.Load(ResourcePath.resource_material_Outline2_tres); + aisleSpriteMaterial.SetShaderParameter("outline_color", new Color(1, 1, 1, 0.9f)); + aisleSpriteMaterial.SetShaderParameter("scale", 0.5f); + aisleSprite.Material = aisleSpriteMaterial; + S_Root.AddChild(aisleSprite); + } + } + } }); }