/// <summary> /// Generates specific values for the DungeonType. /// </summary> /// <param name="room">The current room.</param> /// <param name="dungeonRoomObject">The gameobject to which the room should be generate don.</param> /// <param name="levelNumber">The number of the level.</param> /// <returns>The fully generated DungeonRoom.</returns> private DungeonRoom SetRoomType(Room room, GameObject dungeonRoomObject, int levelNumber, DungeonConfig config) { switch (room.Type) { case RoomType.Start: StartRoom startRoom = dungeonRoomObject.AddComponent <StartRoom>(); if (Player.LocalPlayer.isServer && levelNumber == 0) { startRoom.SpawnItems(RegionDict.Instance.StartingRoomPickables, DungeonCreator.Instance.TilePositionToWorldPosition(room.Position + (room.Layout.Size / 2))); } return(startRoom); case RoomType.Combat: CombatRoom combatRoom = dungeonRoomObject.AddComponent <CombatRoom>(); combatRoom.ThreatLevel = room.TileCount; combatRoom.enemiesToSpawn = new EnemyObject[combatRoom.ThreatLevel / 48]; for (int j = 0; j < combatRoom.enemiesToSpawn.Length; j++) { combatRoom.enemiesToSpawn[j] = RandomUtil.Element(RegionDict.Instance.EnemiesToSpawn); } return(combatRoom); case RoomType.Loot: LootRoom lootRoom = dungeonRoomObject.AddComponent <LootRoom>(); lootRoom.pickables = new Pickable[room.TileCount / 48]; for (int j = 0; j < lootRoom.pickables.Length; j++) { lootRoom.pickables[j] = RandomUtil.Element(RegionDict.Instance.LootingRoomPickables); } return(lootRoom); case RoomType.Shop: ShopRoom shopRoom = dungeonRoomObject.AddComponent <ShopRoom>(); const int numItems = 4; shopRoom.shopItems = new Pickable[numItems]; shopRoom.locations = new Vector2[numItems]; // TODO: Replace Pickabledict with dungeon config shop pickables. for (int j = 0; j < numItems; j++) { int rnd = Random.Range(0, config.shopItems.Length); shopRoom.shopItems[j] = config.shopItems[rnd]; shopRoom.locations[j] = room.Position + new Vector2Int((int)room.GameObjects[j + 4].Position.x, (int)room.GameObjects[j + 4].Position.y); } shopRoom.SpawnItems(); return(shopRoom); case RoomType.Boss: BossRoom bossRoom = dungeonRoomObject.AddComponent <BossRoom>(); bossRoom.bossObjects = new BossObject[] { RandomUtil.Element(RegionDict.Instance.BossesToSpawn) }; DungeonDict.Instance.SetBossRoom(bossRoom); return(bossRoom); case RoomType.Empty: EmptyRoom emptyRoom = dungeonRoomObject.AddComponent <EmptyRoom>(); return(emptyRoom); default: throw new System.Exception("Unknown room type! (" + room.Type + ")"); } }
private void Awake() { room = this; cachedRoomList = new Dictionary <string, RoomInfo>(); roomListEntries = new Dictionary <string, GameObject>(); PhotonNetwork.AutomaticallySyncScene = true; }
private void PlaceStartRoom() { startRoom = Instantiate(startRoomPrefab) as StartRoom; startRoom.transform.SetParent(transform); AddDoorwaysToList(startRoom, ref availableDoorways); startRoom.transform.position = Vector3.zero; startRoom.transform.rotation = Quaternion.identity; }
protected override void Awake() { base.Awake(); //_character.gameObject.SetActive(false); CurrentRoomID = -1; GameObject startRoomObj = Instantiate(_startRoomPrefab, _levelGrid.transform); startRoomObj.transform.position = _offScreenPosition; StartRoom = startRoomObj.GetComponent <StartingRoom>(); StartRoom.Setup(); }
void PlaceStartRoom() { //instanticate room startRoom = Instantiate(startRoomPrefab) as StartRoom; startRoom.transform.parent = this.transform; //get doorways from current room and add the randomly to the list of availible dorways AddDorwaysToList(startRoom, ref availableDoorways); //position room startRoom.transform.position = Vector3.zero; startRoom.transform.rotation = Quaternion.identity; }
void PlaceStartRoom() { // Instantiate room startRoom = Instantiate(startRoomPrefab) as StartRoom; startRoom.transform.parent = this.transform; // Get doorways from current room and add them randomly to the list of available doorways AddDoorwaysToList(startRoom, ref availableDoorways); // Position room startRoom.transform.position = new Vector3(0.0f, yOffSet, 0.0f); startRoom.transform.rotation = Quaternion.identity; }
/// <summary> /// This function instantiate start room /// </summary> private void PlaceStartRoom() { Debug.Log("Place start room"); // Instantiate start room _startRoom = Instantiate(startRoomPrefab, transform) as StartRoom; // Get doorways from current room and add them randomly to the list of available doorways AddDoorwaysToList(_startRoom, ref _availableDoorways); // Position room _startRoom.transform.position = Vector3.zero; _startRoom.transform.rotation = Quaternion.identity; }
void PlaceStartRoom() { // Instantiate room startRoom = Instantiate(startRoomPrefab) as StartRoom; startRoom.transform.parent = this.transform; // Get doorways from current room and add them randomly to // a list of available doorways AddDoorwayToList(startRoom, ref allAvailableDoorways); // Position the room startRoom.transform.position = Vector3.zero; startRoom.transform.rotation = Quaternion.identity; StartCoroutine(ConnectorPlacement()); }
void PlaceStartRoom() { //Instantiate room startRoom = Instantiate(startRoomPrefab) as StartRoom; startRoom.transform.parent = this.transform; //Get doorways from current room and add them randomly to the list of available doorways AddDoorwaysToList(startRoom, ref availableDoorways); //Position room startRoom.transform.position = Vector3.zero; startRoom.transform.rotation = Quaternion.identity; for (int i = 0; i < startRoom.gameObject.transform.childCount; i++) { Track track = startRoom.gameObject.transform.GetChild(i).GetComponent <Track>(); if (prevTrack != null) { prevTrack.NextTrack = track; track.PrevTrack = prevTrack; } prevTrack = track; } }
public PlanetData Generate(float difficultySetting) { PlanetData data = new PlanetData(); PlanetDifficultyModifiers difficultyModifiers = new PlanetDifficultyModifiers(difficultySetting); DungeonRoom currentRoom = null; int keyLevel = 1; //rule 1 - Create starter room DungeonRoom startRoom = new StartRoom(IntPair.zero, null); data.AddRoom(startRoom); data.startRoom = startRoom; //rule 2 - "Current Room" is starter room currentRoom = data.startRoom; //rule 7 - Repeat steps 3 - 6 Y amount of times. int branchCount = Mathf.Max(1, Random.Range( difficultyModifiers.minBranchCount, PlanetDifficultyModifiers.MAX_BRANCH_COUNT)); for (int j = 0; j < branchCount; j++) { //rule 3 - Create a single branch from the "Current room" until X rooms have been // created. Branch can't overlap with existing rooms. If branch meets a dead // end, end the branch. int branchLength = Mathf.Max(1, Random.Range(difficultyModifiers.minBranchLength, difficultyModifiers.maxBranchLength)); for (int i = 0; i < branchLength; i++) { DungeonRoom newRoom = CreateRandomExit(data, currentRoom, false, keyLevel, false, false, difficultyModifiers); if (newRoom == currentRoom) { break; } currentRoom = newRoom; } //rule 4 - Place a key at the end of that branch currentRoom.AddKey(keyLevel); //rule 5 - Create a locked exit to a new room from any existing room except the end of // that branch. List <DungeonRoom> existingRooms = data.GetRooms(); DungeonRoom lockRoom = currentRoom; do { int randomIndex = Random.Range(0, existingRooms.Count); lockRoom = existingRooms[randomIndex]; } while (lockRoom == currentRoom || lockRoom.ExitCount == 4); lockRoom = CreateRandomExit(data, lockRoom, true, keyLevel, j == branchCount - 1, false, difficultyModifiers); keyLevel++; //rule 6 - "Current room" is the new room on the other side of the locked exit currentRoom = lockRoom; } //rule 8 - "Current room" is the final room data.finalRoom = currentRoom; //rule 9 - Create "Dead end" branches Z times of X length from any room except the boss // room. branchCount = Mathf.Max(0, Random.Range(difficultyModifiers.minDeadEndCount, difficultyModifiers.maxDeadEndCount)); for (int i = 0; i < branchCount; i++) { List <DungeonRoom> existingRooms = data.GetRooms(); DungeonRoom deadEndStart = null; do { int randomIndex = Random.Range(0, existingRooms.Count); deadEndStart = existingRooms[randomIndex]; } while (deadEndStart == data.finalRoom || deadEndStart.ExitCount == 4); currentRoom = deadEndStart; int branchLength = Mathf.Max(1, Random.Range(difficultyModifiers.minBranchLength, difficultyModifiers.maxBranchLength)); for (int j = 0; j < branchLength; j++) { DungeonRoom newRoom = CreateRandomExit(data, currentRoom, false, keyLevel, false, j == branchLength - 1, difficultyModifiers); if (newRoom == currentRoom) { break; } currentRoom = newRoom; } } for (int i = 0; i < data.GetRoomCount(); i++) { data.GetRooms()[i].GenerateContent(); } for (int i = 0; i < data.GetRoomCount(); i++) { data.GetRooms()[i].GenerateOuterWalls(); } return(data); }
// Update is called once per frame void Update() { startRoom = FindObjectOfType <StartRoom>(); }
/// <summary> /// /// </summary> /// <param name="startRoom"></param> /// <param name="exitRoom"></param> private int ResolveRoomConnections(StartRoom startRoom, ExitRoom exitRoom) { // Put walls around the edge of the map for (var x = 0; x < GridSize; ++x) { for (var y = 0; y < GridSize; ++y) { foreach (var direction in RoomConnection.Directions) { var room = GetRoom(x, y); if (room?.HasConnection(direction) != true) { continue; } var adjacentRoom = GetAdjacentRoom(x, y, direction); // Adjacent room has no connection point at the opposite side, set to a wall. if (adjacentRoom != null && !adjacentRoom.HasConnection(direction.GetOpposite())) { room.SetConnection(direction, RandomArrayItem(WallConnectionPrefabs)); continue; } // adjacent it out of bounds, set to a wall. if (adjacentRoom == null) { room.SetConnection(direction, RandomArrayItem(WallConnectionPrefabs)); } } } } // Find a route from start to exit. var maxPathResolve = (GridSize * GridSize) * RoomConnection.Directions.Length; BaseRoom currentRoom = startRoom; var roomRoute = new Stack <BaseRoom>(); while (currentRoom != exitRoom) { var openDirections = currentRoom.GetFreeConnectionDirections(); if (!openDirections.Any()) { if (roomRoute.Count == 0) { Debug.LogError($"The room '{currentRoom.name}' has no open connections."); break; } currentRoom = roomRoute.Pop(); continue; } var moveDirection = openDirections[Random.Range(0, openDirections.Count)]; var nextRoom = GetAdjacentRoom(currentRoom, moveDirection); var doorPrefabs = DoorConnectionPrefabs; if (currentRoom == startRoom) { doorPrefabs = doorPrefabs.Where(x => x.Type == DoorConnector.DoorType.Normal).ToArray(); } var doorConnection = RandomArrayItem(doorPrefabs); currentRoom.SetConnection(moveDirection, doorConnection); nextRoom.SetConnection(moveDirection.GetOpposite(), doorConnection); roomRoute.Push(currentRoom); currentRoom = nextRoom; if (--maxPathResolve == 0) { Debug.LogError("Failed to generate a path from start to finish within the maximum number of moves."); break; } } // Fill all open connections with walls. for (var x = 0; x < GridSize; ++x) { for (var y = 0; y < GridSize; ++y) { var room = GetRoom(x, y); if (room == null) { continue; } foreach (var direction in room.GetFreeConnectionDirections()) { var wallPrefab = RandomArrayItem(WallConnectionPrefabs); room.SetConnection(direction, wallPrefab); var adjacentRoom = GetAdjacentRoom(x, y, direction); if (adjacentRoom?.HasConnection(direction.GetOpposite()) == true) { adjacentRoom.SetConnection(direction.GetOpposite(), wallPrefab); } } } } // Remove completely walled rooms for (var x = 0; x < GridSize; ++x) { for (var y = 0; y < GridSize; ++y) { var room = GetRoom(x, y); if (room?.IsBoxedIn() == true) { Destroy(room.gameObject); m_tiles[x, y] = null; } } } return(CalculateShortestRoute(startRoom, exitRoom, 0, new HashSet <BaseRoom>())); }
public void Generate() { grid = new bool[width + 1, width + 1]; maze = new Tile[width + 1, width + 1]; List <pair> frontiers = new List <pair>(); //cells to visit //starting tile int pos = width / 2 + 1; grid[pos, pos] = true; //frontiers.Add(new pair(1, width - 3)); //frontiers.Add(new pair(3, width - 1)); frontiers.Add(new pair(pos - 2, pos)); frontiers.Add(new pair(pos + 2, pos)); frontiers.Add(new pair(pos, pos - 2)); frontiers.Add(new pair(pos, pos + 2)); while (frontiers.Count > 0) { int index = UnityEngine.Random.Range(0, frontiers.Count); //get random cell from list pair coords = frontiers[index]; List <pair> neighbors = getNeighbors(coords.a, coords.b); //get random neighbor int index2 = UnityEngine.Random.Range(0, neighbors.Count); //Debug.Log(index2); pair neighbor = neighbors[index2]; int dx = (neighbor.a - coords.a) / 2; int dy = (neighbor.b - coords.b) / 2; //Debug.Log("dx: " + dx); //Debug.Log("dy: " + dy); grid[coords.a, coords.b] = true; grid[coords.a + dx, coords.b + dy] = true; //passage between selected frontier cell and selected neighbor if (valid(coords.a + 2, coords.b)) //add chosen cell's frontier cells { if (!grid[coords.a + 2, coords.b]) { //Debug.Log(grid[coords.a + 2, coords.b]); pair p1 = new pair(coords.a + 2, coords.b); if (!frontiers.Contains(p1)) { frontiers.Add(new pair(coords.a + 2, coords.b)); } } } if (valid(coords.a, coords.b + 2)) { if (!grid[coords.a, coords.b + 2]) { // Debug.Log(grid[coords.a, coords.b + 2]); pair p2 = new pair(coords.a, coords.b + 2); if (!frontiers.Contains(p2)) { frontiers.Add(new pair(coords.a, coords.b + 2)); } } } if (valid(coords.a - 2, coords.b)) { if (!grid[coords.a - 2, coords.b]) { // Debug.Log(grid[coords.a - 2, coords.b]); pair p3 = new pair(coords.a - 2, coords.b); if (!frontiers.Contains(p3)) { frontiers.Add(new pair(coords.a - 2, coords.b)); } } } if (valid(coords.a, coords.b - 2)) { if (!grid[coords.a, coords.b - 2]) { // Debug.Log(grid[coords.a, coords.b - 2]); pair p4 = new pair(coords.a, coords.b - 2); if (!frontiers.Contains(p4)) { frontiers.Add(new pair(coords.a, coords.b - 2)); } } } frontiers.Remove(coords); //remove chosen cell from list of frontier cells } //positions of start and end rooms (along top and bottom rows) int start = 2 * UnityEngine.Random.Range(1, width / 2) - 1; int end = 2 * UnityEngine.Random.Range(1, width / 2) - 1; grid[0, start] = true; //passage from start room to maze grid[width, end] = true; //passage from maze to end room (use width not width-1 because grid is actually width+1 wide) startRoom = Instantiate(startRoomPrefab) as StartRoom; startRoom.name = "Start Room"; startRoom.transform.parent = transform; startRoom.transform.localPosition = new Vector3(0f, 0f, 0f); endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.name = "End Room"; endRoom.transform.parent = transform; endRoom.transform.localPosition = new Vector3(StartRoom.WIDTH / 2 + width + 2f + EndRoom.WIDTH / 2, 0, end + 1f - EndRoom.WIDTH / 2 - start + 1f); int catX = 2 * UnityEngine.Random.Range(1, width / 2 + 1) - 3; int catZ = 2 * UnityEngine.Random.Range(1, width / 2 + 1) - 3; cat = Instantiate(catPrefab) as Cat; cat.name = "Cat"; cat.transform.parent = transform; cat.transform.localPosition = new Vector3(catX + 1f + StartRoom.WIDTH / 2, 0f, catZ + 1f - start + 1f); for (int z = 0; z < width + 1; ++z) { for (int x = 0; x < width + 1; ++x) { if (grid[x, z]) //if a passage { Passage pass = Instantiate(passagePrefab) as Passage; maze[x, z] = pass; pass.name = "Tile " + x + ", " + z; pass.transform.parent = transform; pass.transform.localPosition = new Vector3(x + 1f + StartRoom.WIDTH / 2, 0f, z - start); //want tile at (1,1) to be at position x = 0 z = 0 so player starts in top left } else //else a wall { Wall wall = Instantiate(wallPrefab) as Wall; maze[x, z] = wall; wall.name = "Tile " + x + ", " + z; wall.transform.parent = transform; wall.transform.localPosition = new Vector3(x + 1f + StartRoom.WIDTH / 2, 0f, z - start); //want tile at (1,1) to be at position x = 0 z = 0 so player starts in top left } } } }
static Dungeon GetCustomDungeon() { var roomN = new BossRoom() { Coords = new RoomCoords(0, 1) }; var roomNE = new Chamber() { Coords = new RoomCoords(1, 1) }; var roomW = new Chamber() { Coords = new RoomCoords(-1, 0) }; var roomC = new StartRoom() { Coords = new RoomCoords(0, 0) }; var roomE = new Chamber() { Coords = new RoomCoords(1, 0) }; var roomSW = new Chamber() { Coords = new RoomCoords(-1, -1) }; var roomS = new Chamber() { Coords = new RoomCoords(0, -1) }; var roomSE = new Chamber() { Coords = new RoomCoords(1, -1) }; var roomNW = new Chamber() { Coords = new RoomCoords(-1, 1) }; roomNW.AdjacentEast = roomN; roomNW.AdjacentSouth = roomW; roomN.AdjacentWest = roomNW; roomN.AdjacentEast = roomNE; roomNE.AdjacentWest = roomN; roomNE.AdjacentSouth = roomE; roomE.AdjacentNorth = roomNE; roomE.AdjacentWest = roomC; roomC.AdjacentEast = roomE; roomC.AdjacentWest = roomW; roomC.AdjacentSouth = roomS; roomS.AdjacentNorth = roomC; roomS.AdjacentEast = roomSE; roomS.AdjacentWest = roomSW; roomSE.AdjacentWest = roomS; roomW.AdjacentNorth = roomNW; roomW.AdjacentEast = roomC; roomW.AdjacentSouth = roomSW; roomSW.AdjacentNorth = roomW; roomSW.AdjacentEast = roomS; return(new Dungeon() { Rooms = new List <Room> { roomNW, roomN, roomNE, roomW, roomC, roomE, roomSW, roomS, roomSE } }); }
public WorldBuilder() { // Create Rooms var room1 = new StartRoom( "The Room", "I'm inside a small room with bad lighting, I can see a door, maybe I can open it?", "There's a key and a note on the ground!"); var room2 = new Hallway( "Hallway", "A small hallway with cement covered walls, the air is damp. I think I'm in a cellar?\n" + "There is a path leading to the left, it looks dark. There's also a path leading to the right.", ""); var room3Right = new JanitorsRoom( "Janitor's Room", "It's a small room, quite messy, it smells like gasoline. I see a painting of an old man with a handle bar mustasch.\n" + "I can't see any exits here besides the way I came from.", ""); var room4Left = new FinalRoom( "Final Room", "It's a small room with walls covered in moist, I can see a door with a codelock next to it.", "There's nothing here except the door..."); // Create Items var roomKey = new Item( "Room Key", "It looks like it could fit to this door.", 1, "The key is old and rusty, it looks fragile."); var note = new Note( "Note", "A piece of paper with something written on it.", 0, "A piece of paper with something written on it."); var bottle = new Bottle( "Bottle of Kerosene", "It's commonly used to power jet engines.", 2, "A bottle of kerosene, it's very flammable."); var rags = new Rags( "Rags", "Some old clothes ripped apart.", 2, "I think this used to be a shirt..."); var broom = new Broom( "Broom", "A regular broom used to cleaning.", 5, "It's a broom, what more do you need to know?"); var painting = new Item( "Painting", "A painting of Mr.X?", 0, "The painting is signed by Mr X." + " There seems to be missing a piece of the painting.", false); var rocks = new Rock( "Pile of Rocks", "It's a pile of rocks.", 7, "A large pile of small rocks, almost as someone placed them there? Maybe I can move them.", false); // Create Exit Points var roomExit = new Door( room2, 1, true, false, "Rooms Door", "You hear a crack... the door is unlocked! Oh... the key broke in half.", "The door is locked, maybe there's a key somewhere?", "A brown wooden door with a sturdy lock."); var room2RightExit = new RightOfHallway( room3Right, 2, false, false, "Right", "", "", "" ); var room2LeftExit = new LeftOfHallway( room4Left, 10, true, false, "Left", "Finally some light! I can now see where I'm going.", "I can't go that way, it's too dark. I need some light...", "It's just a dark passage..." ); var finalRoomExit = new FinalDoor( 11, true, false, "Codelock Door", "Success! The door is unlocked, let's get out of here!", "The door is locked. There's a codelock to it. I need to find that code!", "A big iron door with a codelock next to it." ); // Add exits to room sists room1.Exit.Add(roomExit); room2.Exit.Add(new Door( room1, 1, false, false, "Rooms Door", "", "", "That's the door I came from. The key is still stuck inside the lock, whoops!")); room2.Exit.Add(room2RightExit); room2.Exit.Add(room2LeftExit); room3Right.Exit.Add(new Exit( room2, 2, false, false, "Left", "", "", "")); room4Left.Exit.Add(new Exit (room2, 2, false, false, "Right", "", "", "")); room4Left.Exit.Add(finalRoomExit); // Add items to room inventory room1.RoomInventory.Add(roomKey); room1.RoomInventory.Add(note); room2.RoomInventory.Add(rocks); room3Right.RoomInventory.Add(bottle); room3Right.RoomInventory.Add(rags); room3Right.RoomInventory.Add(broom); room3Right.RoomInventory.Add(painting); // Add all instances of rooms to property Rooms Rooms.Add(room1); Rooms.Add(room2); Rooms.Add(room3Right); }
public GameWorld(int Width, int Height, Point start, int seed = 0) { ////TODO: Make better world generation rng = new Random(0); width = Width; height = Height; map = new MapObject[width, height]; int ID = 0; //Fill map with air for (int x = 0; x <= map.GetUpperBound(0); x++) { for (int y = 0; y <= map.GetUpperBound(1); y++) { map[x, y] = new Space(ID++, new Point(x, y)); } } if (Width % Room.RoomBaseSize != 0 || Height % Room.RoomBaseSize != 0) { throw new Exception("The large map can not be mapped onto the smaller!"); } roomMap = new Room[Width / Room.RoomBaseSize, Height / Room.RoomBaseSize]; //Define all possible rooms Point _Position = new Point(0, 0); List <Room> possibilites = new List <Room> { new IntersectionRoom(_Position), new TIntersectionBottom(_Position), new TIntersectionTop(_Position), new TIntersectionLeft(_Position), new TIntersectionRight(_Position), new SingleEntranceRoomTop(_Position), new SingleEntranceRoomRight(_Position), new SingleEntranceRoomLeft(_Position), new SingleEntranceRoomBottom(_Position), new FilledRoom(_Position) }; //Add start room roomMap[0, 0] = new StartRoom(new Point(0, 0)); roomMap[0, 0].Generate(ref map, ref ID); for (int x = 0; x <= roomMap.GetUpperBound(0); x++) { for (int y = 0; y <= roomMap.GetUpperBound(1); y++) { if (roomMap[x, y] != null) { continue; } //Find possible rooms //Find needed exits List <int> top; List <int> bottom; List <int> left; List <int> right; if (y == 0) { top = new List <int>(); } else { top = roomMap[x, y - 1].exits.bottom; } if (y == roomMap.GetUpperBound(1)) { bottom = new List <int>(); } else if (roomMap[x, y + 1] != null) { bottom = roomMap[x, y + 1].exits.top; } else { bottom = null; } if (x == 0) { left = new List <int>(); } else { left = roomMap[x - 1, y].exits.right; } if (x == roomMap.GetUpperBound(0)) { right = new List <int>(); } else if (roomMap[x + 1, y] != null) { right = roomMap[x + 1, y].exits.left; } else { right = null; } Adjacent <List <int> > neededExits = new Adjacent <List <int> >(top, left, right, bottom); //Find possible rooms Room room = possibilites.First(p => { bool _top = p.exits.top.SequenceEqual(neededExits.top); bool _left = p.exits.left.SequenceEqual(neededExits.left); bool _right = null == neededExits.right || p.exits.right.SequenceEqual(neededExits.right); bool _bottom = null == neededExits.bottom || p.exits.bottom.SequenceEqual(neededExits.bottom); return(_top && _left && _right && _bottom); }); //Add room roomMap[x, y] = room.NewRoom(new Point(x * Room.RoomBaseSize, y * Room.RoomBaseSize)); roomMap[x, y].Generate(ref map, ref ID); } } }
/// <summary> /// Generate Map /// </summary> /// <returns></returns> public IEnumerator generateMap() { // Check if the generations stucks in a loop if (current_iteration < MAX_ITERATIONS) { // Stop all Tweens LeanTween.cancelAll(); // Increase Iteration current_iteration += 1; // Delete old map clearWorld(); // Wait a Frame yield return(new WaitForFixedUpdate()); // Create a new Map SetMap(); // Print Matrix if (printDebugMatrix) { printMatrix(); } // Load all resources rooms in a Array resourcesEnemyRoomList.Clear(); resourcesHallwayList.Clear(); resourcesStartRoomList.Clear(); resourcesSpecialRooms.Clear(); resourcesEnemyRoomList = Resources.LoadAll <GameObject>("Rooms/Enemy Rooms").ToList(); resourcesStartRoomList = Resources.LoadAll <GameObject>("Rooms/Start Rooms").ToList(); resourcesHallwayList = Resources.LoadAll <GameObject>("Rooms/Hallways").ToList(); resourcesSpecialRooms = Resources.LoadAll <GameObject>("Rooms/Special Rooms").ToList(); if (resourcesBossRooms.Count == 0) { resourcesBossRooms = Resources.LoadAll <GameObject>("Rooms/Boss Rooms").ToList(); } // Spawn Rooms SpawnRooms(); // Spawn Boss Room SpawnSpecialRooms(1, 1); // Spawn Special Rooms SpawnSpecialRooms(specialRoomCount, 0); // Controll that no room is on the same place as a other if (controllWorldGen()) { current_iteration += 1; StartCoroutine(generateMap()); } // Set Hallway SpawnHallways(); // Set Playerpos foreach (GameObject r in rooms) { StartRoom sr = r.GetComponent <StartRoom>(); if (sr != null) { PlayerController.Instance.transform.position = sr.PlayerSpawn.position; PlayerController.Instance.unit.setHealthPlayer(0); } } // Generate Minimap miniMapGenerator.generateMiniMap(); // Bake Navmesh StartCoroutine(bakeNavmesh()); } else { // Load loading Scene SceneManager.LoadScene(1); } }