2018-06-21 01:43:14 +00:00
|
|
|
package doodle
|
|
|
|
|
2019-04-10 00:35:44 +00:00
|
|
|
import (
|
2022-09-24 22:17:25 +00:00
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/gamepad"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
|
2019-12-31 02:13:28 +00:00
|
|
|
"git.kirsle.net/go/render/event"
|
2019-04-10 00:35:44 +00:00
|
|
|
)
|
2018-07-22 00:12:22 +00:00
|
|
|
|
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
|
2018-07-24 03:10:53 +00:00
|
|
|
Destroy() error
|
2018-07-22 03:43:01 +00:00
|
|
|
|
|
|
|
// Loop should update the scene's state but not draw anything.
|
2019-12-22 22:11:01 +00:00
|
|
|
Loop(*Doodle, *event.State) error
|
2018-07-22 03:43:01 +00:00
|
|
|
|
|
|
|
// 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 {
|
2022-02-20 02:25:36 +00:00
|
|
|
// Inform the gamepad controller what scene.
|
|
|
|
gamepad.SceneName = scene.Name()
|
|
|
|
|
2019-04-10 02:17:56 +00:00
|
|
|
// Clear any debug labels.
|
|
|
|
customDebugLabels = []debugLabel{}
|
|
|
|
|
2018-07-24 03:10:53 +00:00
|
|
|
// Teardown existing scene.
|
2018-07-26 02:38:54 +00:00
|
|
|
if d.Scene != nil {
|
|
|
|
d.Scene.Destroy()
|
2018-07-24 03:10:53 +00:00
|
|
|
}
|
|
|
|
|
2018-07-26 02:38:54 +00:00
|
|
|
log.Info("Goto Scene: %s", scene.Name())
|
|
|
|
d.Scene = scene
|
|
|
|
return d.Scene.Setup(d)
|
2018-06-21 01:43:14 +00:00
|
|
|
}
|