89 lines
2.5 KiB
Go
89 lines
2.5 KiB
Go
|
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)
|
||
|
}
|