public RogueRect(RogueRect other) { Left = other.Left; Right = other.Right; Top = other.Top; Bottom = other.Bottom; }
public override void Paint(Level level) { var painter = new RoomPainter(level, this); PaintOutsideWalls(level); var newRect = new RogueRect(Bounds); newRect.Left += 1; newRect.Right = newRect.Left + 2; newRect.Top -= 2; newRect.Bottom += 1; painter.PaintFloorArea(newRect); newRect.Right = Bounds.Right - 2; newRect.Left = newRect.Right - 2; painter.PaintFloorArea(newRect); newRect = new RogueRect(Bounds); newRect.Bottom += 1; newRect.Top = newRect.Bottom + 2; newRect.Left += 1; newRect.Right -= 2; painter.PaintFloorArea(newRect); newRect.Top = Bounds.Top - 2; newRect.Bottom = newRect.Top - 2; painter.PaintFloorArea(newRect); painter.AutoPaintWalls(); }
private RogueRect GetBoundary() { var bounds = new RogueRect() { Left = int.MaxValue, Right = int.MinValue, Top = int.MinValue, Bottom = int.MaxValue, }; foreach (var room in Rooms) { if (room.Bounds.Left < bounds.Left) { bounds.Left = room.Bounds.Left; } if (room.Bounds.Right > bounds.Right) { bounds.Right = room.Bounds.Right; } if (room.Bounds.Top > bounds.Top) { bounds.Top = room.Bounds.Top; } if (room.Bounds.Bottom < bounds.Bottom) { bounds.Bottom = room.Bounds.Bottom; } } return(bounds); }
private Vector2Int GetIdealCenter(RogueRect prev, RogueRect next, float m, float b, Direction Direction) { //find the ideal center for this new room using the line equation and known dimensions var targetCenter = new Vector2Int(); if (Direction == Direction.RIGHT) { targetCenter.x = prev.Right + (next.Width) / 2; targetCenter.y = (int)(m * targetCenter.x + b); } else if (Direction == Direction.LEFT) { targetCenter.x = prev.Left - (next.Width) / 2; targetCenter.y = (int)(m * targetCenter.x + b); } else if (Direction == Direction.TOP) { targetCenter.y = prev.Top + (next.Height) / 2; targetCenter.x = (int)((targetCenter.y - b) / m); } else { targetCenter.y = prev.Bottom - (next.Height) / 2; targetCenter.x = (int)((targetCenter.y - b) / m); } var width = (float)prev.Width; var height = (float)prev.Height; return(targetCenter); }
public Room(RoomInfo info) { Info = info; Bounds = new RogueRect(); Neighbors = new List <Room>(); ConnectionPoints = new Dictionary <Room, SerializableVector2Int>(); Corners = new List <SerializableVector2Int>(); }
public List <Vector2Int> GetPossibleSpawnLocations() { var rect = new RogueRect() { Left = Bounds.Left + 1, Right = Bounds.Right - 2, Bottom = Bounds.Bottom + 1, Top = Bounds.Top - 2 }; return(rect.GetPoints()); }
public void Reset() { Bounds = new RogueRect(); ConnectionPoints = new Dictionary <Room, SerializableVector2Int>(); Corners = new List <SerializableVector2Int>(); foreach (var room in Neighbors) { room.Neighbors.Remove(this); room.ConnectionPoints.Remove(this); } Neighbors = new List <Room>(); }
/// <summary> /// Gets the rectangle that is the intersection between these rectangles /// </summary> /// <param name="other"></param> /// <returns></returns> public RogueRect Intersect(RogueRect other) { var result = new RogueRect(); result.Left = Math.Max(Left, other.Left); result.Right = Math.Min(Right, other.Right); result.Top = Math.Min(Top, other.Top); result.Bottom = Math.Max(Bottom, other.Bottom); if (result.Width < 0 || result.Height < 0) { return null; } return result; }
private Vector2Int?FindStairsLocation() { var spawnArea = new RogueRect() { Left = Bounds.Left + 2, Right = Bounds.Right - 3, Top = Bounds.Top - 3, Bottom = Bounds.Bottom + 2 }; var possiblePoints = spawnArea.GetPoints(); if (possiblePoints.Count > 0) { return(SeededRandom.PickRandom(possiblePoints)); } return(null); }
public static TileMapData SaveTileMap(Tilemap tileMap, RogueRect bounds) { var data = new TileMapData() { TileNames = new string[bounds.Height, bounds.Width], Bounds = bounds, }; for (int i = bounds.Left; i < bounds.Right; i++) { for (int j = bounds.Bottom; j < bounds.Top; j++) { var tile = tileMap.GetTile(new Vector3Int(i, j, 0)); data.TileNames[j - bounds.Bottom, i - bounds.Left] = tile == null ? "" : tile.name; } } return(data); }
public override void Paint(Level level) { var painter = new RoomPainter(level, this); var center = GetCenterPoint(); //Helpers.DrawDebugLine(center.x, center.y); foreach (var door in ConnectionPoints.Values) { var start = new Vector2Int(door.x, door.y); if (start.y == Bounds.Top) { start.y--; } else if (start.x == Bounds.Right) { start.x--; } int rightShift = (int)center.x - start.x; int downShift = (int)center.y - start.y; Vector2Int mid; Vector2Int end; //always goes inward first if (door.x == Bounds.Left || door.x == Bounds.Right) { mid = new Vector2Int(start.x + rightShift, start.y); end = new Vector2Int(mid.x, mid.y + downShift); } else { mid = new Vector2Int(start.x, start.y + downShift); end = new Vector2Int(mid.x + rightShift, mid.y); } var firstHalf = new RogueRect(start, mid); var secondHalf = new RogueRect(mid, end); painter.PaintFloorArea(firstHalf); painter.PaintFloorArea(secondHalf); } painter.AutoPaintWalls(); }
private Vector2Int IntersectRogueRectAndLine(RogueRect RogueRectangle, float m, float b, Direction Direction) { if (Direction == Direction.RIGHT) { return(new Vector2Int(RogueRectangle.Right, (int)Math.Round(m * RogueRectangle.Right + b))); } else if (Direction == Direction.LEFT) { return(new Vector2Int(RogueRectangle.Left, (int)Math.Round(m * RogueRectangle.Left + b))); } else if (Direction == Direction.TOP) { return(new Vector2Int((int)Math.Round((RogueRectangle.Top - b) / m), RogueRectangle.Top)); } else { return(new Vector2Int((int)Math.Round((RogueRectangle.Bottom - b) / m), RogueRectangle.Bottom)); } }
private Direction GetEdgeThatWillConnect(RogueRect RogueRectangle, float m, float b, float angle) { var width = (float)RogueRectangle.Width; var height = (float)RogueRectangle.Height; if (-height / 2f <= m * width / 2 && m * width / 2 <= height) { if (angle <= 90 || angle >= 270) { return(Direction.RIGHT); } return(Direction.LEFT); } else { if (angle <= 180) { return(Direction.TOP); } return(Direction.BOTTOM); } }
/// <summary> /// Returns true if the rectangles are colliding. Touching is not considered colliding /// </summary> /// <param name="other"></param> /// <returns></returns> public bool IsColliding(RogueRect other) { return !(Math.Max(Left, other.Left) >= Math.Min(Right, other.Right) || Math.Min(Top, other.Top) <= Math.Max(Bottom, other.Bottom)); }
private RogueRect FindFreeSpace(RogueRect space, Vector2Int start) { var collisions = new List <Room>(PlacedRooms); do { //Remove all rooms that we aren't currently colliding with or currently inside or that are inside us collisions.RemoveAll(room => !room.Bounds.IsColliding(space) && !room.Bounds.IsInside(space) && !space.IsInside(room.Bounds)); if (collisions.Count != 0) { var closestRoom = GetClosestRoom(collisions, start); if (closestRoom == null) { return(null); } var intersection = closestRoom.Bounds.Intersect(space); if (intersection.Width >= intersection.Height) { if (intersection.Right == space.Right || Math.Abs(space.Right - intersection.Left) <= Math.Abs(space.Left - intersection.Right)) { space.Right = intersection.Left; } else { space.Left = intersection.Right; } } else { if (intersection.Top == space.Top || Math.Abs(space.Top - intersection.Bottom) <= Math.Abs(space.Bottom - intersection.Top)) { space.Top = intersection.Bottom; } else { space.Bottom = intersection.Top; } } ////We multiply by height and width here in order to take into effect the current size when determing what way to cut off the RogueRect //int wDiff = int.MaxValue; //var closestRogueRect = closestRoom.Bounds; //if (closestRogueRect.Left >= start.x) //{ // wDiff = (space.Right - closestRogueRect.Left); //} //else if (closestRogueRect.Right <= start.x) //{ // wDiff = (closestRogueRect.Right - space.Left); //} //var hDiff = int.MaxValue; //if (closestRogueRect.Top >= start.y) //{ // hDiff = (space.Bottom - closestRogueRect.Top); //} //else if (closestRogueRect.Bottom <= start.y) //{ // hDiff = (closestRogueRect.Bottom - space.Top); //} ////reduce by as little as possible to resolve the collision //if (wDiff < hDiff || (wDiff == hDiff && Random.Range(0, 2) == 0)) //{ // if (closestRogueRect.Left >= start.x && closestRogueRect.Left < space.Right) // space.Right = closestRogueRect.Left; // if (closestRogueRect.Right <= start.x && closestRogueRect.Right > space.Left) // space.Left = closestRogueRect.Right; //} //else //{ // if (closestRogueRect.Top >= start.y && closestRogueRect.Top < space.Bottom) // space.Bottom = closestRogueRect.Top; // if (closestRogueRect.Bottom <= start.y && closestRogueRect.Bottom > space.Top) // space.Top = closestRogueRect.Bottom; //} collisions.Remove(closestRoom); } } while (collisions.Count != 0); return(space); }
public void PaintFloorArea(RogueRect rect) { PaintFloorArea(rect.Left, rect.Right, rect.Bottom, rect.Top); }
/// <summary> /// Returns true if this rectangle is completely inside the other rectangle /// </summary> /// <param name="other"></param> /// <returns></returns> public bool IsInside(RogueRect other) { return Left >= other.Left && Right <= other.Right && Top <= other.Top && Bottom >= other.Bottom; }