added tile constants, added BoardState

This commit is contained in:
Squishy Bloob 2024-03-23 08:10:26 +00:00
parent f82ddece02
commit 3cf9d57277
6 changed files with 167 additions and 59 deletions

BIN
assets/goban.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 503 B

BIN
assets/stones.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

63
main.go
View File

@ -1,64 +1,9 @@
package main package main
import . "git.danitheskunk.com/squishy/blooblib" import (
. "git.danitheskunk.com/squishy/blooblib"
type Game struct { . "git.danitheskunk.com/squishy/goo/src"
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() {
}
func main() { func main() {
Run(&Game{}) Run(&Game{})

47
src/boardstate.go Normal file
View File

@ -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})
}

28
src/game.go Normal file
View File

@ -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() {
}

88
src/gobanrenderer.go Normal file
View File

@ -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)
}