diff --git a/src/game.go b/src/game.go index ae10651..85c8556 100644 --- a/src/game.go +++ b/src/game.go @@ -10,7 +10,6 @@ type Game struct { CurrentScene SceneName Config *Config Scale float32 - Screen *ebiten.Image } func NewGame(config *Config, startscene SceneName) *Game { @@ -24,10 +23,10 @@ func NewGame(config *Config, startscene SceneName) *Game { // setup scene[s] game.CurrentScene = startscene game.Scenes[Play] = NewPlayScene(game, config) + game.Scenes[Toolbar] = NewToolbarScene(game, config) game.Scenes[Menu] = NewMenuScene(game, config) game.Scenes[Options] = NewOptionsScene(game, config) game.Scenes[Keybindings] = NewKeybindingsScene(game, config) - game.Scenes[Toolbar] = NewToolbarScene(game, config) // setup environment ebiten.SetWindowSize(game.ScreenWidth, game.ScreenHeight) @@ -35,7 +34,6 @@ func NewGame(config *Config, startscene SceneName) *Game { ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled) ebiten.SetScreenClearedEveryFrame(true) - game.Screen = ebiten.NewImage(game.ScreenWidth, game.ScreenHeight) return game } @@ -50,13 +48,18 @@ func (game *Game) Layout(outsideWidth, outsideHeight int) (int, int) { } func (game *Game) Update() error { - scene := game.GetCurrentScene() + for _, scene := range game.Scenes { + if scene.IsPrimary() { + if quit := scene.Update(); quit != nil { + return quit + } - if quit := scene.Update(); quit != nil { - return quit + } } + scene := game.GetCurrentScene() next := scene.GetNext() + if next != game.CurrentScene { game.Scenes[next].SetPrevious(game.CurrentScene) scene.ResetNext() @@ -77,6 +80,7 @@ func (game *Game) Draw(screen *ebiten.Image) { if current == game.CurrentScene { // avoid to redraw it in the next step skip = true + break } } } diff --git a/src/play.go b/src/play.go index 0b12496..5fb2b6c 100644 --- a/src/play.go +++ b/src/play.go @@ -19,7 +19,7 @@ type Images struct { } const ( - DEBUG_FORMAT = "FPS: %0.2f, TPG: %d, M: %0.2fMB, Generations: %d\nScale: %.02f, Zoom: %d, Cam: %.02f,%.02f Cursor: %d,%d %s" + DEBUG_FORMAT = "FPS: %0.2f, TPG: %d, M: %0.2fMB, Generations: %d\nScale: %.02f, Zoom: %d, Cam: %.02f,%.02f Cursor: %d,%d %s, UI Active: %t" ) type ScenePlay struct { @@ -485,10 +485,8 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) { scene.DrawDebug(screen) - op.GeoM.Reset() - op.GeoM.Translate(0, 0) - - scene.Game.Screen.DrawImage(screen, op) + // draw the toolbar directly from here, because otherwise it flickers + scene.Game.Scenes[Toolbar].Draw(screen) } func (scene *ScenePlay) DrawEvolution(screen *ebiten.Image, x, y int, op *ebiten.DrawImageOptions) { @@ -556,7 +554,7 @@ func (scene *ScenePlay) DrawDebug(screen *ebiten.Image) { scene.Game.Scale, scene.Camera.ZoomFactor, scene.Camera.Position[0], scene.Camera.Position[1], x, y, - paused) + paused, uiinput.UIActive) FontRenderer.Renderer.SetSizePx(10 + int(scene.Game.Scale*10)) FontRenderer.Renderer.SetTarget(screen)