48 lines
1004 B
Go
48 lines
1004 B
Go
|
package src
|
||
|
|
||
|
import . "git.danitheskunk.com/squishy/blooblib"
|
||
|
|
||
|
type CellState uint8
|
||
|
|
||
|
const (
|
||
|
Empty = CellState(0)
|
||
|
Black = CellState(1)
|
||
|
White = CellState(2)
|
||
|
)
|
||
|
|
||
|
type BoardState struct {
|
||
|
tilemap *Tilemap
|
||
|
}
|
||
|
|
||
|
var tilesStones []*Image
|
||
|
|
||
|
func NewBoardState() *BoardState {
|
||
|
if tilesStones == nil {
|
||
|
tilesStones = LoadImage("assets/stones.png").MakeTileset(Vec2i{X: 16, Y: 16})
|
||
|
}
|
||
|
|
||
|
return &BoardState{tilemap: NewTilemap(Vec2i{X: 19, Y: 19}, tilesStones)}
|
||
|
}
|
||
|
|
||
|
func (bs *BoardState) Get(pos Vec2i) CellState {
|
||
|
if pos.X < 0 || pos.Y < 0 || pos.X >= 19 || pos.Y >= 19 {
|
||
|
panic("boardstate out of bounds")
|
||
|
}
|
||
|
return CellState(bs.tilemap.Get(pos))
|
||
|
}
|
||
|
|
||
|
func (bs *BoardState) Set(pos Vec2i, val CellState) {
|
||
|
if pos.X < 0 || pos.Y < 0 || pos.X >= 19 || pos.Y >= 19 {
|
||
|
panic("boardstate out of bounds")
|
||
|
}
|
||
|
bs.tilemap.Set(pos, int(val))
|
||
|
}
|
||
|
|
||
|
func (bs *BoardState) Clear() {
|
||
|
bs.tilemap.Clear(int(Empty))
|
||
|
}
|
||
|
|
||
|
func (bs *BoardState) Draw(target *Image) {
|
||
|
target.DrawTilemap(bs.tilemap, Vec2i{X: 10 * 16, Y: 1 * 16})
|
||
|
}
|