sdl2-life

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

commit e83824ad11a0670b48ead2dcc5b26d1254281271
parent a30292b9e4f54db12558ddce2733a93e18736693
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Sat, 22 Apr 2023 15:25:59 -0700

Status at top and bottom works for rotation 180

Diffstat:
Mmain.go | 33++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/main.go b/main.go @@ -731,19 +731,28 @@ func (g *LifeGame) Draw(status string) { // DrawCell draws a new cell on an empty background func (g *LifeGame) DrawCell(c Cell) { - var y int32 + var x, 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)}) + x = int32(c.x * cfg.CellSize) + } else if cfg.Rotate == 180 { + // Invert top and bottom + if cfg.StatusTop { + y = int32(c.y * cfg.CellSize) } else { - g.renderer.FillRect(&sdl.Rect{x, y, int32(cfg.CellSize), int32(cfg.CellSize)}) + y = int32(c.y*cfg.CellSize + 4 + g.font.Height()) } + 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)}) } } @@ -803,6 +812,20 @@ func (g *LifeGame) UpdateStatus(status string) { log.Printf("Failed to copy texture: %s\n", err) return } + } else if cfg.Rotate == 180 { + var y int32 + if cfg.StatusTop { + y = int32(cfg.Height - 2 - h) + } else { + y = 2 + } + + x := int32((cfg.Width - w) / 2) + rect := &sdl.Rect{x, y, int32(w), int32(h)} + if err = g.renderer.CopyEx(texture, nil, rect, 0.0, nil, sdl.FLIP_HORIZONTAL|sdl.FLIP_VERTICAL); err != nil { + log.Printf("Failed to copy texture: %s\n", err) + return + } } }