first commit

This commit is contained in:
2026-09-19 17:24:02 +08:00
commit afb343aa49
109 changed files with 13011 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
namespace OSM.Client.World;
public partial class GreyboxMap2D : Node2D
{
[Export]
public Vector2I MapSize { get; set; } = new(16, 12);
[Export]
public Vector2 CellSize { get; set; } = new(128, 64);
public override void _Ready()
{
QueueRedraw();
}
public void SetMapSize(Vector2I mapSize)
{
MapSize = mapSize;
QueueRedraw();
}
public override void _Draw()
{
for (var y = 0; y < MapSize.Y; y++)
{
for (var x = 0; x < MapSize.X; x++)
{
var center = GridProjector.GridToScreen(new Vector2I(x, y), CellSize.X, CellSize.Y);
var points = Diamond(center);
var checker = (x + y) % 2 == 0;
var fill = checker
? new Color("273746")
: new Color("22313f");
DrawColoredPolygon(points, fill);
}
}
DrawCover(new Vector2I(5, 4), new Color("526777"));
DrawCover(new Vector2I(6, 4), new Color("526777"));
DrawCover(new Vector2I(10, 7), new Color("705d54"));
DrawCover(new Vector2I(11, 7), new Color("705d54"));
}
private Vector2[] Diamond(Vector2 center)
{
var halfWidth = CellSize.X * 0.5f;
var halfHeight = CellSize.Y * 0.5f;
return
[
center + new Vector2(0, -halfHeight),
center + new Vector2(halfWidth, 0),
center + new Vector2(0, halfHeight),
center + new Vector2(-halfWidth, 0)
];
}
private void DrawCover(Vector2I grid, Color color)
{
var center = GridProjector.GridToScreen(grid, CellSize.X, CellSize.Y);
var top = center + new Vector2(0, -28);
var basePoints = Diamond(center);
var topPoints = Diamond(top);
DrawColoredPolygon(
[
basePoints[1], basePoints[2], topPoints[2], topPoints[1]
], color.Darkened(0.25f));
DrawColoredPolygon(
[
basePoints[2], basePoints[3], topPoints[3], topPoints[2]
], color.Darkened(0.4f));
DrawColoredPolygon(topPoints, color);
}
}