47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package grid
|
|
|
|
import (
|
|
"image/color"
|
|
|
|
"tetris/engine/render"
|
|
|
|
rl "github.com/gen2brain/raylib-go/raylib"
|
|
)
|
|
|
|
const (
|
|
// How many pixels wide and tall each cell is.
|
|
CELL_SIZE = 32
|
|
|
|
// Number of pixels between each cell
|
|
CELL_SPACING = 1
|
|
)
|
|
|
|
func DrawBackground(rect rl.RectangleInt32, col color.RGBA, border_size int32, border_col color.RGBA) {
|
|
render.DrawRectBorder(rl.RectangleInt32{
|
|
X: int32(rect.X),
|
|
Y: int32(rect.Y),
|
|
Width: int32((rect.Width * (CELL_SIZE + CELL_SPACING)) + CELL_SPACING),
|
|
Height: int32((rect.Height * (CELL_SIZE + CELL_SPACING)) + CELL_SPACING),
|
|
}, col, border_size, border_col)
|
|
}
|
|
|
|
func Draw(rect rl.RectangleInt32) {
|
|
// offset for background.
|
|
rect.X = rect.X + CELL_SPACING
|
|
rect.Y = rect.Y + CELL_SPACING
|
|
|
|
cell := rl.Rectangle{
|
|
X: 0,
|
|
Y: 0,
|
|
Width: float32(CELL_SIZE),
|
|
Height: float32(CELL_SIZE),
|
|
}
|
|
|
|
for y := range rect.Height {
|
|
for x := range rect.Width {
|
|
cell.X = float32(rect.X + (x * (CELL_SIZE + CELL_SPACING)))
|
|
cell.Y = float32(rect.Y + (y * (CELL_SIZE + CELL_SPACING)))
|
|
rl.DrawRectangleRec(cell, rl.Black)
|
|
}
|
|
}
|
|
}
|