public World GenerateGoodDungeon() { int roomGenerationRadius = 30; Int2 roomSize; Vector2 roomPoint; Collections.allRooms = new List <Room>(); for (int i = 0; i < 150; i++) { roomSize = new Int2((int)Utilities.NormalizedRandom(18, 48), (int)Utilities.NormalizedRandom(12, 36)); roomPoint = Utilities.RandomPointInCircle(roomGenerationRadius); Collections.allRooms.Add(new Room(roomPoint, roomSize)); } for (int i = 0; i < 5; i++) { SeparateRooms(); } int roomCount = Collections.allRooms.Count; for (int i = 0; i < roomCount; i++) { for (int j = i + 1; j < roomCount; j++) { if (Collections.allRooms[i] == null || Collections.allRooms[j] == null) { continue; } if (Collections.allRooms[i].TooCloseTo(Collections.allRooms[j])) { Collections.allRooms[i] = null; } } } Collections.allRooms.RemoveAll(room => room == null); Collections.allRooms.RemoveAll(room => room.size.x < 24 || room.size.y < 16); int minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue; foreach (Room room in Collections.allRooms) { if (room.position.x < minX) { minX = (int)room.position.x; } if (room.position.y < minY) { minY = (int)room.position.y; } if (room.position.x > maxX) { maxX = (int)room.position.x; } if (room.position.y > maxY) { maxY = (int)room.position.y; } } int border = 128; int width = maxX - minX + 2 * border; int height = maxY - minY + 2 * border; Int2 offset = new Int2(width / 2, height / 2); World newWorld = new World("Dungeon", width, height); world = newWorld; Collections.allRooms.ForEach(x => x.position += offset.ToVector2()); Collections.allRooms = Collections.allRooms.OrderBy(point => point.position.x).ToList(); Triangle superTriangle = Delaunay.SuperTriangle(Collections.allRooms); List <Triangle> delauneyTriangles = Delaunay.Triangulate(superTriangle, Collections.allRooms); List <DelaunayEdge> delaunayEdges = Delaunay.DelaunayEdges(superTriangle, delauneyTriangles); Graph <int> W = new Graph <int>(Enumerable.Range(0, delaunayEdges.Count)); foreach (DelaunayEdge edge in delaunayEdges) { W.SetEdge(edge.start, edge.end, (int)Mathf.Sqrt( (Collections.allRooms[edge.start].position.x - Collections.allRooms[edge.end].position.x) * (Collections.allRooms[edge.start].position.x - Collections.allRooms[edge.end].position.x) + (Collections.allRooms[edge.start].position.y - Collections.allRooms[edge.end].position.y) * (Collections.allRooms[edge.start].position.y - Collections.allRooms[edge.end].position.y))); } Prim <int> prim = new Prim <int>(); Dictionary <Graph <int> .Node, Graph <int> .Node> tree = new Dictionary <Graph <int> .Node, Graph <int> .Node>(); prim.prim(W, W.FindVertex(0), ref tree); Tile tile = new Tile(12); StaticWorld(tile, tile); foreach (Room room in Collections.allRooms) { Rectangle((int)(room.position.x - room.size.x / 2f), (int)(room.position.y - room.size.y / 2f), room.size.x, room.size.y); } foreach (KeyValuePair <Graph <int> .Node, Graph <int> .Node> kv in tree) { //Debug.DrawLine(Collections.allRooms[kv.Key.context].position, //Collections.allRooms[kv.Value.context].position, Color.red, 100f); Int2 startPoint = new Int2((int)Collections.allRooms[kv.Key.context].position.x, (int)Collections.allRooms[kv.Key.context].position.y); Int2 endPoint = new Int2((int)Collections.allRooms[kv.Value.context].position.x, (int)Collections.allRooms[kv.Value.context].position.y); Hallway(startPoint, endPoint); } return(newWorld); }