mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Draw room connections
This commit is contained in:
parent
bbdba6ae6d
commit
1e6c7e7f4e
2 changed files with 47 additions and 0 deletions
|
|
@ -74,6 +74,8 @@ public partial class RogueliteRoomManager : Node2D
|
|||
|
||||
private List<Vector2I> _mainPath = new();
|
||||
private List<RoomConnection> _connections = new();
|
||||
|
||||
public List<RoomConnection> Connections => _connections;
|
||||
|
||||
private void GenerateStraightLineDungeon()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ public partial class Minimap : CanvasLayer
|
|||
|
||||
private List<RogueliteRoom> SpawnedRooms => RoomManager.SpawnedRooms;
|
||||
|
||||
private List<RoomConnection> Connections => RoomManager.Connections;
|
||||
|
||||
[Export] public int CellSize { get; private set; } = 16;
|
||||
[Export] public Vector2 Padding { get; private set; } = new Vector2(20, 20);
|
||||
|
||||
|
|
@ -89,6 +91,49 @@ public partial class Minimap : CanvasLayer
|
|||
|
||||
RenderingServer.CanvasItemAddRect(_canvasItemRid, new Rect2(drawPos, drawSize), color);
|
||||
}
|
||||
|
||||
DrawRoomConnections( Connections, min, offset);
|
||||
}
|
||||
|
||||
private void DrawRoomConnections(List<RoomConnection> connections, Vector2I minGrid, Vector2 baseOffset)
|
||||
{
|
||||
foreach (var connection in connections)
|
||||
{
|
||||
// Skip if either room is missing
|
||||
if (!RoomGrid.ContainsKey(connection.From) || !RoomGrid.ContainsKey(connection.To))
|
||||
continue;
|
||||
|
||||
// // Calculate center positions of each room
|
||||
// Vector2 from = baseOffset + ((connection.From - minGrid) * (CellSize + (int)Separation)) + new Vector2(CellSize / 2f, CellSize / 2f);
|
||||
// Vector2 to = baseOffset + ((connection.To - minGrid) * (CellSize + (int)Separation)) + new Vector2(CellSize / 2f, Separation / 2f);
|
||||
|
||||
// Get relative positions of the two rooms
|
||||
Vector2 fromPos = baseOffset + ((connection.From - minGrid) * (CellSize + (int)Separation));
|
||||
Vector2 toPos = baseOffset + ((connection.To - minGrid) * (CellSize + (int)Separation));
|
||||
|
||||
// Determine direction between rooms (assumes adjacent rooms only)
|
||||
Vector2 delta = (toPos - fromPos).Normalized();
|
||||
|
||||
// Midpoint between rooms, where the gap is
|
||||
Vector2 gapCenter = (fromPos + toPos) * 0.5f + new Vector2(CellSize / 2f, CellSize / 2f);
|
||||
|
||||
// Calculate endpoints of the connection line (centered in gap)
|
||||
Vector2 halfGap = delta * (Separation / 2f);
|
||||
Vector2 lineStart = gapCenter - halfGap;
|
||||
Vector2 lineEnd = gapCenter + halfGap;
|
||||
|
||||
// Pick color based on type
|
||||
Color color = Colors.White;
|
||||
if (connection.IsSecret)
|
||||
color = Colors.Purple;
|
||||
else if (connection.IsLocked)
|
||||
color = Colors.Orange;
|
||||
|
||||
float thickness = 1f;
|
||||
|
||||
// Draw the line
|
||||
RenderingServer.CanvasItemAddLine(_canvasItemRid, lineStart, lineEnd, color, thickness);
|
||||
}
|
||||
}
|
||||
|
||||
private Color GetColorForRoomType(RoomType type)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue