Noah Petherbridge
6713dd7bfc
Implement scrolling behavior in Play Mode by allowing the Canvas to follow a specific actor and keep it in view. The Canvas has a FollowActor property which holds an ID of the actor to follow (if blank, no actor is being followed). In Play Mode the Player is followed and when they get too close to the left or right edges of the screen, the level will scroll to try and catch them. If the player is moving very fast they can outrun the camera. The bounded levels are enforced in Play Mode and the camera won't scroll to view pixels out-of-bounds and the Doodad actors inside the level aren't allowed to exit its boundaries. This is global, not only for the Player doodad but any Doodad that came with the level as well. Other changes: - Restructured Canvas widget code into many new files. The Canvas widget is shaping up to be where most of the magic happens, which is okay because it's close to the action and pulling the strings from outside would be harder, even tho as a UI element you think it should be lightweight. - Debug Overlay: added room for Scenes to insert their own custom Debug Overlay key/value pairs (the values are string pointers so the Scene can update them freely): - The core labels are FPS, Scene and Mouse. The Pixel (world coordinate under cursor) is removed from the core labels. - Edit Scene provides Pixel, Tool and Swatch - Play Scene provides Pixel, Player, Viewport, Scroll
35 lines
872 B
Go
35 lines
872 B
Go
package doodle
|
|
|
|
import "git.kirsle.net/apps/doodle/events"
|
|
|
|
// 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, *events.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 {
|
|
// Reset any custom debug overlay entries.
|
|
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)
|
|
}
|