2024-03-25 04:03:53 +01:00
|
|
|
package goo
|
2024-03-23 09:10:26 +01:00
|
|
|
|
|
|
|
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})
|
|
|
|
}
|
2024-03-23 13:54:00 +01:00
|
|
|
|
|
|
|
func (bs *BoardState) DrawHover(target *Image, pos Vec2i, player CellState) {
|
|
|
|
if bs.Get(pos) == Empty {
|
|
|
|
switch player {
|
|
|
|
case Black:
|
|
|
|
target.Draw(tilesStones[tileStoneBlackHalf], Vec2i{X: (10 + pos.X) * 16, Y: (1 + pos.Y) * 16})
|
|
|
|
break
|
|
|
|
case White:
|
|
|
|
target.Draw(tilesStones[tileStoneWhiteHalf], Vec2i{X: (10 + pos.X) * 16, Y: (1 + pos.Y) * 16})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|