sdl2-life

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

commit 889bff0a6c0f70eb430bbbd7177a71f470df9e87
parent e83824ad11a0670b48ead2dcc5b26d1254281271
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Sat, 22 Apr 2023 16:40:48 -0700

Status for rotation of 90 and 270 is now working

Diffstat:
Mmain.go | 44+++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/main.go b/main.go @@ -311,7 +311,7 @@ func (g *LifeGame) InitializeCells() { g.age = 0 // Fill it with dead cells first - g.cells = make([][]*Cell, g.rows, g.columns) + g.cells = make([][]*Cell, g.rows) for y := 0; y < g.rows; y++ { for x := 0; x < g.columns; x++ { c := &Cell{x: x, y: y} @@ -747,6 +747,20 @@ func (g *LifeGame) DrawCell(c Cell) { y = int32(c.y*cfg.CellSize + 4 + g.font.Height()) } x = int32(c.x * cfg.CellSize) + } else if cfg.Rotate == 90 { + if cfg.StatusTop { + x = int32(c.x*cfg.CellSize + 4 + g.font.Height()) + } else { + x = int32(c.x * cfg.CellSize) + } + y = int32(c.y * cfg.CellSize) + } else if cfg.Rotate == 270 { + if cfg.StatusTop { + x = int32(c.x * cfg.CellSize) + } else { + x = int32(c.x*cfg.CellSize + 4 + g.font.Height()) + } + y = int32(c.y * cfg.CellSize) } if cfg.Border { @@ -826,6 +840,34 @@ func (g *LifeGame) UpdateStatus(status string) { log.Printf("Failed to copy texture: %s\n", err) return } + } else if cfg.Rotate == 90 { + var x int32 + if cfg.StatusTop { + x = int32(2 + h) + } else { + x = int32(cfg.Width) + } + + y := int32((cfg.Height - w) / 2) + rect := &sdl.Rect{x, y, int32(w), int32(h)} + if err = g.renderer.CopyEx(texture, nil, rect, 90.0, &sdl.Point{0, 0}, sdl.FLIP_HORIZONTAL|sdl.FLIP_VERTICAL); err != nil { + log.Printf("Failed to copy texture: %s\n", err) + return + } + } else if cfg.Rotate == 270 { + var x int32 + if cfg.StatusTop { + x = int32(cfg.Width) + } else { + x = int32(2 + h) + } + + y := int32((cfg.Height - w) / 2) + rect := &sdl.Rect{x, y, int32(w), int32(h)} + if err = g.renderer.CopyEx(texture, nil, rect, 90.0, &sdl.Point{0, 0}, sdl.FLIP_NONE); err != nil { + log.Printf("Failed to copy texture: %s\n", err) + return + } } }