private float getDebugRotation(Room r) { if (r.getRotation() == 1) { return(MathHelper.ToRadians(90)); } if (r.getRotation() == 2) { return(MathHelper.ToRadians(180)); } if (r.getRotation() == 3) { return(MathHelper.ToRadians(270)); } return(MathHelper.ToRadians(0)); }
public List <Room> getAccessibleRooms(Room current) { List <Room> listOfAccessibleRooms = new List <Room>(); Vector2 location = current.location; int rotation = current.getRotation(); // Intersection if (current.getRoomType() == Room.INTERSECTION) { for (int dir = Room.LEFT; dir <= Room.DOWN; dir++) { Room r = getRoomAt(current, dir); if (r != null) { listOfAccessibleRooms.Add(r); } } } // Triad else if (current.getRoomType() == Room.TRIAD) { for (int offset = -1; offset <= 1; offset++) { int dirToBeChecked = (rotation + offset) % 4; Room r = getRoomAt(current, dirToBeChecked); if (r != null) { listOfAccessibleRooms.Add(r); } } } // Corridor else if (current.getRoomType() == Room.CORRIDOR) { for (int offset = 0; offset <= 2; offset += 2) { int dirTobeChecked = (rotation + offset) % 4; Room r = getRoomAt(current, dirTobeChecked); if (r != null) { listOfAccessibleRooms.Add(r); } } } // Deadend else if (current.getRoomType() == Room.DEAD_END) { listOfAccessibleRooms.Add(getRoomAt(current, rotation)); } return(listOfAccessibleRooms); }
/// <summary> /// Given the current room, this function checks if current room has the door /// opened at the direction chosen. /// </summary> /// <param name="current"></param> /// <param name="dir"></param> /// <returns></returns> private Boolean isDoorEnabled(Room current, int dir) { // No door required, no problem if (dir == NO_DOOR_REQUIRED) { return(true); } // Intersections has all rooms open, no problem if (current.getRoomType() == Room.INTERSECTION) { return(true); } // Only the previous rotation was open. if (current.getRoomType() == Room.DEAD_END) { return(dir == current.getRotation()); } // Given the rotation of the room, only the opposite is not(!) allowed. if (current.getRoomType() == Room.TRIAD) { int rotation = current.getRotation() + 2; // get the opposite direction return(!(rotation == (dir + 2) % 4)); } if (current.getRoomType() == Room.CORRIDOR) { int rotation = current.getRotation(); return(rotation == dir || rotation == ((dir + 2) % 4)); // can open the direction of the room, or the opposite. } if (current.getRoomType() == Room.CORNER) { int rotation = current.getRotation(); return(rotation == dir || rotation == ((dir + 1) % 4)); // can open the direction of the room, or the next direction. } return(false); }
private float getDebugRotation(Room r) { if (r.getRotation() == 1) return MathHelper.ToRadians(90); if (r.getRotation() == 2) return MathHelper.ToRadians(180); if (r.getRotation() == 3) return MathHelper.ToRadians(270); return MathHelper.ToRadians(0); }
public List<Room> getAccessibleRooms(Room current) { List<Room> listOfAccessibleRooms = new List<Room>(); Vector2 location = current.location; int rotation = current.getRotation(); // Intersection if (current.getRoomType() == Room.INTERSECTION) { for (int dir = Room.LEFT; dir <= Room.DOWN; dir++) { Room r = getRoomAt(current, dir); if (r != null) listOfAccessibleRooms.Add(r); } } // Triad else if (current.getRoomType() == Room.TRIAD) { for (int offset = -1; offset <= 1; offset++) { int dirToBeChecked = (rotation + offset) % 4; Room r = getRoomAt(current, dirToBeChecked); if (r != null) listOfAccessibleRooms.Add(r); } } // Corridor else if (current.getRoomType() == Room.CORRIDOR) { for (int offset = 0; offset <= 2; offset += 2) { int dirTobeChecked = (rotation + offset) % 4; Room r = getRoomAt(current, dirTobeChecked); if (r != null) listOfAccessibleRooms.Add(r); } } // Deadend else if (current.getRoomType() == Room.DEAD_END) { listOfAccessibleRooms.Add(getRoomAt(current, rotation)); } return listOfAccessibleRooms; }
/// <summary> /// Given the current room, this function checks if current room has the door /// opened at the direction chosen. /// </summary> /// <param name="current"></param> /// <param name="dir"></param> /// <returns></returns> private Boolean isDoorEnabled(Room current, int dir) { // No door required, no problem if (dir == NO_DOOR_REQUIRED) return true; // Intersections has all rooms open, no problem if (current.getRoomType() == Room.INTERSECTION) return true; // Only the previous rotation was open. if (current.getRoomType() == Room.DEAD_END) { return dir == current.getRotation(); } // Given the rotation of the room, only the opposite is not(!) allowed. if (current.getRoomType() == Room.TRIAD) { int rotation = current.getRotation() + 2; // get the opposite direction return !(rotation == (dir + 2) % 4); } if (current.getRoomType() == Room.CORRIDOR) { int rotation = current.getRotation(); return rotation == dir || rotation == ((dir + 2) % 4); // can open the direction of the room, or the opposite. } if (current.getRoomType() == Room.CORNER) { int rotation = current.getRotation(); return rotation == dir || rotation == ((dir + 1) % 4); // can open the direction of the room, or the next direction. } return false; }
// DFS Maze creation, fixed. // TODONT: Add corners for map generation. // Deprecated /** * 22, 22, 22, 22, 12% (deadend) chance. */ private void generateMaze(int x, int y, Room prev) { int roomType, roomRotation; Room current = getRoom(x, y); /** * BASE CASE END OF RECURSIVE ALGORITHM * * This checks if the room has already been * explored or if the room is out of bounds * from the map. */ if (exploredRooms.Contains(current)) return; if (current == null) return; /** * ROOM TYPE, ROTATION, DESIGN * * This handles the room generation with * regards to room type, rotation, and design */ do { if (prev == null) roomRotation = random.Next(4); else roomRotation = (prev.getRotation() + 2) % 4; current.setRotation(roomRotation); roomType = random.Next(4) + 2; current.setRoomType(roomType); } while (!areRoomsConnected(isToTheDirectionOf(current, prev), prev, current) || getAccessibleRooms(current).Count <= 0); int[,] roomDesign = roomDatabaseReference.getRoomDesign(roomType, roomRotation); if (roomDesign != null) { current.setRoomDesign(roomDesign); current.Initialize(); } else { // TODONT: Must use room designer java application to create corners. // Deprecated. Corner rooms are done already. throw new Exception("Undefined Room Design Exception!"); } /** * MAZE CREATION * * Start the DFS creation of the maze */ // Add the current room to list of explored rooms exploredRooms.Add(current); List<Room> roomsAvailable = getAccessibleRooms(current); do { // Get a random room from the list and remove it from the list int index = random.Next(roomsAvailable.Count); Room roomToVenture = roomsAvailable.ElementAt(index); roomsAvailable.RemoveAt(index); // The room is already explored, don't go set it anymore if (exploredRooms.Contains(roomToVenture)) continue; // There is no room to venture to, don't go there if (roomToVenture == null) continue; // Determine the direction to take and the coordinate of the target room int directionToTake = isToTheDirectionOf(current, roomToVenture); Vector2 destinationCoordinate = getPointAt(current, directionToTake); // Recurse -- DEPRECATED generateMaze((int)destinationCoordinate.X, (int)destinationCoordinate.Y, current); } while (roomsAvailable.Count > 0); }
// DFS Maze creation, fixed. // TODONT: Add corners for map generation. // Deprecated /** * 22, 22, 22, 22, 12% (deadend) chance. */ private void generateMaze(int x, int y, Room prev) { int roomType, roomRotation; Room current = getRoom(x, y); /** * BASE CASE END OF RECURSIVE ALGORITHM * * This checks if the room has already been * explored or if the room is out of bounds * from the map. */ if (exploredRooms.Contains(current)) { return; } if (current == null) { return; } /** * ROOM TYPE, ROTATION, DESIGN * * This handles the room generation with * regards to room type, rotation, and design */ do { if (prev == null) { roomRotation = random.Next(4); } else { roomRotation = (prev.getRotation() + 2) % 4; } current.setRotation(roomRotation); roomType = random.Next(4) + 2; current.setRoomType(roomType); } while (!areRoomsConnected(isToTheDirectionOf(current, prev), prev, current) || getAccessibleRooms(current).Count <= 0); int[,] roomDesign = roomDatabaseReference.getRoomDesign(roomType, roomRotation); if (roomDesign != null) { current.setRoomDesign(roomDesign); current.Initialize(); } else { // TODONT: Must use room designer java application to create corners. // Deprecated. Corner rooms are done already. throw new Exception("Undefined Room Design Exception!"); } /** * MAZE CREATION * * Start the DFS creation of the maze */ // Add the current room to list of explored rooms exploredRooms.Add(current); List <Room> roomsAvailable = getAccessibleRooms(current); do { // Get a random room from the list and remove it from the list int index = random.Next(roomsAvailable.Count); Room roomToVenture = roomsAvailable.ElementAt(index); roomsAvailable.RemoveAt(index); // The room is already explored, don't go set it anymore if (exploredRooms.Contains(roomToVenture)) { continue; } // There is no room to venture to, don't go there if (roomToVenture == null) { continue; } // Determine the direction to take and the coordinate of the target room int directionToTake = isToTheDirectionOf(current, roomToVenture); Vector2 destinationCoordinate = getPointAt(current, directionToTake); // Recurse -- DEPRECATED generateMaze((int)destinationCoordinate.X, (int)destinationCoordinate.Y, current); } while (roomsAvailable.Count > 0); }