Initial commit
This commit is contained in:
commit
0245a5cb43
22 changed files with 610 additions and 0 deletions
47
game/draw/grid/grid.go
Normal file
47
game/draw/grid/grid.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue