awakengine

package module
v0.0.0-...-56d71c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

README

AwakEngine!

A silly 2D point-and-click adventure engine.

Usage

Do this:

go get github.com/DrJosh9000/awakengine

Implement the Game interface, and pass it to Run.

Examples

https://github.com/DrJosh9000/awakeman/e27

Documentation

Index

Constants

View Source
const (
	EventNone = EventType(iota)
	EventMouseDown
	EventMouseUp
)

Variables

This section is empty.

Functions

func ImageAsMap

func ImageAsMap(imgkey string) ([]uint8, vec.I2, error)

ImageAsMap returns the contents and size of a paletted PNG file.

func Navigate(from, to vec.I2) []vec.I2

Navigate attempts to construct a path within the terrain.

func PushDialogue

func PushDialogue(dl ...*DialogueLine)

PushDialogue makes some dialogue the next dialogue to play.

func PushDialogueToBack

func PushDialogueToBack(dl ...*DialogueLine)

PushDialogueToBack makes some dialogue the dialogue to play after all the current dialogue is finished.

func RegisterImage

func RegisterImage(key string, png []byte)

RegisterImage tells the engine that a key maps to an image. Registered images will be loaded into a texture atlas with loadAllImages.

func Run

func Run(g Game, cfg *Config) error

Run runs the game (ebiten.Run) in addition to setting up any necessary GIF recording.

Types

type BaseDoodad

type BaseDoodad struct {
	*SheetFrame
	Offset vec.I2
	UL, DR vec.I2 // base obstacle box (frame relative)
}

BaseDoodad models a static object rendered at the player layer, but computed as obstacles (like terrain).

type Bubble

type Bubble struct {
	*View
	Key string
	// contains filtered or unexported fields
}

Bubble renders a bubble at any size larger than bubblePartSize.Mul(3)

func (*Bubble) AddToScene

func (b *Bubble) AddToScene(s *Scene)

func (*Bubble) Surround

func (b *Bubble) Surround(r vec.Rect)

type Button

type Button struct {
	*Bubble
	*Text
	Action func()
	// contains filtered or unexported fields
}

func NewButton

func NewButton(text string, action func(), bounds vec.Rect, parent *View) *Button

func (*Button) AddToScene

func (b *Button) AddToScene(s *Scene)

func (*Button) Dispose

func (b *Button) Dispose()

func (*Button) Handle

func (b *Button) Handle(e *Event) (handled bool)

type ButtonSpec

type ButtonSpec struct {
	Label  string
	Action func()
}

type CharInfo

type CharInfo struct {
	X, Y, Width, Height, XOffset, YOffset, XAdvance int
}

type CharMetrics

type CharMetrics map[byte]CharInfo

type Config

type Config struct {
	Debug           bool
	FramesPerUpdate int
	LevelGeomDump   string
	LevelPreview    bool
	RecordingFile   string
	RecordingFrames int
}

type DialogueDisplay

type DialogueDisplay struct {
	*View
	// contains filtered or unexported fields
}

Dialogue is all the things needed for displaying blocking dialogue text.

func NewDialogueDisplay

func NewDialogueDisplay(scene *Scene) *DialogueDisplay

NewDialogueDisplay creates a new DialogueDisplay.

func (*DialogueDisplay) AddToScene

func (d *DialogueDisplay) AddToScene(scene *Scene)

func (*DialogueDisplay) Handle

func (d *DialogueDisplay) Handle(event *Event) bool

Update updates things in the dialogue, based on user input or passage of time. Returns true if the event is handled.

func (*DialogueDisplay) Layout

func (d *DialogueDisplay) Layout(line *DialogueLine)

Layout rearranges views

type DialogueLine

type DialogueLine struct {
	Avatar   *SheetFrame
	Text     string
	Buttons  []*ButtonSpec
	AutoNext bool
	Slowness int
}

DialogueLine is information for displaying a singe line of dialogue in a display.

type Doodad

type Doodad struct {
	P vec.I2
	*BaseDoodad
}

Doodad is an instance of a BaseDoodad in a specific location.

