feat: add game/grid.go
This commit is contained in:
parent
6e21b1fcb2
commit
2a84c7bf6a
1 changed files with 32 additions and 0 deletions
32
game/grid.go
Normal file
32
game/grid.go
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package game
|
||||||
|
|
||||||
|
import (
|
||||||
|
"tetris/engine/graphics"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
GRID_WIDTH = 10
|
||||||
|
GRID_HEIGHT = 16
|
||||||
|
)
|
||||||
|
|
||||||
|
type Grid [GRID_WIDTH * GRID_HEIGHT]Block
|
||||||
|
|
||||||
|
func (Grid) Width() int32 {
|
||||||
|
return GRID_WIDTH
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Grid) Height() int32 {
|
||||||
|
return GRID_HEIGHT
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g Grid) At(x, y byte) Block {
|
||||||
|
return g[uint16(x)+(uint16(y)*GRID_WIDTH)]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g Grid) Tile(x, y byte) graphics.Tile {
|
||||||
|
return g.At(x, y).Tile()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Grid) Set(x, y byte, c Block) {
|
||||||
|
(*g)[uint16(x)+(uint16(y)*GRID_WIDTH)] = c
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue