Dungeon Builder p5

This commit is contained in:
dingo
2025-12-28 13:07:07 -05:00
parent ac03b07bea
commit 1355416b74
2 changed files with 72 additions and 10 deletions
+35 -9
View File
@@ -290,11 +290,17 @@ public class DungeonGeneratorV2
if (worldX >= 0 && worldX < MapWidth && worldY >= 0 && worldY < MapHeight)
{
layout.Tiles[worldX, worldY] = p.TileDefinitionId;
// Look up tile definition for sheet info
var tileDef = _tileDefinitions.GetValueOrDefault(p.TileDefinitionId);
layout.TileDetails.Add(new PlacedTile
{
X = worldX,
Y = worldY,
TileDefinitionId = p.TileDefinitionId,
SheetId = tileDef?.TileMapSheetId ?? 0,
FrameIndex = tileDef?.FrameIndex ?? 0,
Layer = p.Layer,
Rotation = p.Rotation,
FlipX = p.FlipX,
@@ -360,12 +366,14 @@ public class DungeonGeneratorV2
{
layout.Tiles[x, y] = floorId > 0 ? floorId : 1; // 1 = walkable but no visual
if (floorId > 0)
if (floorId > 0 && floorTile != null)
{
layout.TileDetails.Add(new PlacedTile
{
X = x, Y = y,
TileDefinitionId = floorId,
SheetId = floorTile.TileMapSheetId,
FrameIndex = floorTile.FrameIndex,
Layer = 0
});
}
@@ -386,21 +394,23 @@ public class DungeonGeneratorV2
var floorTile = _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
int floorId = floorTile?.Id ?? 1;
int sheetId = floorTile?.TileMapSheetId ?? 0;
int frameIndex = floorTile?.FrameIndex ?? 0;
// L-shaped corridor
if (_rng.Next(2) == 0)
{
CarveHorizontalCorridor(layout, x, targetX, y, floorId);
CarveVerticalCorridor(layout, y, targetY, targetX, floorId);
CarveHorizontalCorridor(layout, x, targetX, y, floorId, sheetId, frameIndex);
CarveVerticalCorridor(layout, y, targetY, targetX, floorId, sheetId, frameIndex);
}
else
{
CarveVerticalCorridor(layout, y, targetY, x, floorId);
CarveHorizontalCorridor(layout, x, targetX, targetY, floorId);
CarveVerticalCorridor(layout, y, targetY, x, floorId, sheetId, frameIndex);
CarveHorizontalCorridor(layout, x, targetX, targetY, floorId, sheetId, frameIndex);
}
}
private void CarveHorizontalCorridor(DungeonLayoutV2 layout, int x1, int x2, int y, int floorId)
private void CarveHorizontalCorridor(DungeonLayoutV2 layout, int x1, int x2, int y, int floorId, int sheetId, int frameIndex)
{
int minX = Math.Min(x1, x2);
int maxX = Math.Max(x1, x2);
@@ -415,14 +425,21 @@ public class DungeonGeneratorV2
layout.Tiles[x, ty] = floorId;
if (floorId > 1)
{
layout.TileDetails.Add(new PlacedTile { X = x, Y = ty, TileDefinitionId = floorId, Layer = 0 });
layout.TileDetails.Add(new PlacedTile
{
X = x, Y = ty,
TileDefinitionId = floorId,
SheetId = sheetId,
FrameIndex = frameIndex,
Layer = 0
});
}
}
}
}
}
private void CarveVerticalCorridor(DungeonLayoutV2 layout, int y1, int y2, int x, int floorId)
private void CarveVerticalCorridor(DungeonLayoutV2 layout, int y1, int y2, int x, int floorId, int sheetId, int frameIndex)
{
int minY = Math.Min(y1, y2);
int maxY = Math.Max(y1, y2);
@@ -437,7 +454,14 @@ public class DungeonGeneratorV2
layout.Tiles[tx, y] = floorId;
if (floorId > 1)
{
layout.TileDetails.Add(new PlacedTile { X = tx, Y = y, TileDefinitionId = floorId, Layer = 0 });
layout.TileDetails.Add(new PlacedTile
{
X = tx, Y = y,
TileDefinitionId = floorId,
SheetId = sheetId,
FrameIndex = frameIndex,
Layer = 0
});
}
}
}
@@ -545,6 +569,8 @@ public class PlacedTile
public int X { get; set; }
public int Y { get; set; }
public int TileDefinitionId { get; set; }
public int SheetId { get; set; } // For client rendering
public int FrameIndex { get; set; } // Frame in the sheet
public int Layer { get; set; }
public int Rotation { get; set; }
public bool FlipX { get; set; }