func (*Doodad) Dst

func (d *Doodad) Dst() (x0, y0, x1, y1 int)

func (*Doodad) Fixed

func (d *Doodad) Fixed() bool

func (*Doodad) Retire

func (d *Doodad) Retire() bool

func (*Doodad) Update

func (d *Doodad) Update(int)

func (*Doodad) Visible

func (d *Doodad) Visible() bool

func (*Doodad) Z

func (d *Doodad) Z() int

type Event

type Event struct {
	Time      int
	Type      EventType
	ScreenPos vec.I2 // 0,0 is top left of screen.
	WorldPos  vec.I2 // 0,0 is origin of world.
	MouseDown bool
}

type EventType

type EventType int

type Font

type Font interface {
	ImageKey(invert bool) string
	Metrics() CharMetrics
	LineHeight() int
	YOffset() int
}

type FrameInfo

type FrameInfo struct {
	Duration int    // in model frames. -1 means infinite, 0 means 1
	Next     int    // next model frame index, no special meaning for 0...
	Offset   vec.I2 // subtract from position to get top-left of destination
}

FrameInfo describes how to play a frame in an animation.

func BasicFrameInfos

func BasicFrameInfos(n, duration int, offset vec.I2) []FrameInfo

BasicFrameInfos is a convenience for making FrameInfos that all have the same offset and duration, and all have the next frame as the next frame.

type Game

type Game interface {
	// BubbleKey returns the key for the bubble image, and inverse.
	BubbleKey() (string, string)

	// Font is the general/default typeface to use.
	Font() Font

	Handler

	// Level provides the base level.
	Level() (*Level, error)

	// Player provides the player unit.
	Player() (Unit, *Sprite)

	Scene() *Scene

	// Triggers provide some dynamic behaviour.
	Triggers() []*Trigger

	// Viewport is the size of the window and the pixels in the window.
	Viewport() (pixelSize int, title string)
}

Game abstracts the non-engine parts of the game: the story, art, level design, etc.

type Grid

type Grid struct {
	*View
	GridDelegate
	// contains filtered or unexported fields
}

func (*Grid) Handle

func (g *Grid) Handle(e *Event) bool

func (*Grid) Reload

func (g *Grid) Reload()

Reload all the items.

type GridDelegate

type GridDelegate interface {
	Columns() int
	Item(i int, par *View)
	ItemSize() vec.I2
	ItemHandle(i int, e *Event) bool // item #i should handles event e
	NumItems() int
}

type Handler

type Handler interface {
	// Handle handles the event e and returns true if the event is "consumed" or
	// false if the event "lives on" to be handled elsewhere.
	Handle(e *Event) bool
}

Handler handles events.

type ImageView

type ImageView struct {
	*View
	*SheetFrame
}

ImageView displays one frame of a sheet filling a view.

func (*ImageView) Dst

func (v *ImageView) Dst() (x0, y0, x1, y1 int)

func (*ImageView) Src

func (v *ImageView) Src() (x0, y0, x1, y1 int)

type Level

type Level struct {
	Doodads                 []*Doodad // sparse terrain objects
	MapSize                 vec.I2
	TileMap, BlockMap       []uint8
	TileInfos, BlockInfos   []TileInfo // dense terrain objects
	TilesetKey, BlocksetKey string
	TileSize, BlockHeight   int

	// Obstacles and Paths are optional but speed up game start time.
	Obstacles, Paths *vec.Graph
}

Level describes things needed for a base terrain/level.

type Part

type Part interface {
	Container() *View
	ImageKey() string
	Src() (x0, y0, x1, y1 int) // relative to the image referred to by ImageKey()
	Dst() (x0, y0, x1, y1 int) // relative to the containing view.
	Fixed() bool
	Retire() bool  // true if the part will never draw again.
	Visible() bool // true if the part is visible.
	Z() int
}

Part participates in the draw system.

type Scene

type Scene struct {
	*View
	World, HUD *View
	// contains filtered or unexported fields
}

Scene manages drawing one scene.

