diff --git a/game/state/machine/machine.go b/game/state/machine/machine.go index 06e8639..79e2ff1 100644 --- a/game/state/machine/machine.go +++ b/game/state/machine/machine.go @@ -32,17 +32,21 @@ func (m *Machine) Switch(name string) { } // Update ticks the current state, then applies any queued transition. -func (m *Machine) Update(delta float32) { +func (m *Machine) Update(delta float32) bool { if m.current == nil { - return + return false } m.current.Update(m, delta) if m.pending != "" { + if m.pending == "quit" { + return false + } next := m.pending m.pending = "" m.switchNow(next) } + return true } // Render proxies to current state. diff --git a/main.go b/main.go index f48c78a..9aa54d2 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,9 @@ func main() { // Enter game loop for !rl.WindowShouldClose() { audio.Update() - fsm.Update(rl.GetFrameTime()) + if !fsm.Update(rl.GetFrameTime()) { + break + } fsm.Render() } }