From 4dd6d936535e9e39d09b365d9ae005c4a9ddefb5 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 14 Sep 2025 21:48:30 +0200 Subject: [PATCH] feat(draw): add grid.DrawBlock() --- game/draw/grid/grid.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/game/draw/grid/grid.go b/game/draw/grid/grid.go index 3a6fe83..b5775c2 100644 --- a/game/draw/grid/grid.go +++ b/game/draw/grid/grid.go @@ -32,23 +32,21 @@ func DrawBackground(pos rl.Vector2, grid Grid, col color.RGBA, border_size int32 }, col, border_size, border_col) } -func Draw(pos rl.Vector2, grid Grid) { - // offset for background. - pos.X = pos.X + CELL_SPACING - pos.Y = pos.Y + CELL_SPACING - - cell := rl.Rectangle{ - X: 0, - Y: 0, +func DrawBlock(pos rl.Vector2, x, y byte, tile graphics.Tile) { + dest := rl.Rectangle{ + X: float32(int32(pos.X) + (int32(x) * (CELL_SIZE + CELL_SPACING)) + CELL_SPACING), + Y: float32(int32(pos.Y) + (int32(y) * (CELL_SIZE + CELL_SPACING)) + CELL_SPACING), Width: float32(CELL_SIZE), Height: float32(CELL_SIZE), } - for y := range grid.Height() { - for x := range grid.Width() { - cell.X = float32(int32(pos.X) + (x * (CELL_SIZE + CELL_SPACING))) - cell.Y = float32(int32(pos.Y) + (y * (CELL_SIZE + CELL_SPACING))) - render.DrawTextureRec(grid.Tile(byte(x), byte(y)).GetTexRect(), cell) + render.DrawTextureRec(tile.GetTexRect(), dest) +} + +func Draw(pos rl.Vector2, grid Grid) { + for y := range byte(grid.Height()) { + for x := range byte(grid.Width()) { + DrawBlock(pos, x, y, grid.Tile(x, y)) } } }