public void GenerateNewFloor() { //destroy previous room prefabs and minimap foreach (FloorNode room in nodeList) { room.DestroyRoom(); } MinimapScript.MyInstance.ClearMap(); nodeList.Clear(); IncreaseFloorLevel(); //create a first room FloorNode newNode = new FloorNode(); newNode.SetRoomType(FloorNode.roomTypeEnum.regular); newNode.SetCoord(0, 0); nodeList.Add(newNode); SetCurrentNode(newNode); //create the number of regular rooms desired int roomNumber = basicRoomsNumber; while (roomNumber > 0) { CreateRandomNode(FloorNode.roomTypeEnum.regular); roomNumber--; } //add other rooms after AddSpecialRooms(); //when every nodes are placed and have their coordinates //we create each node's room prefab and disable them foreach (FloorNode node in nodeList) { node.SetRoom(node.GetRoomType(), dungeonLevel); node.CreateRoom(); node.ActivateRoom(false); } //create the first room on the minimap InitializeMap(nodeList[0].GetRoom()); //if the player has the item to reveal the map if (isMapRevealed) { MinimapScript.MyInstance.ShowFullMap(nodeList); } else { MinimapScript.MyInstance.AddRoom(newNode, false); } //update the display of the current room on the minimap MinimapScript.MyInstance.UpdateCurrentRoomDisplay(GetCurrentNode()); currentNodeIndex = 0; }
private void CreateRandomNode(FloorNode.roomTypeEnum roomType) { bool canBeCreated = false; //debug count int count = 0; while (!canBeCreated && count < 1000) { count++; //take an existing room FloorNode existingNode = nodeList[Random.Range(0, nodeList.Count)]; //choose a random direction var randomDirection = (FloorNode.directionEnum)Random.Range(0, 4); //set the new room coord based on the existing room we used to place it (int x, int y) = existingNode.GetCoord(); if (randomDirection == FloorNode.directionEnum.east) { x += 1; } if (randomDirection == FloorNode.directionEnum.west) { x -= 1; } if (randomDirection == FloorNode.directionEnum.north) { y += 1; } if (randomDirection == FloorNode.directionEnum.south) { y -= 1; } //if the existing room is a regular room, is not occupied, has no room at the direction chosen //and does not exceed one of the maximum coordinate, we create the room there if (existingNode.GetNeighbourNode(randomDirection) == null && !isTileOccupied(x, y) && existingNode.GetRoomType() == FloorNode.roomTypeEnum.regular && x < 4 && x > -4 && y < 4 && y > -4) { FloorNode newNode = new FloorNode(); newNode.SetRoomType(roomType); //connect the new room with the existing room CreateLinkBetweenNodes(existingNode, newNode, randomDirection); newNode.SetCoord(x, y); if (existingNode.GetRoomType() == FloorNode.roomTypeEnum.regular) { //check if there are rooms existing around the new room and connect them. //This allow the level to have loops and not look like a tree ConnectNodeNeighbours(newNode); } nodeList.Add(newNode); canBeCreated = true; } } }