1
0
Fork 0

feat(draw): add grid.DrawBlock()

This commit is contained in:
Henrik Hautakoski 2025-09-14 21:48:30 +02:00
parent 656487903e
commit 4dd6d93653

View file

@ -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))
}
}
}