public override bool AddExit(Direction dir, Room[,] floorLayout) { if (exits[DirectionUtility.getIndex(dir)] == true) { DisableWall(dir); return(true); } return(false); }
public virtual bool AddExit(Direction dir, Room[,] floorLayout) { if (exits[DirectionUtility.getIndex(dir)] == false) { exits[DirectionUtility.getIndex(dir)] = true; RoomManager.instance.ReplaceRoom(this, exits, floorLayout); } Debug.Log("Replacing Room " + x + " and " + y); return(true); }
public void FuseRooms(Room roomA, Room roomB, Room[,] floorLayout) { Debug.Log("Fusing " + roomA.x + ", " + roomA.y + " and " + roomB.x + ", " + roomB.y); List <int> goingDirections = new List <int> { 0, 1, 2, 3 }; foreach (int i in goingDirections) { if (roomA.x + DirectionUtility.getX(i) == roomB.x && roomA.y + DirectionUtility.getY(i) == roomB.y) { bool[] roomAexits = roomA.getExits(); roomAexits[i] = true; bool[] roomBexits = roomB.getExits(); roomBexits[DirectionUtility.getIndex(DirectionUtility.opposite(i))] = true; ReplaceRoom(roomA, roomAexits, floorLayout); ReplaceRoom(roomB, roomBexits, floorLayout); return; } } }
public void EnableWall(Direction dir) { if (dir == Direction.UP) { Timing.RunCoroutine(SetVisibility(upWall, true)); } if (dir == Direction.DOWN) { Timing.RunCoroutine(SetVisibility(downWall, true)); } if (dir == Direction.LEFT) { Timing.RunCoroutine(SetVisibility(leftWall, true)); } if (dir == Direction.RIGHT) { Timing.RunCoroutine(SetVisibility(rightWall, true)); } storedExits[DirectionUtility.getIndex(dir)] = false; }
//The Tunnel method will decide what kind of room is needed and call getCorridor to make rooms public void Tunnel(int x, int y, Room[,] floorLayout, Direction from, Room _room) { //Decide directions this room will go to bool[] exits = FindDirections(x, y, floorLayout, _room); exits[DirectionUtility.getIndex(from)] = true; //Once all exits have been found, ask for a room to fill in this one if (x >= 0 && y >= 0 && x < floorLayout.GetLength(0) && y < floorLayout.GetLength(1)) { if (floorLayout[x, y] == null) { Room createdRoom = GetCorridor(exits); createdRoom.x = x; createdRoom.y = y; GameObject madeRoom = Instantiate(createdRoom.gameObject, new Vector3(x * ROOM_SIZE_X, y * -ROOM_SIZE_Y, 0), Quaternion.identity); //Set baseRoom floorLayout[x, y] = madeRoom.GetComponent <Room>(); floorLayout[x, y].setBase(_room); order++; floorLayout[x, y].setOrder(order); //Call Tunnel on each room this one can go to for (int i = 0; i < 4; i++) { if (exits[i] == true && i != DirectionUtility.getIndex(from)) { if (floorLayout[x + DirectionUtility.getX(i), y + DirectionUtility.getY(i)] == null) { //if(CheckPoint(x+Direction.getX(i),y+Direction.getY(i), floorLayout)) { Tunnel(x + DirectionUtility.getX(i), y + DirectionUtility.getY(i), floorLayout, DirectionUtility.opposite(i), _room); //} } } } } } }
public static bool[] FindDirections(int x, int y, Room[,] floorLayout, Room _baseRoom) { bool[] exits = new bool[4]; List <int> goingDirections = new List <int> { 0, 1, 2, 3 }; do { foreach (int i in goingDirections) { //Make sure we're inside the bounds of the loop int _x = x + DirectionUtility.getX(i); int _y = y + DirectionUtility.getY(i); if (_x < floorLayout.GetLength(0) && _x >= 0 && _y < floorLayout.GetLength(1) && _y >= 0) { if (floorLayout[_x, _y] == null) { //Randomize whether this exit will be used if (Random.Range(0, 100) < ROOM_CHANCE) { exits[i] = true; } } else { //Check if this this room is connected to an UNCONNECTED MAINROOM if ((floorLayout[_x, _y].isConnected() == false || _baseRoom.isConnected() == false) && floorLayout[_x, _y].getBaseRoom() != _baseRoom) { //Open this entrance of the mainRoom //_checkedRoom.DisableWall(DirectionUtility.opposite(i)); bool addStatus = floorLayout[_x, _y].AddExit(DirectionUtility.opposite(i), floorLayout); if (addStatus == true) { //Flag connection _baseRoom.Connect(floorLayout[_x, _y]); exits[i] = true; } } //Make sure we're not dealing with a special room (that only opens up IF we're not connected, so get with the program!) SpecialRoom tempRoom = floorLayout[_x, _y] as SpecialRoom; if (tempRoom == null) { //Check if room this one is facing is already open to this room bool[] roomExits = floorLayout[_x, _y].getExits(); if (roomExits[DirectionUtility.getIndex(DirectionUtility.opposite(i))] == true) { exits[i] = true; } } /* * foreach(SpecialRoom _checkedRoom in mainRooms) { * if(floorLayout[_x,_y]==((Room) _checkedRoom) && ((Room) _checkedRoom) != _baseRoom) { * //If it is, check if this mainRoom is connected to another room yet * //if((!_checkedRoom.isConnected() || !_baseRoom.isConnected()) && roomExits[DirectionUtility.getIndex(DirectionUtility.opposite(i))] == true) { * if(!_checkedRoom.isConnected() || !_baseRoom.isConnected() || roomExits[DirectionUtility.getIndex(DirectionUtility.opposite(i))] == true) { * //If it isn't, connect it * _baseRoom.Connect(_checkedRoom); * exits[i] = true; * noExit = false; * //Open this entrance of the mainRoom * _checkedRoom.DisableWall(DirectionUtility.opposite(i)); * } * } * }*/ } } //Now that everything has been checked, remove this direction goingDirections.Remove(i); break; } // End of for loop } while(goingDirections.Count > 0); return(exits); }
public bool CheckExit(Direction checkMe) { exits = validateExits(); return(exits[DirectionUtility.getIndex(checkMe)]); }