public void CreateCorridors(List <Room> relevantRooms) { var generatedEdges = new List <Tuple <Room, Room> >(); foreach (var node in finalGraph.nodes) { var roomFrom = GetRoomByPos(node.context, relevantRooms); foreach (var edge in node.edges) { var roomTo = GetRoomByPos(edge.to.context, relevantRooms); if (generatedEdges.Any(generatedEdge => generatedEdge.Item1.Equals(roomFrom) && generatedEdge.Item2.Equals(roomTo) || generatedEdge.Item1.Equals(roomTo) && generatedEdge.Item2.Equals(roomFrom))) { continue; } var midpoint = roomFrom.GetMidPointBetween(roomTo); var isHorAligned = midpoint.x > roomFrom.GetLeft() && midpoint.x <roomFrom.GetRight() && midpoint.x> roomTo.GetLeft() && midpoint.x < roomTo.GetRight(); var isVerAligned = midpoint.y > roomFrom.GetTop() && midpoint.y <roomFrom.GetBottom() && midpoint.y> roomTo.GetTop() && midpoint.y < roomTo.GetBottom(); generatedEdges.Add(new Tuple <Room, Room>(roomFrom, roomTo)); if (isHorAligned) { if (roomTo.GetTop() < roomFrom.GetTop()) { GridFiller.FillCorridor(grid, new Vector2(midpoint.x, roomTo.GetBottom()), new Vector2(midpoint.x, roomFrom.GetTop()), 3, Orientation.VERTICAL); } else { GridFiller.FillCorridor(grid, new Vector2(midpoint.x, roomFrom.GetBottom()), new Vector2(midpoint.x, roomTo.GetTop()), 3, Orientation.VERTICAL); } continue; } if (isVerAligned) { if (roomTo.GetLeft() < roomFrom.GetLeft()) { GridFiller.FillCorridor(grid, new Vector2(roomTo.GetRight(), midpoint.y), new Vector2(roomFrom.GetLeft(), midpoint.y), 3, Orientation.HORIZONTAL); } else { GridFiller.FillCorridor(grid, new Vector2(roomFrom.GetRight(), midpoint.y), new Vector2(roomTo.GetLeft(), midpoint.y), 3, Orientation.HORIZONTAL); } continue; } // RoomTo is BOTTOM-RIGHT if (roomTo.GetTop() > roomFrom.GetTop() && roomTo.GetLeft() > roomFrom.GetLeft()) { GridFiller.FillCorridor(grid, new Vector2(roomFrom.GetRight(), roomFrom.GetMidPoint().y), new Vector2(roomTo.GetMidPoint().x, roomFrom.GetMidPoint().y), 3, Orientation.HORIZONTAL); GridFiller.FillCorridor(grid, new Vector2(roomTo.GetMidPoint().x, roomFrom.GetMidPoint().y), new Vector2(roomTo.GetMidPoint().x, roomTo.GetTop()), 3, Orientation.VERTICAL); } // RoomTo is TOP-RIGHT if (roomTo.GetTop() < roomFrom.GetTop() && roomTo.GetLeft() > roomFrom.GetLeft()) { GridFiller.FillCorridor(grid, new Vector2(roomFrom.GetRight(), roomFrom.GetMidPoint().y), new Vector2(roomTo.GetMidPoint().x, roomFrom.GetMidPoint().y), 3, Orientation.HORIZONTAL); GridFiller.FillCorridor(grid, new Vector2(roomTo.GetMidPoint().x, roomFrom.GetMidPoint().y), new Vector2(roomTo.GetMidPoint().x, roomTo.GetBottom()), 3, Orientation.VERTICAL); } // RoomTo is BOTTOM-LEFT if (roomTo.GetTop() > roomFrom.GetTop() && roomTo.GetLeft() < roomFrom.GetLeft()) { GridFiller.FillCorridor(grid, new Vector2(roomFrom.GetLeft(), roomFrom.GetMidPoint().y), new Vector2(roomTo.GetMidPoint().x, roomFrom.GetMidPoint().y), 3, Orientation.HORIZONTAL); GridFiller.FillCorridor(grid, new Vector2(roomTo.GetMidPoint().x, roomFrom.GetMidPoint().y), new Vector2(roomTo.GetMidPoint().x, roomTo.GetTop()), 3, Orientation.VERTICAL); } // RoomTo is TOP-LEFT if (roomTo.GetTop() < roomFrom.GetTop() && roomTo.GetLeft() < roomFrom.GetLeft()) { GridFiller.FillCorridor(grid, new Vector2(roomFrom.GetLeft(), roomFrom.GetMidPoint().y), new Vector2(roomTo.GetMidPoint().x, roomFrom.GetMidPoint().y), 3, Orientation.HORIZONTAL); GridFiller.FillCorridor(grid, new Vector2(roomTo.GetMidPoint().x, roomFrom.GetMidPoint().y), new Vector2(roomTo.GetMidPoint().x, roomTo.GetBottom()), 3, Orientation.VERTICAL); } } } }