diff --git a/assets/goban.png b/assets/goban.png new file mode 100644 index 0000000..69becc3 Binary files /dev/null and b/assets/goban.png differ diff --git a/assets/stones.png b/assets/stones.png new file mode 100644 index 0000000..9a7ba48 Binary files /dev/null and b/assets/stones.png differ diff --git a/main.go b/main.go index 7dc067e..6e23c89 100644 --- a/main.go +++ b/main.go @@ -1,64 +1,9 @@ package main -import . "git.danitheskunk.com/squishy/blooblib" - -type Game struct { - tilemap *Tilemap -} - -func (g *Game) Init(settings *Settings) { - settings.Title = "Goo v0.0" - - tiles := LoadImage("go.png").MakeTileset(Vec2i{X: 16, Y: 16}) - g.tilemap = NewTilemap(Vec2i{X: 40, Y: 23}, tiles) - g.tilemap.Clear(16) - for y := 0; y < 19; y += 1 { - for x := 0; x < 19; x += 1 { - g.tilemap.Set(Vec2i{X: 10 + x, Y: 1 + y}, 3) - } - g.tilemap.Set(Vec2i{X: 10, Y: 1 + y}, 11) - g.tilemap.Set(Vec2i{X: 28, Y: 1 + y}, 12) - } - - for x := 0; x < 19; x += 1 { - g.tilemap.Set(Vec2i{X: 10 + x, Y: 1}, 9) - g.tilemap.Set(Vec2i{X: 10 + x, Y: 19}, 10) - g.tilemap.Set(Vec2i{X: 10 + x, Y: 20}, 17) - g.tilemap.Set(Vec2i{X: 10 + x, Y: 21}, 18) - } - - for y := 0; y < 21; y += 1 { - g.tilemap.Set(Vec2i{X: 29, Y: 1 + y}, 19) - } - g.tilemap.Set(Vec2i{X: 10, Y: 21}, 20) - g.tilemap.Set(Vec2i{X: 29, Y: 1}, 21) - - g.tilemap.Set(Vec2i{X: 10, Y: 1}, 5) - g.tilemap.Set(Vec2i{X: 28, Y: 1}, 6) - g.tilemap.Set(Vec2i{X: 10, Y: 19}, 7) - g.tilemap.Set(Vec2i{X: 28, Y: 19}, 8) - - g.tilemap.Set(Vec2i{X: 13, Y: 4}, 4) - g.tilemap.Set(Vec2i{X: 25, Y: 4}, 4) - g.tilemap.Set(Vec2i{X: 13, Y: 16}, 4) - g.tilemap.Set(Vec2i{X: 25, Y: 16}, 4) - g.tilemap.Set(Vec2i{X: 13, Y: 10}, 4) - g.tilemap.Set(Vec2i{X: 13, Y: 16}, 4) - g.tilemap.Set(Vec2i{X: 25, Y: 10}, 4) - g.tilemap.Set(Vec2i{X: 25, Y: 16}, 4) - g.tilemap.Set(Vec2i{X: 19, Y: 4}, 4) - g.tilemap.Set(Vec2i{X: 19, Y: 10}, 4) - g.tilemap.Set(Vec2i{X: 19, Y: 16}, 4) -} - -func (g *Game) Render(screen *Image) { - screen.DrawTilemap(g.tilemap, Vec2i{}) - screen.Draw(g.tilemap.Tileset[2], Vec2i{X: 16 * 25, Y: 16 * 4}) - screen.Draw(g.tilemap.Tileset[1], Vec2i{X: 16 * 13, Y: 16 * 16}) -} - -func (g *Game) Update() { -} +import ( + . "git.danitheskunk.com/squishy/blooblib" + . "git.danitheskunk.com/squishy/goo/src" +) func main() { Run(&Game{}) diff --git a/src/boardstate.go b/src/boardstate.go new file mode 100644 index 0000000..5ea01b9 --- /dev/null +++ b/src/boardstate.go @@ -0,0 +1,47 @@ +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}) +} diff --git a/src/game.go b/src/game.go new file mode 100644 index 0000000..6c4614d --- /dev/null +++ b/src/game.go @@ -0,0 +1,28 @@ +package src + +import ( + . "git.danitheskunk.com/squishy/blooblib" +) + +type Game struct { + gobanRenderer *GobanRenderer + boardState *BoardState +} + +func (g *Game) Init(settings *Settings) { + settings.Title = "Goo v0.0" + g.boardState = NewBoardState() + g.gobanRenderer = NewGobanRenderer(g.boardState) + + g.boardState.Set(Vec2i{X:3,Y:3}, Black) +} + +func (g *Game) Render(screen *Image) { + g.gobanRenderer.Render(screen) + //screen.DrawTilemap(g.tilemap, Vec2i{}) + //screen.Render(g.tilemap.Tileset[2], Vec2i{X: 16 * 25, Y: 16 * 4}) + //screen.Render(g.tilemap.Tileset[1], Vec2i{X: 16 * 13, Y: 16 * 16}) +} + +func (g *Game) Update() { +} diff --git a/src/gobanrenderer.go b/src/gobanrenderer.go new file mode 100644 index 0000000..0fb01b6 --- /dev/null +++ b/src/gobanrenderer.go @@ -0,0 +1,88 @@ +package src + +import . "git.danitheskunk.com/squishy/blooblib" + +type GobanRenderer struct { + tilemap *Tilemap + boardState *BoardState +} + +const ( + tileBoardTopLeft = 0 + tileBoardTopRight = 2 + tileBoardBottomLeft = 8 + tileBoardBottomRight = 10 + tileBoardTop = 1 + tileBoardBottom = 9 + tileBoardLeft = 4 + tileBoardRight = 6 + tileBoard = 5 + tileBoardStar = 3 + tileBg = 12 + tileBottomOfBoard1 = 7 + tileBottomOfBoard2 = 11 + tileRightOfBoard = 13 + tileBottomLeftOfBoard = 14 + tileTopRightOfBoard = 15 + tileStoneBlack = 0 + tileStoneWhite = 1 + tileStoneBlackHalf = 2 + tileStoneWhiteHalf = 3 +) + +var tilesGoban []*Image + +func NewGobanRenderer(boardState *BoardState) *GobanRenderer { + if tilesGoban == nil { + tilesGoban = LoadImage("assets/goban.png").MakeTileset(Vec2i{X: 16, Y: 16}) + } + + tilemap := NewTilemap(Vec2i{X: 40, Y: 23}, tilesGoban) + tilemap.Clear(tileBg) + + for y := 0; y < 19; y += 1 { + for x := 0; x < 19; x += 1 { + tilemap.Set(Vec2i{X: 10 + x, Y: 1 + y}, tileBoard) + } + tilemap.Set(Vec2i{X: 10, Y: 1 + y}, tileBoardLeft) + tilemap.Set(Vec2i{X: 28, Y: 1 + y}, tileBoardRight) + } + + for x := 0; x < 19; x += 1 { + tilemap.Set(Vec2i{X: 10 + x, Y: 1}, tileBoardTop) + tilemap.Set(Vec2i{X: 10 + x, Y: 19}, tileBoardBottom) + + tilemap.Set(Vec2i{X: 10 + x, Y: 20}, tileBottomOfBoard1) + tilemap.Set(Vec2i{X: 10 + x, Y: 21}, tileBottomOfBoard2) + } + + for y := 0; y < 21; y += 1 { + tilemap.Set(Vec2i{X: 29, Y: 1 + y}, tileRightOfBoard) + } + tilemap.Set(Vec2i{X: 10, Y: 21}, tileBottomLeftOfBoard) + tilemap.Set(Vec2i{X: 29, Y: 1}, tileTopRightOfBoard) + + tilemap.Set(Vec2i{X: 10, Y: 1}, tileBoardTopLeft) + tilemap.Set(Vec2i{X: 28, Y: 1}, tileBoardTopRight) + tilemap.Set(Vec2i{X: 10, Y: 19}, tileBoardBottomLeft) + tilemap.Set(Vec2i{X: 28, Y: 19}, tileBoardBottomRight) + + tilemap.Set(Vec2i{X: 13, Y: 4}, tileBoardStar) + tilemap.Set(Vec2i{X: 25, Y: 4}, tileBoardStar) + tilemap.Set(Vec2i{X: 13, Y: 16}, tileBoardStar) + tilemap.Set(Vec2i{X: 25, Y: 16}, tileBoardStar) + tilemap.Set(Vec2i{X: 13, Y: 10}, tileBoardStar) + tilemap.Set(Vec2i{X: 13, Y: 16}, tileBoardStar) + tilemap.Set(Vec2i{X: 25, Y: 10}, tileBoardStar) + tilemap.Set(Vec2i{X: 25, Y: 16}, tileBoardStar) + tilemap.Set(Vec2i{X: 19, Y: 4}, tileBoardStar) + tilemap.Set(Vec2i{X: 19, Y: 10}, tileBoardStar) + tilemap.Set(Vec2i{X: 19, Y: 16}, tileBoardStar) + + return &GobanRenderer{tilemap: tilemap, boardState: boardState} +} + +func (gr *GobanRenderer) Render(target *Image) { + target.DrawTilemap(gr.tilemap, Vec2i{}) + gr.boardState.Draw(target) +}