Add new doodads: * Start Flag: place this in a level to set the spawn point of the player character. If no flag is found, the player spawns at 0,0 in the top corner of the map. Only use one Start Flag per level, otherwise the player will randomly spawn at one of them. * Crumbly Floor: a solid floor that begins to shake and then fall apart after a moment when a mobile character steps on it. The floor respawns after 5 seconds. * State Blocks: blue and orange blocks that toggle between solid and pass-thru whenever a State Button is activated. * State Button: a solid "ON/OFF" block that toggles State Blocks back and forth when touched. Only activates if touched on the side or bottom; acts as a solid floor when walked on from the top. New features for doodad scripts: * Actor scripts: call SetMobile(true) to mark an actor as a mobile mob (i.e. player character or enemy). Other doodads can check if the actor colliding with them IsMobile so they don't activate if placed too close to other (non-mobile) doodads in a level. The Blue and Red Azulians are the only mobile characters so far. * Message.Broadcast allows sending a pub/sub message out to ALL doodads in the level, instead of only to linked doodads as Message.Publish does. This is used for the State Blocks to globally communicate on/off status without needing to link them all together manually.
38 lines
895 B
Go
38 lines
895 B
Go
package doodle
|
|
|
|
import (
|
|
"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 {
|
|
// 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)
|
|
}
|