Cell ofssets

This commit is contained in:
Marco 2025-04-15 17:28:03 +02:00
commit 13ac8e4f2f
5 changed files with 136 additions and 17 deletions

View file

@ -97,28 +97,35 @@ public partial class Minimap : CanvasLayer
private void DrawRoomConnections(List<RoomConnection> connections, Vector2I minGrid, Vector2 baseOffset)
{
int spacing = (int)Separation;
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));
// Convert grid coordinates to local minimap grid (relative to min)
Vector2I fromGrid = connection.From - minGrid;
Vector2I toGrid = connection.To - minGrid;
// Determine direction between rooms (assumes adjacent rooms only)
Vector2 delta = (toPos - fromPos).Normalized();
// Center of the From cell in pixels
Vector2 fromCenter = baseOffset
+ fromGrid * (CellSize + spacing)
+ new Vector2(CellSize / 2f, CellSize / 2f);
// Midpoint between rooms, where the gap is
Vector2 gapCenter = (fromPos + toPos) * 0.5f + new Vector2(CellSize / 2f, CellSize / 2f);
// Center of the To cell in pixels
Vector2 toCenter = baseOffset
+ toGrid * (CellSize + spacing)
+ new Vector2(CellSize / 2f, CellSize / 2f);
// The gap center between rooms
Vector2 gapCenter = (fromCenter + toCenter) * 0.5f;
// Short line inside the separation gap
Vector2 delta = (toCenter - fromCenter).Normalized();
Vector2 halfGap = delta * (spacing / 2f);
// Calculate endpoints of the connection line (centered in gap)
Vector2 halfGap = delta * (Separation / 2f);
Vector2 lineStart = gapCenter - halfGap;
Vector2 lineEnd = gapCenter + halfGap;