sdl2-life

Conway's Game of Life with go-sdl2
git clone https://www.brianlane.com/git/sdl2-life
Log | Files | Refs | README

commit a30292b9e4f54db12558ddce2733a93e18736693
parent 3f40d05b5690e3f456a8dfc250dfdc07e5394fae
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Sat, 22 Apr 2023 15:14:53 -0700

Status at the top works for rotation 0

Diffstat:
Mmain.go | 38+++++++++++++++++++++++++++-----------
1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/main.go b/main.go @@ -731,12 +731,19 @@ func (g *LifeGame) Draw(status string) { // DrawCell draws a new cell on an empty background func (g *LifeGame) DrawCell(c Cell) { - x := int32(c.x * cfg.CellSize) - y := int32(c.y * cfg.CellSize) - if cfg.Border { - g.renderer.FillRect(&sdl.Rect{x + 1, y + 1, int32(cfg.CellSize - 2), int32(cfg.CellSize - 2)}) - } else { - g.renderer.FillRect(&sdl.Rect{x, y, int32(cfg.CellSize), int32(cfg.CellSize)}) + var y int32 + if cfg.Rotate == 0 { + if cfg.StatusTop { + y = int32(c.y*cfg.CellSize + 4 + g.font.Height()) + } else { + y = int32(c.y * cfg.CellSize) + } + x := int32(c.x * cfg.CellSize) + if cfg.Border { + g.renderer.FillRect(&sdl.Rect{x + 1, y + 1, int32(cfg.CellSize - 2), int32(cfg.CellSize - 2)}) + } else { + g.renderer.FillRect(&sdl.Rect{x, y, int32(cfg.CellSize), int32(cfg.CellSize)}) + } } } @@ -782,11 +789,20 @@ func (g *LifeGame) UpdateStatus(status string) { return } - x := int32((cfg.Width - w) / 2) - rect := &sdl.Rect{x, int32(cfg.Height - 2 - h), int32(w), int32(h)} - if err = g.renderer.Copy(texture, nil, rect); err != nil { - log.Printf("Failed to copy texture: %s\n", err) - return + if cfg.Rotate == 0 { + var y int32 + if cfg.StatusTop { + y = 2 + } else { + y = int32(cfg.Height - 2 - h) + } + + x := int32((cfg.Width - w) / 2) + rect := &sdl.Rect{x, y, int32(w), int32(h)} + if err = g.renderer.Copy(texture, nil, rect); err != nil { + log.Printf("Failed to copy texture: %s\n", err) + return + } } }