Using a Scene as a parent will subtract the camera position. To use screen coordinates, use a parent of nil.

func NewScene

func NewScene(camSize, terrainSize vec.I2) *Scene

func (*Scene) AddPart

func (s *Scene) AddPart(parts ...Part)

AddPart adds parts to the pipeline.

func (*Scene) CameraFocus

func (s *Scene) CameraFocus(p vec.I2)

CameraFocus sets the World offset such that p should be center of screen, or at least within the bounds of the terrain.

func (*Scene) Draw

func (s *Scene) Draw(screen *ebiten.Image) error

func (*Scene) Update

func (s *Scene) Update()

type Sheet

type Sheet struct {
	Columns    int
	Key        string
	FrameInfos []FrameInfo
	FrameSize  vec.I2
}

func (*Sheet) FrameSrc

func (s *Sheet) FrameSrc(f int) (x0, y0, x1, y1 int)

Src returns the source rectangle for frame number f.

type SheetFrame

type SheetFrame struct {
	*Sheet
	FrameNo int
}

SheetFrame lets you specify a frame in addition to a sheet.

func (*SheetFrame) ImageKey

func (s *SheetFrame) ImageKey() string

func (*SheetFrame) Src

func (s *SheetFrame) Src() (x0, y0, x1, y1 int)

type Sprite

type Sprite struct {
	*View        // Container for drawPosition; can be a new view.
	Pos   vec.F2 // Position

	SpriteDelegate
	// contains filtered or unexported fields
}

Sprite concerns itself with displaying the right frame of an animation at the right time, at the right position, and at the right Z order.

func (*Sprite) AdvanceAnim

func (s *Sprite) AdvanceAnim()

func (*Sprite) Container

func (s *Sprite) Container() *View

func (*Sprite) Dst

func (s *Sprite) Dst() (x0, y0, x1, y1 int)

func (*Sprite) Fixed

func (s *Sprite) Fixed() bool

func (*Sprite) ImageKey

func (s *Sprite) ImageKey() string

func (*Sprite) ResetAnim

func (s *Sprite) ResetAnim()

func (*Sprite) Retire

func (s *Sprite) Retire() bool

func (*Sprite) Src

func (s *Sprite) Src() (x0, y0, x1, y1 int)

func (*Sprite) Update

func (s *Sprite) Update(t int)

func (*Sprite) Visible

func (s *Sprite) Visible() bool

func (*Sprite) Z

func (s *Sprite) Z() int

type SpriteDelegate

type SpriteDelegate interface {
	// Instancey things
	Fixed(s *Sprite) bool
	SpriteSheet(s *Sprite) *Sheet    // Which sheet we're currently using
	Update(s *Sprite, modelTime int) // Do model updates
	Z(s *Sprite) int                 // Given our position, what's the right Z?
}

type Terrain

type Terrain struct {
	*View
	*Level
	// contains filtered or unexported fields
}

Terrain is the base layer of the game world.

func (*Terrain) AddToScene

func (t *Terrain) AddToScene(s *Scene)

AddToScene adds terrain objects to the scene.

func (*Terrain) Block

func (t *Terrain) Block(x, y int) TileInfo

Block gets the information about the block at a tile coordinate.

func (*Terrain) Blocking

func (t *Terrain) Blocking(i, j int) bool

func (*Terrain) Fixed

func (t *Terrain) Fixed() bool

func (*Terrain) MakeAllVisible

func (t *Terrain) MakeAllVisible()

MakeAllVisible enables visiblity for all parts of the terrain.

func (*Terrain) ObstaclesAndPaths

func (t *Terrain) ObstaclesAndPaths(fatUL, fatDR, limit vec.I2) (obstacles, paths *vec.Graph)

ObstaclesAndPaths constructs two graphs, the first describing terrain obsctacles, the second describing a network of valid paths around the obstacles. Obstacles will be fattened according to the footprint fatUL, fatDR, and paths will be based on vertices at convex points of the obstacle graph plus 1 pixel in both dimensions outwards from the convex vertex.

func (*Terrain) Retire

func (t *Terrain) Retire() bool

