diff --git a/DungeonShooting_Godot/resource/map/RoomConfig.json b/DungeonShooting_Godot/resource/map/RoomConfig.json index e5c9d13..8f2f2a3 100644 --- a/DungeonShooting_Godot/resource/map/RoomConfig.json +++ b/DungeonShooting_Godot/resource/map/RoomConfig.json @@ -28,14 +28,14 @@ "End": 128 }, { - "Direction": 0, + "Direction": 1, "Start": 16, "End": 128 }, { - "Direction": 1, - "Start": 16, - "End": 128 + "Direction": 2, + "Start": 208, + "End": 320 }, { "Direction": 3, @@ -44,11 +44,11 @@ }, { "Direction": 0, - "Start": 208, - "End": 320 + "Start": 16, + "End": 128 }, { - "Direction": 2, + "Direction": 0, "Start": 208, "End": 320 } diff --git a/DungeonShooting_Godot/resource/map/tiledata/Room3.json b/DungeonShooting_Godot/resource/map/tiledata/Room3.json index 5a3fd83..ed98615 100644 --- a/DungeonShooting_Godot/resource/map/tiledata/Room3.json +++ b/DungeonShooting_Godot/resource/map/tiledata/Room3.json @@ -24,14 +24,14 @@ "End": 128 }, { - "Direction": 0, + "Direction": 1, "Start": 16, "End": 128 }, { - "Direction": 1, - "Start": 16, - "End": 128 + "Direction": 2, + "Start": 208, + "End": 320 }, { "Direction": 3, @@ -40,11 +40,11 @@ }, { "Direction": 0, - "Start": 208, - "End": 320 + "Start": 16, + "End": 128 }, { - "Direction": 2, + "Direction": 0, "Start": 208, "End": 320 } diff --git a/DungeonShooting_Godot/src/framework/common/Utils.cs b/DungeonShooting_Godot/src/framework/common/Utils.cs index 31c9455..3b06941 100644 --- a/DungeonShooting_Godot/src/framework/common/Utils.cs +++ b/DungeonShooting_Godot/src/framework/common/Utils.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Godot; @@ -7,12 +8,19 @@ public static class Utils { + private static readonly Random _random; + + static Utils() + { + _random = new Random(); + } + /// /// 返回随机 boolean 值 /// public static bool RandomBoolean() { - return GD.Randf() >= 0.5f; + return _random.NextSingle() >= 0.5f; } /// @@ -22,8 +30,8 @@ { if (min == max) return min; if (min > max) - return GD.Randf() * (min - max) + max; - return GD.Randf() * (max - min) + min; + return _random.NextSingle() * (min - max) + max; + return _random.NextSingle() * (max - min) + min; } /// @@ -33,8 +41,8 @@ { if (min == max) return min; if (min > max) - return Mathf.FloorToInt(GD.Randf() * (min - max + 1) + max); - return Mathf.FloorToInt(GD.Randf() * (max - min + 1) + min); + return Mathf.FloorToInt(_random.NextSingle() * (min - max + 1) + max); + return Mathf.FloorToInt(_random.NextSingle() * (max - min + 1) + min); } /// diff --git a/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs b/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs index 96e2387..752bb51 100644 --- a/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs +++ b/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs @@ -529,66 +529,74 @@ { if (areaInfo.Direction == DoorDirection.N || areaInfo.Direction == DoorDirection.S) //纵向门 { - var num = room1.GetHorizontalStart() * TileCellSize; - var p1 = num + areaInfo.Start; - var p2 = num + areaInfo.End; + var num = room1.GetHorizontalStart(); + var p1 = num + areaInfo.Start / TileCellSize; + var p2 = num + areaInfo.End / TileCellSize; if (room1.Position.X > room2.Position.X) { - var range = CalcOverlapRange(room2.GetHorizontalEnd() * TileCellSize, - room1.GetHorizontalEnd() * TileCellSize, p1, p2); + var range = CalcOverlapRange(room2.GetHorizontalEnd(), + room1.GetHorizontalEnd(), p1, p2); //交集范围够生成门 - if (range.Y - range.X >= CorridorWidth * TileCellSize) + if (range.Y - range.X >= CorridorWidth) { - if (areaRange == null || range.X < areaRange.Value.X) + var tempRange = new Vector2I(Mathf.Abs(room1.Position.X - (int)range.X), + Mathf.Abs(room1.Position.X - (int)range.Y) - CorridorWidth); + if (areaRange == null || tempRange.X < areaRange.Value.X) { - areaRange = new Vector2I(Mathf.Abs(room1.Position.X - (int)(range.X / 16)), Mathf.Abs(room1.Position.X - (int)(range.Y / 16)) - CorridorWidth); + areaRange = tempRange; } } } else { - var range = CalcOverlapRange(room1.GetHorizontalStart() * TileCellSize, - room2.GetHorizontalStart() * TileCellSize, p1, p2); + var range = CalcOverlapRange(room1.GetHorizontalStart(), + room2.GetHorizontalStart(), p1, p2); //交集范围够生成门 - if (range.Y - range.X >= CorridorWidth * TileCellSize) + if (range.Y - range.X >= CorridorWidth) { - if (areaRange == null || range.Y > areaRange.Value.Y) + var tempRange = new Vector2I(Mathf.Abs(room1.Position.X - (int)range.X), + Mathf.Abs(room1.Position.X - (int)range.Y) - CorridorWidth); + if (areaRange == null || tempRange.Y > areaRange.Value.Y) { - areaRange = new Vector2I(Mathf.Abs(room1.Position.X - (int)(range.X / 16)), Mathf.Abs(room1.Position.X - (int)(range.Y / 16)) - CorridorWidth); + areaRange = tempRange; } } } } else //横向门 { - var num = room1.GetVerticalStart() * TileCellSize; - var p1 = num + areaInfo.Start; - var p2 = num + areaInfo.End; + var num = room1.GetVerticalStart(); + var p1 = num + areaInfo.Start / TileCellSize; + var p2 = num + areaInfo.End / TileCellSize; if (room1.Position.Y > room2.Position.Y) { - var range = CalcOverlapRange(room2.GetVerticalEnd() * TileCellSize, - room1.GetVerticalEnd() * TileCellSize, p1, p2); + var range = CalcOverlapRange(room2.GetVerticalEnd(), + room1.GetVerticalEnd(), p1, p2); //交集范围够生成门 - if (range.Y - range.X >= CorridorWidth * TileCellSize) + if (range.Y - range.X >= CorridorWidth) { - if (areaRange == null || range.X < areaRange.Value.X) + var tempRange = new Vector2I(Mathf.Abs(room1.Position.Y - (int)range.X), + Mathf.Abs(room1.Position.Y - (int)range.Y) - CorridorWidth); + if (areaRange == null || tempRange.X < areaRange.Value.X) { - areaRange = new Vector2I(Mathf.Abs(room1.Position.Y - (int)(range.X / 16)), Mathf.Abs(room1.Position.Y - (int)(range.Y / 16)) - CorridorWidth); + areaRange = tempRange; } } } else { - var range = CalcOverlapRange(room1.GetVerticalStart() * TileCellSize, - room2.GetVerticalStart() * TileCellSize, p1, p2); + var range = CalcOverlapRange(room1.GetVerticalStart(), + room2.GetVerticalStart(), p1, p2); //交集范围够生成门 - if (range.Y - range.X >= CorridorWidth * TileCellSize) + if (range.Y - range.X >= CorridorWidth) { - if (areaRange == null || range.Y > areaRange.Value.Y) + var tempRange = new Vector2I(Mathf.Abs(room1.Position.Y - (int)range.X), + Mathf.Abs(room1.Position.Y - (int)range.Y) - CorridorWidth); + if (areaRange == null || tempRange.Y > areaRange.Value.Y) { - areaRange = new Vector2I(Mathf.Abs(room1.Position.Y - (int)(range.X / 16)), Mathf.Abs(room1.Position.Y - (int)(range.Y / 16)) - CorridorWidth); + areaRange = tempRange; } } } @@ -616,6 +624,7 @@ private bool TryConnect_WS_Door(RoomInfo room, RoomInfo nextRoom, RoomDoorInfo roomDoor, RoomDoorInfo nextRoomDoor, ref Vector2 cross) { + //ok var offset1 = 0; var offset2 = 0; roomDoor.Direction = DoorDirection.W; //← @@ -626,9 +635,8 @@ return false; } - roomDoor.OriginPosition = new Vector2(room.GetHorizontalStart(), room.GetVerticalStart() + offset2); - nextRoomDoor.OriginPosition = new Vector2(nextRoom.GetHorizontalStart() + offset1, - nextRoom.GetVerticalEnd()); + roomDoor.OriginPosition = new Vector2(room.GetHorizontalStart(), room.GetVerticalStart() + offset1); + nextRoomDoor.OriginPosition = new Vector2(nextRoom.GetHorizontalStart() + offset2, nextRoom.GetVerticalEnd()); cross = new Vector2(nextRoomDoor.OriginPosition.X, roomDoor.OriginPosition.Y); return true; } @@ -665,7 +673,7 @@ } roomDoor.OriginPosition = - new Vector2(room.GetHorizontalStart(), room.GetVerticalStart() + offset2); // + new Vector2(room.GetHorizontalStart(), room.GetVerticalStart() + offset1); // nextRoomDoor.OriginPosition = new Vector2(nextRoom.GetHorizontalStart() + offset2, nextRoom.GetVerticalStart()); cross = new Vector2(nextRoomDoor.OriginPosition.X, roomDoor.OriginPosition.Y); @@ -684,8 +692,8 @@ return false; } - roomDoor.OriginPosition = new Vector2(room.GetHorizontalEnd(), room.GetVerticalStart() + offset2); - nextRoomDoor.OriginPosition = new Vector2(nextRoom.GetHorizontalStart() + offset1, + roomDoor.OriginPosition = new Vector2(room.GetHorizontalEnd(), room.GetVerticalStart() + offset1); + nextRoomDoor.OriginPosition = new Vector2(nextRoom.GetHorizontalStart() + offset2, nextRoom.GetVerticalEnd()); cross = new Vector2(nextRoomDoor.OriginPosition.X, roomDoor.OriginPosition.Y); return true; @@ -723,8 +731,8 @@ } roomDoor.OriginPosition = new Vector2(room.GetHorizontalEnd(), - room.GetVerticalStart() + offset2); - nextRoomDoor.OriginPosition = new Vector2(nextRoom.GetHorizontalStart() + offset1, nextRoom.GetVerticalStart()); + room.GetVerticalStart() + offset1); + nextRoomDoor.OriginPosition = new Vector2(nextRoom.GetHorizontalStart() + offset2, nextRoom.GetVerticalStart()); cross = new Vector2(nextRoomDoor.OriginPosition.X, roomDoor.OriginPosition.Y); return true; } diff --git a/DungeonShooting_Godot/src/game/GameApplication.cs b/DungeonShooting_Godot/src/game/GameApplication.cs index f50a3c6..9b908ac 100644 --- a/DungeonShooting_Godot/src/game/GameApplication.cs +++ b/DungeonShooting_Godot/src/game/GameApplication.cs @@ -78,7 +78,7 @@ public override void _EnterTree() { //随机化种子 - GD.Randomize(); + //GD.Randomize(); //固定帧率 Engine.MaxFps = 60; //调试绘制开关