sdl2-life

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

commit 38b4c9d891c862d6678aa319b431f3e4cc23ff75
parent 3c81880178bc6b444995beaad2d7f716fc40f834
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Sun, 10 Nov 2019 16:25:14 -0800

Slow down the frame rate

Diffstat:
Mmain.go | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/main.go b/main.go @@ -213,8 +213,8 @@ func (g *LifeGame) UpdateCell(x, y int, erase bool) { g.renderer.Present() } -// NextTic executes the next screen of the game -func (g *LifeGame) NextTic() { +// NextFrame executes the next screen of the game +func (g *LifeGame) NextFrame() { if g.pause { return } @@ -244,6 +244,7 @@ func (g *LifeGame) NextTic() { // Run executes the main loop of the game // it handles user input and updating the display at the selected update rate func (g *LifeGame) Run() { + fpsTime := sdl.GetTicks() g.Draw() running := true @@ -270,7 +271,10 @@ func (g *LifeGame) Run() { } } } - g.NextTic() + if sdl.GetTicks() > fpsTime+(1000/fps) { + g.NextFrame() + fpsTime = sdl.GetTicks() + } } }