func (*Terrain) Size

func (t *Terrain) Size() vec.I2

Size returns the world size in pixels.

func (*Terrain) Tile

func (t *Terrain) Tile(x, y int) TileInfo

Tile gets the information about the tile at a tile coordinate.

func (*Terrain) TileCoord

func (t *Terrain) TileCoord(wc vec.I2) vec.I2

TileCoord returns information about the tile at a world coordinate.

func (*Terrain) UpdatePartVisibility

func (t *Terrain) UpdatePartVisibility(origin vec.I2, dist int)

UpdatePartVisibility makes tile & block parts visible if they can be seen from origin.

type Text

type Text struct {
	*View
	Font
	Text   string
	Invert bool
	// contains filtered or unexported fields
}

func (*Text) AddToScene

func (t *Text) AddToScene(s *Scene)

func (*Text) Advance

func (t *Text) Advance() error

Advance makes the next character visible.

func (*Text) Layout

func (t *Text) Layout(visible bool)

Layout causes the text to lay out all the characters, and update the size to exactly contain the text. Text will be wrapped to the existing Size.X as a width.

type TileInfo

type TileInfo struct {
	Name     string
	Blocking bool // Player is unable to walk through?
}

TileInfo describes the properties of a tile.

type Trigger

type Trigger struct {
	Name    string
	Tiles   []vec.I2
	Active  func(gameFrame int) bool
	Depends []string
	Fire    func(gameFrame int)
	Repeat  bool
	// contains filtered or unexported fields
}

Trigger is everything to do with reacting to the player or time or ... On the PC entering any of the Tiles, Fired, Active, and Depends will be checked and then Fire will happen. If no Tiles are listed, it will be added to a global list of triggers checked on every frame.

func (*Trigger) Reset

func (t *Trigger) Reset()

type Unit

type Unit interface {
	// GoIdle asks the unit to stop whatever it's doing ("at ease").
	GoIdle()

	// Footprint is the rectangle relative to the sprite position with the ground area of the unit.
	Footprint() (ul, dr vec.I2)

	// Path is the path the unit is currently following. The current position is
	// implied as the first point.
	Path() []vec.I2
}

Unit can be given orders. Examples of units include the player character, NPCs, etc. Or it could be a unit in an RTS.

type View

type View struct {
	// contains filtered or unexported fields
}

View represents a rectangular region in a view hierarchy. It caches its real position information because why not.

func (*View) Bounds

func (v *View) Bounds() vec.Rect

func (*View) Container

func (v *View) Container() *View

Convenience methods for embedding in Parts.

func (*View) Dispose

func (v *View) Dispose()

Dispose retires this view and all subviews, and disconnects everything.

func (*View) Fixed

func (v *View) Fixed() bool

func (*View) Position

func (v *View) Position() vec.I2

Position is always the view's top-left corner.

func (*View) RelativeBounds

func (v *View) RelativeBounds() vec.Rect

func (*View) RelativeZ

func (v *View) RelativeZ() int

func (*View) Retire

func (v *View) Retire() bool

func (*View) SetBounds

func (v *View) SetBounds(bounds vec.Rect)

func (*View) SetParent

func (v *View) SetParent(parent *View)

func (*View) SetPosition

func (v *View) SetPosition(ul vec.I2)

SetPosition moves the view to a new position without altering the size. It invalidates.

func (*View) SetPositionAndSize

func (v *View) SetPositionAndSize(pos, size vec.I2)

SetPosition moves the view to a new position and changes its size. It invalidates.

func (*View) SetRetire

func (v *View) SetRetire(ret bool)

func (*View) SetSize

func (v *View) SetSize(sz vec.I2)

SetSize alters the size of the view without altering the top-left corner of the bounds. It invalidates nothing.

func (*View) SetVisible

func (v *View) SetVisible(vis bool)

func (*View) SetZ

func (v *View) SetZ(z int)

func (*View) Size

func (v *View) Size() vec.I2

func (*View) Visible

func (v *View) Visible() bool

func (*View) Z

func (v *View) Z() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL