doodle/scene.go

32 lines
791 B
Go
Raw Permalink Normal View History

2018-06-21 01:43:14 +00:00
package doodle
import "git.kirsle.net/apps/doodle/events"
2018-06-21 01:43:14 +00:00
// Scene is an abstraction for a game mode in Doodle. The app points to one
// scene at a time and that scene has control over the main loop, and its own
// state information.
type Scene interface {
2018-06-21 02:00:46 +00:00
Name() string
2018-06-21 01:43:14 +00:00
Setup(*Doodle) error
Destroy() error
// Loop should update the scene's state but not draw anything.
Loop(*Doodle, *events.State) error
// Draw should use the scene's state to figure out what pixels need
// to draw to the screen.
Draw(*Doodle) error
2018-06-21 01:43:14 +00:00
}
// Goto a scene. First it unloads the current scene.
func (d *Doodle) Goto(scene Scene) error {
// Teardown existing scene.
if d.Scene != nil {
d.Scene.Destroy()
}
log.Info("Goto Scene: %s", scene.Name())
d.Scene = scene
return d.Scene.Setup(d)
2018-06-21 01:43:14 +00:00
}