Documentation
¶
Index ¶
- Constants
- func Contains(container pixel.Rect, target pixel.Rect) bool
- func LoadImage(path string) (pixel.Picture, error)
- func StrBool(s interface{}) bool
- func StrFloat(s interface{}) float64
- type Action
- type Actor
- type Configuration
- type Controller
- type Default
- type Directory
- type Engine
- func (e *Engine) ActivateScene(scene string)
- func (e *Engine) AddActor(id string, actor *Actor)
- func (e *Engine) ConfigurePixel()
- func (e *Engine) CreateCoreActions()
- func (e *Engine) DisplayMessageBox(msg string)
- func (e *Engine) GetScene(id string) *Scene
- func (e *Engine) Initialize(file string)
- func (e *Engine) NewActor(filename string, position pixel.Vec) *Actor
- func (e *Engine) NewScene(id string, bgcolor string) error
- func (e *Engine) Run()
- func (e *Engine) RunScript(script *Script) interface{}
- func (e *Engine) RunScriptAction(action *Action) interface{}
- func (e *Engine) RunScriptFile(file string)
- type Handler
- type Map
- type MessageBox
- type Scene
- func (s *Scene) CollisionFree(clip pixel.Rect) bool
- func (s *Scene) Contains(target pixel.Rect) bool
- func (s *Scene) Draw()
- func (s *Scene) GetView(id string) (*View, error)
- func (s *Scene) LoadActorsFromMapData()
- func (s *Scene) LoadMap(file string) error
- func (s *Scene) MoveActor(actor *Actor, direction int)
- func (s *Scene) NewView(id string, position pixel.Vec, camera pixel.Rect, bgcolor string)
- func (s *Scene) ProcessActorDestinations()
- func (s *Scene) RemoveView(id string)
- func (s *Scene) Render()
- func (s *Scene) SetBackground(bgcolor string)
- func (s *Scene) UseActor(actor string)
- type Script
- type ScriptAction
- type Scripting
- type System
- type View
- func (v *View) CameraContains(target pixel.Rect) bool
- func (v *View) CenterOn(movement pixel.Vec)
- func (v *View) Draw()
- func (v *View) FocusOn(actor *Actor)
- func (v *View) Hide()
- func (v *View) Move(position pixel.Vec)
- func (v *View) Render()
- func (v *View) SetBackground(bgcolor string)
- func (v *View) Show()
- func (v *View) Toggle()
- func (v *View) UseMap() error
- type Viewable
- type Window
Constants ¶
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Action ¶
type Action struct { // The action keyword Action string // The arguments for this command Args []interface{} }
Action will hold the instructions on an action to perform
type Actor ¶
type Actor struct { // XMLName is how we reference when loading xml information XMLName xml.Name `xml:"actor"` // Position of the actor, needs to be relative to map Position pixel.Vec // Destinations will be preset by running scripts. Destinations []pixel.Vec // Src is the source graphic Src pixel.Picture // Output should be the sprite Output *pixel.Sprite // Clip is the area of the actor relative to the map. Clip pixel.Rect // Speed will set a speed modifier for the actor. Speed float64 `xml:"speed,attr"` // Visible determines if we see the sprite or not. Visible bool // Collision determines if it collides with anything or not Collision bool }
Actor is an element that will move around within the view.
func (*Actor) Render ¶ added in v0.19.0
func (a *Actor) Render()
Render will draw out the actor to the output. This often only will need to run on file load, not during running loops.
type Configuration ¶
type Configuration struct { XMLName xml.Name `xml:"configuration"` System System `xml:"system"` Default Default `xml:"default"` }
Configuration setting collection
func LoadConfiguration ¶
func LoadConfiguration(file string) (*Configuration, error)
LoadConfiguration loads a configuration from the provided XML file.
type Controller ¶
type Controller struct { // Handlers are the collections of Handler Sets Handlers map[string][]*Handler // Engine is the engine the controller is running on. Engine *Engine }
Controller manages the key handlers, running handler methods as appropriate. The current state of the system will depend on what handlers are present. If there are any system handlers present, they will override the application handlers until there are not any system handlers present.
func (*Controller) AddHandler ¶ added in v0.19.0
func (c *Controller) AddHandler(class string, id string, button pixelgl.Button, sensitive bool, action func())
AddHandler will add the indicated type of handler to this control. `sensitive` will indicate if the JustPress method is used, which triggers the handler once. Otherwise the handler will act as a game button, allowing it to be held for repeated effect.
func (*Controller) Initialize ¶
func (c *Controller) Initialize()
Initialize will setup any structure elements that require not being nil.
func (*Controller) RemoveHandler ¶ added in v0.19.0
func (c *Controller) RemoveHandler(class string, id string)
RemoveHandler will remove a handler from the provided handler list.
func (*Controller) Run ¶
func (c *Controller) Run()
Run will loop through our controllers running any handlers that are setup.
type Default ¶
type Default struct { XMLName xml.Name `xml:"default"` Scene Scene `xml:"scene"` Actor Actor `xml:"actor"` MessageBox MessageBox `xml:"messagebox"` }
Default object values when not provided.
type Directory ¶ added in v0.19.0
type Directory struct { XMLName xml.Name `xml:"directory"` Characters string `xml:"characters,attr"` }
Directory will set default directories not set elsewhere
type Engine ¶ added in v0.18.0
type Engine struct { // Config holds our main configuration values to run the system. Config *Configuration // PixelWindow is our graphics window configuration. PixelWindow pixelgl.WindowConfig // ScriptActions holds defined scripting actions. ScriptActions map[string]*ScriptAction // Font is our basic text atlas for system purposes. Font *text.Atlas // Scenes holds the various game scene contents. Scenes map[string]*Scene // ActiveScene is the currently running scene. ActiveScene *Scene // Actors holds the loaded actors for the game. They can be used across // scenes so it's not a good idea to tie them tightly to scenes. Scenes will // hold a list of actors that are visible or running on them. Actors map[string]*Actor // Control is the handlers that are loaded into the engine. Soon we should have global // control handlers, and scene independent handlers. Control *Controller // Logic is not used yet, but will be put in place to handle game logic functions that // should be run periodically, which are not tied to events. Logic func() // LastMove is the time of the last game cycle, used for managing game timing and motion. LastMove time.Time // Dt is used to calculate change in game cycle time, used for managing // game timing and motion. Dt float64 // contains filtered or unexported fields }
Engine is the core system that holds all running functionality.
func (*Engine) ActivateScene ¶ added in v0.18.0
ActivateScene will set the currently running scene.
func (*Engine) ConfigurePixel ¶ added in v0.18.0
func (e *Engine) ConfigurePixel()
ConfigurePixel will build up the pixel configuration from our game configuration. In this way if any window options are changed, we simply use ConfigurePixel to update the pixel window.
func (*Engine) CreateCoreActions ¶ added in v0.18.0
func (e *Engine) CreateCoreActions()
CreateCoreActions sets up the basic scripting actions that will always be included in the system.
func (*Engine) DisplayMessageBox ¶ added in v0.19.0
DisplayMessageBox will display a message on screen and then wait for user input.
func (*Engine) Initialize ¶ added in v0.18.0
Initialize starts up the RPG engine
func (*Engine) NewActor ¶ added in v0.18.0
NewActor creates a new actor and returns it TODO: Allow for non image actors.
func (*Engine) NewScene ¶ added in v0.18.0
NewScene will create a new scene. We use the already loaded configuration to initialize it. It should crash amazingly when there's no config loaded.
func (*Engine) RunScript ¶ added in v0.18.0
RunScript will run a game script, by default using our game script collection.
func (*Engine) RunScriptAction ¶ added in v0.18.0
RunScriptAction will run the specified script action.
func (*Engine) RunScriptFile ¶ added in v0.18.0
RunScriptFile will load and run a script, presuming script directory and extension.
type Handler ¶
type Handler struct { // ID will be a string we can use to identify a handler when we need to // remove it. ID string // The keypress we are checking Button pixelgl.Button // Sensitive will indicate if we JustPress...usually for menus Sensitive bool // The action to perform Action func() }
Handler is our structure that we will create and add to the controller
type Map ¶
type Map struct { // Basic map data as loaded from file Src *tiled.Map // Size will be the size of our map, pulled from our map data Size pixel.Vec // The rendered full map. We set this up as an array so that in future // we can process assorted layers independently if needed. Img []*pixel.PictureData // Our collision information, a collection of map objects. Collision []*pixel.Rect }
Map will contain our map with some easy to use stuff, like for rendering
type MessageBox ¶ added in v0.18.0
type MessageBox struct { XMLName xml.Name `xml:"messagebox"` Color string `xml:"color,attr"` BGColor string `xml:"bgcolor,attr"` X float64 `xml:"x,attr"` Y float64 `xml:"y,attr"` Height float64 `xml:"height,attr"` Width float64 `xml:"width,attr"` }
MessageBox sets options for the system messagebox.
type Scene ¶
type Scene struct { // XMLName is how we reference when loading xml information. XMLName xml.Name `xml:"scene"` // basespeed is the speed that this scene will run at. Basespeed float64 `xml:"basespeed,attr"` // Background is the background colour to clear this screen to. Background color.RGBA // Rendered is the canvas we draw to before flipping to screen. Rendered *pixelgl.Canvas // Views is the collection of views of the scene. Views map[string]*View // ViewOrder is the order the views are drawn down. ViewOrder []string // Actors is the collection of actors of the scene. Actors map[string]*Actor // MapData is the tiled data object. MapData *Map // Control is the collection of handlers specific to the scene. Control *Controller // Engine is the engine this scene belongs to. Engine *Engine }
Scene holds the information for a combination of views and actors. A view should be able to have multiple actors and multiple outputs.
func (*Scene) CollisionFree ¶
CollisionFree will indicate the space is free of collisions. It tests against the collision objects that are found in the map file.
func (*Scene) Contains ¶
Contains will indicate if the rectangle is contained within this view's source map. Used for bounds checking against actors and the camera.
func (*Scene) Draw ¶
func (s *Scene) Draw()
Draw will draw the scene out to the Engine win target. This should be the pixelgl.Window reference.
func (*Scene) LoadActorsFromMapData ¶ added in v0.19.0
func (s *Scene) LoadActorsFromMapData()
LoadActorsFromMapData will return an array of actors that are present in the mapdata.
func (*Scene) LoadMap ¶ added in v0.19.0
LoadMap will load a map into a scene. This needs to be called before we can start a map view.
func (*Scene) ProcessActorDestinations ¶ added in v0.16.4
func (s *Scene) ProcessActorDestinations()
ProcessActorDestinations will move the relevent actors towards their respective destinations
func (*Scene) RemoveView ¶ added in v0.18.0
RemoveView will destroy the view from the scene, also maintaining the vieworder.
func (*Scene) Render ¶ added in v0.18.0
func (s *Scene) Render()
Render will draw our views onto our scene canvas.
func (*Scene) SetBackground ¶
SetBackground will set the background color of the scene.
type Script ¶
type Script struct {
Actions []*Action
}
Script will hold a sequence or collection of commands. In theory this is is what a script file might get loaded into.
func NewScript ¶ added in v0.16.4
func NewScript() *Script
NewScript will return a new, empty script.
type ScriptAction ¶
type ScriptAction struct { Action string Runner func([]interface{}) interface{} }
ScriptAction will hold the implementation of script actions.
func NewScriptAction ¶
func NewScriptAction(action string, runner func([]interface{}) interface{}) *ScriptAction
NewScriptAction will create and return a new ScriptAction.
type Scripting ¶
type Scripting struct { XMLName xml.Name `xml:"scripting"` Dir string `xml:"dir,attr"` Extension string `xml:"extension,attr"` }
Scripting sets customizable script options.
type System ¶
type System struct { XMLName xml.Name `xml:"system"` Window Window `xml:"window"` Scripting Scripting `xml:"scripting"` Directory Directory `xml:"directory"` }
System configuration setting.
type View ¶
type View struct { // Visible indicates if the view should be rendered. Visible bool // Background is the background color of the view. Background color.RGBA // Src indicates the source picture data to draw from Src *pixel.PictureData // Focus is the actor that the view will follow. This actor will be // restricted to the bounds of the view. Focus *Actor // VisibleActors are the actors that are actually visible on this // view. VisibleActors []string // Output is the rendered map which is drawn to the screen. Output []*pixel.Sprite // Rendered is our background canvas to draw onto which will be // flipped to the screen. Rendered *pixelgl.Canvas // DesignView is the function that will be called to draw our view. // With consideration for views that don't focus on a map. DesignView func() // Position of our view on the window. Position pixel.Vec // Camera is the region of the map that is currently in view. // The camera also controls what is in display, period. So if we set it // once and don't change it, that's fine. Camera pixel.Rect // Speed is the speed modifier of this camera, not used yet. Speed float64 // Scene will be the scene this view is a part of. Scene *Scene // Engine is passed through for ease of access Engine *Engine }
View is the object that is rendered to the screen. It manages the associated graphics and actors, as well as any motion directly related to the view.
func (*View) CameraContains ¶
CameraContains will ensure that the camera contains the given rectangle. Should be refactored soon too.
func (*View) SetBackground ¶
SetBackground sets the background color of the view.