From 3cf9d572778e9fd1f9d56c77ac51bbe3fbc11592 Mon Sep 17 00:00:00 2001 From: squishy Date: Sat, 23 Mar 2024 08:10:26 +0000 Subject: [PATCH] added tile constants, added BoardState --- assets/goban.png | Bin 0 -> 503 bytes assets/stones.png | Bin 0 -> 334 bytes main.go | 63 ++----------------------------- src/boardstate.go | 47 +++++++++++++++++++++++ src/game.go | 28 ++++++++++++++ src/gobanrenderer.go | 88 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 167 insertions(+), 59 deletions(-) create mode 100644 assets/goban.png create mode 100644 assets/stones.png create mode 100644 src/boardstate.go create mode 100644 src/game.go create mode 100644 src/gobanrenderer.go diff --git a/assets/goban.png b/assets/goban.png new file mode 100644 index 0000000000000000000000000000000000000000..69becc3477419976076f1cdbec7eedc7ee5931e3 GIT binary patch literal 503 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!7>k44ofy`glX(f`90>3Uab;uU z5D^fz7FR76*WIF^b>B|;R~FaL#nS(;I{yFTaP3pdoZHTk2Tes5=t))CsRUUIDJY1T zq-ew(QJH^F;o9+Ke{TQ(|Nr0T1HZ2A__|>Fi>%^3Ub8E$8XSy+Rg_GWWTcF=H3}WA zcbB@~UXuLf(wtilUTxlav3v6R+|pjJkR)SEM<*5IXhVy>prBo)SueLPe*EnJ&i%hz zW?P-bd|49Y z7t8>33MD{Td!8ZCteKuJjv*1PZ?72gH7M|~22^vU9d7t;ztFq&g4oOcSu0+~^R(Km z5}MYMdRFGq^GQZi81h&;UI;mqaELC5l$h|8tz#|Qvq2Y#?AEcoxlQ0Ji5FrV?< z?+0hs3pg+^Ivh}Ay3g)>U?zhcLR8-3_pCM|Y{_n;j$qBY!KFb{t q6F4BEa6ri5fPjMox5fe%z4xKdq_!)hmJ0zL$>8bg=d#Wzp$P!2)$(@$ literal 0 HcmV?d00001 diff --git a/assets/stones.png b/assets/stones.png new file mode 100644 index 0000000000000000000000000000000000000000..9a7ba488f2af88a81705629c8615f20f368f55bc GIT binary patch literal 334 zcmV-U0kQsxP)Px$2uVaiR9J=Wmq7}HFc3vYD1{!Nu0_NXcmkI>aF(9H6BLoI+XEE3v8$mWj&Wj> zI0fHwNSyzFMu`9i2YZsmdT>=XlU*Cep55Ku5pEk;a$#G004NspR+Zt5L5RL8sM6Evrd_?#RGf|*oLG`VlWY$leaNL zbcJWu&6*kFUj2gy=!44u_3GG2n8MTE0&F%TvYCAQ4`Uzh8;ByfYpIFhnn3ZM@}dy!9_Yelel5hc@KW~|`6seuLek_R gV*iEzeg6TI509A5tv!M?1ONa407*qoM6N<$f`mPfTL1t6 literal 0 HcmV?d00001 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) +}