/*public bool IsIsolated(Room room) { //DOESN'T WORK WITH ROOMS INSIDE OTHER ROOMS Room tempRoom = new Room(controller, this, new Point(room.cornerNW.X - 1, room.cornerNW.Y - 1), new Point(room.cornerSE.X, room.cornerSE.Y)); Point tempPoint = new Point(0, 0); Point corner1 = new Point(tempRoom.cornerSE.X, tempRoom.cornerNW.Y); Point corner2 = new Point(tempRoom.cornerNW.X, tempRoom.cornerSE.Y); for (int ix = tempRoom.cornerNW.X; ix < tempRoom.cornerSE.X + 1; ix++) { for (int iy = tempRoom.cornerNW.Y; iy < tempRoom.cornerSE.Y + 1; iy++) { tempPoint.X = ix; tempPoint.Y = iy; if (OutOfBounds(tempPoint)) { continue; } if (mapArray[ix, iy] == 0 && !room.ContainsPoint(tempPoint)) { if (tempPoint != tempRoom.cornerNW && tempPoint != tempRoom.cornerSE && tempPoint != corner1 && tempPoint != corner2) { return false; } } } } return true; }*/ public bool IsIsolated(Room room) { foreach (Room r in roomList) { if (room.Intersects(r) && r != room) { return false; } } return true; }
public void CreateRandomLevel(int numberOfRooms, int roomSizeX, int roomSizeY, int maxRoomSizeX, int maxRoomSizeY) { this.player = controller.player; ResetFloorVars(); while (roomList.Count == 0 || !CheckIfAllConnected(roomList)) { ResetFloorVars(); //CREATE BIG ROOMS for (int i = 0; i < numberOfRooms; i++) { GenerateRandomIsolatedRoom(roomSizeX, roomSizeY, maxRoomSizeX, maxRoomSizeY); } //CORRIDORS for (int i = 0; i < roomList.Count; i++) { Room tempRoom; int x1, x2, y1, y2; for (int i2 = 0; i2 < roomList.Count; i2++) { if (roomList[i].cornerNW.X <= roomList[i2].cornerNW.X) { x1 = roomList[i].cornerNW.X; x2 = roomList[i2].cornerSE.X; } else { x1 = roomList[i2].cornerNW.X; x2 = roomList[i].cornerSE.X; } tempRoom = new Room(controller, this, new Point(x1, roomList[i].cornerNW.Y), new Point(x2, roomList[i].cornerNW.Y + 1)); if (roomList[i2] != roomList[i]) { if (tempRoom.Intersects(roomList[i2])) { GenerateRoom(tempRoom.cornerNW, tempRoom.cornerSE); break; } } } for (int i2 = 0; i2 < roomList.Count; i2++) { if (roomList[i].cornerNW.Y <= roomList[i2].cornerNW.Y) { y1 = roomList[i].cornerNW.Y; y2 = roomList[i2].cornerSE.Y; } else { y1 = roomList[i2].cornerNW.Y; y2 = roomList[i].cornerSE.Y; } tempRoom = new Room(controller, this, new Point(roomList[i].cornerNW.X, y1), new Point(roomList[i].cornerNW.X + 1, y2)); if (tempRoom.Intersects(roomList[i2]) && roomList[i2] != roomList[i] /*&& IsIsolated(rm)*/) { GenerateRoom(tempRoom.cornerNW, tempRoom.cornerSE); break; } } } //ELIMINATE ISOLATED ROOMS for (int i = roomList.Count - 1; i > -1; i--) { if (IsIsolated(roomList[i]) && roomList.Count > 0) { for (int ix = roomList[i].cornerNW.X; ix < roomList[i].cornerSE.X; ix++) { for (int iy = roomList[i].cornerNW.Y; iy < roomList[i].cornerSE.Y; iy++) { mapArray[ix, iy] = (int)Element.Wall; } } for (int ib = bigRoomList.Count - 1; ib > -1; ib--) { if (bigRoomList[ib] == roomList[i]) { bigRoomList.RemoveAt(ib); break; } } roomList.RemoveAt(i); } } } //MAKE DOORS foreach (Room r in roomList) { CheckForDoors(r); } //STAIRS bool posInBig; Point stairs; do { posInBig = false; stairs = GenerateFreePos(); foreach (Room r in bigRoomList) { if (r.ContainsPoint(stairs)) { posInBig = true; break; } } } while (!posInBig); mapArray[stairs.X, stairs.Y] = (int)Element.Stairs; //PLAYER do { posInBig = false; player.position = GenerateFreePos(); foreach (Room r in bigRoomList) { if (r.ContainsPoint(player.position)) { posInBig = true; break; } } } while (!posInBig); //GENERATING ITEMS Point temp; bool overlap = false; for (int i = 0; i < bigRoomList.Count; i++) { overlap = false; temp = GenerateFreePos(); foreach (Item it in itemList) { if (temp == it.position) { overlap = true; } } if (temp != Point.Zero && temp != player.position && !overlap) { itemList.Add(new Item(controller, temp, (Map.Element)mapArray[temp.X, temp.Y])); mapArray[temp.X, temp.Y] = (int)Element.Item; } } //ENEMIES overlap = false; for (int i = 0; i < bigRoomList.Count + (int)controller.level / 10; i++) { overlap = false; temp = GenerateFreePos(); foreach (Enemy e in enemyList) { if (temp == e.position) { overlap = true; } } if (temp != Point.Zero && temp != player.position && !overlap) { Type t = typeof(Enemy.EnemyType); enemyList.Add(new Enemy(controller, temp, (Enemy.EnemyType)controller.random.Next(Enum.GetValues(t).Length))); } } mapString = ArrayToString(mapArray); controller.camera.ResetPosition(); GenerateFog(); GenerateMinimapFog(); }