doodle/pkg/scene.go
Noah Petherbridge 4de0126b19 Game Controller Support
Adds support for Xbox and Nintendo style game controllers. The gamepad
controls are documented on the README and in the game's Settings window.

The buttons are not customizable yet, except that the player can choose
between two button styles:

* X Style (default): "A" button is on the bottom and "B" on the right.
* N Style: swaps the A/B and the X/Y buttons to use a Nintendo-style
  layout instead of an Xbox-style.
2022-02-19 18:31:22 -08:00

42 lines
1018 B
Go

package doodle
import (
"git.kirsle.net/apps/doodle/pkg/gamepad"
"git.kirsle.net/apps/doodle/pkg/log"
"git.kirsle.net/go/render/event"
)
// 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 {
Name() string
Setup(*Doodle) error
Destroy() error
// Loop should update the scene's state but not draw anything.
Loop(*Doodle, *event.State) error
// Draw should use the scene's state to figure out what pixels need
// to draw to the screen.
Draw(*Doodle) error
}
// Goto a scene. First it unloads the current scene.
func (d *Doodle) Goto(scene Scene) error {
// Inform the gamepad controller what scene.
gamepad.SceneName = scene.Name()
// Clear any debug labels.
customDebugLabels = []debugLabel{}
// 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)
}