primen

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2020 License: MIT Imports: 15 Imported by: 0

README

Primen

Primen is a 2D game engine written in Go following the Entity Component System paradigm. Primen is powered by the Ebiten game library.

WIP

I'm developing this project along with a game, so the features are being added according with my game's priorities.

Planned Integrations

Documentation

Index

Constants

View Source
const TagDelta = "delta"

TagDelta is the key set of the time taken between frames (in seconds)

Variables

This section is empty.

Functions

func ColorFromHex added in v0.3.0

func ColorFromHex(hexv string) color.RGBA

ColorFromHex parses a RRGGBBAA (or RRGGBB) hexadecimal color into color.RGBA

Returns color.Transparent on invalid hex inputs.

func Destroy added in v0.3.0

func Destroy(obj Object) bool

Destroy an object

func SetDrawFuncs added in v0.3.0

func SetDrawFuncs(w *ecs.World, entity ecs.Entity, beforefn, fn, afterfn core.DrawFn) error

SetDrawFuncs adds a component with the specified draw functions

func SetFuncs

func SetFuncs(w *ecs.World, entity ecs.Entity, beforefn, fn, afterfn core.UpdateFn) error

SetFuncs adds a component with the specified update functions

Types

type AnimatedSprite added in v0.3.0

type AnimatedSprite struct {
	*Sprite
	// contains filtered or unexported fields
}

func NewAnimatedSprite added in v0.3.0

func NewAnimatedSprite(parent WorldTransform, layer Layer, anim Animation) *AnimatedSprite

func (*AnimatedSprite) PlayClip added in v0.3.0

func (as *AnimatedSprite) PlayClip(name string)

func (*AnimatedSprite) PlayClipIndex added in v0.3.0

func (as *AnimatedSprite) PlayClipIndex(i int)

type Animation added in v0.3.0

type Animation = core.Animation

type Dict

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

Dict is a concurrency-safe map.

func (*Dict) Exists

func (d *Dict) Exists(key string) bool

Exists checks if the item exists

func (*Dict) Get

func (d *Dict) Get(key string) interface{}

Get an item

func (*Dict) Set

func (d *Dict) Set(key string, value interface{})

Set an item

type DrawLayerItem added in v0.4.0

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

func (*DrawLayerItem) Layer added in v0.4.0

func (dli *DrawLayerItem) Layer() Layer

func (*DrawLayerItem) SetLayer added in v0.4.0

func (dli *DrawLayerItem) SetLayer(l Layer)

func (*DrawLayerItem) SetZIndex added in v0.4.0

func (dli *DrawLayerItem) SetZIndex(index int64)

func (*DrawLayerItem) ZIndex added in v0.4.0

func (dli *DrawLayerItem) ZIndex() int64

type Engine

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

Engine is what controls the ECS of primen.

func NewEngine

func NewEngine(v *NewEngineInput) *Engine

NewEngine returns a new Engine

func (*Engine) AddEventListener

func (e *Engine) AddEventListener(eventName string, fn core.EventFn) core.EventID

func (*Engine) AddWorld

func (e *Engine) AddWorld(w *ecs.World, priority int)

AddWorld adds a world to the engine. The priority is used to sort world execution, from hight to low.

func (*Engine) Default

func (e *Engine) Default() *ecs.World

Default world

func (*Engine) DispatchEvent

func (e *Engine) DispatchEvent(eventName string, data interface{})

func (*Engine) Draw

func (e *Engine) Draw(screen *ebiten.Image)

func (*Engine) DrawFrame

func (e *Engine) DrawFrame() int64

DrawFrame returns the current frame. Use ctx.Frame() (more performant)

func (*Engine) FS

func (e *Engine) FS() io.Filesystem

FS returns the filesystem

func (*Engine) Get

func (e *Engine) Get(key string) interface{}

Get an item from the global map

func (*Engine) Height

func (e *Engine) Height() int

Height returns the logical height

func (*Engine) Layout

func (e *Engine) Layout(outsideWidth, outsideHeight int) (int, int)

Layout for ebiten.Game inteface

func (*Engine) Ready

func (e *Engine) Ready() <-chan struct{}

Ready returns a channel that signals when the engine is ready

func (*Engine) RemoveEventListener

func (e *Engine) RemoveEventListener(id core.EventID) bool

func (*Engine) RemoveWorld

func (e *Engine) RemoveWorld(w *ecs.World) bool

RemoveWorld removes a *World

func (*Engine) Root added in v0.3.0

func (e *Engine) Root(w *ecs.World) WorldTransform

Root transform of the world is the world wrapped in a WorldTransform interface

func (*Engine) Run

func (e *Engine) Run() error

Run boots up the game engine

func (*Engine) Set

func (e *Engine) Set(key string, value interface{})

Set an item to the global map

func (*Engine) SetScreenScale added in v0.4.0

func (e *Engine) SetScreenScale(scale float64)

func (*Engine) Update

func (e *Engine) Update(screen *ebiten.Image) error

func (*Engine) UpdateFrame

func (e *Engine) UpdateFrame() int64

UpdateFrame returns the current frame. Use ctx.Frame() (more performant)

func (*Engine) Width

func (e *Engine) Width() int

Width returns the logical width

type EngineOptions

type EngineOptions struct {
	Width               int
	Height              int
	Scale               float64
	Title               string
	IsFullscreen        bool
	IsResizable         bool
	IsMaxResolution     bool
	IsTransparentScreen bool
	IsFloating          bool
	IsMaximized         bool
	IsFixedResolution   bool
}

EngineOptions is used to setup Ebiten @ Engine.boot

type Label added in v0.3.0

type Label struct {
	*WorldItem
	*TransformItem
	// contains filtered or unexported fields
}

func NewLabel added in v0.3.0

func NewLabel(parent WorldTransform, fontFace font.Face, layer Layer) *Label

func (*Label) ComputedSize added in v0.3.0

func (l *Label) ComputedSize() (w, h int)

func (*Label) SetArea added in v0.3.0

func (l *Label) SetArea(w, h int)

func (*Label) SetColor added in v0.3.0

func (l *Label) SetColor(c color.Color)

func (*Label) SetFilter added in v0.3.0

func (l *Label) SetFilter(filter ebiten.Filter)

func (*Label) SetOrigin added in v0.3.0

func (l *Label) SetOrigin(ox, oy float64)

SetOrigin sets the label origin reference

0, 0 is top left

1, 1 is bottom right

func (*Label) SetText added in v0.3.0

func (l *Label) SetText(t string)

func (*Label) Text added in v0.3.0

func (l *Label) Text() string

type Layer added in v0.3.0

type Layer = core.LayerIndex

Layer index type

const (
	Layer0  Layer = 0
	Layer1  Layer = 1
	Layer2  Layer = 2
	Layer3  Layer = 3
	Layer4  Layer = 4
	Layer5  Layer = 5
	Layer6  Layer = 6
	Layer7  Layer = 7
	Layer8  Layer = 8
	Layer9  Layer = 9
	Layer10 Layer = 10
	Layer11 Layer = 11
	Layer12 Layer = 12
	Layer13 Layer = 13
	Layer14 Layer = 14
	Layer15 Layer = 15
)

LAYERS

type Layerer added in v0.4.0

type Layerer interface {
	SetLayer(l Layer)
	SetZIndex(index int64)
	Layer() Layer
	ZIndex() int64
}

Layerer is the interface of an object with a core.DrawLayer

type NewEngineInput

type NewEngineInput struct {
	Width             int             // main window width
	Height            int             // main window height
	Scale             float64         // pixel scale (default: 1)
	TransparentScreen bool            // transparent screen
	Maximized         bool            // start window maximized
	Floating          bool            // always on top of all windows
	Fullscreen        bool            // start in fullscreen
	Resizable         bool            // is window resizable?
	FixedResolution   bool            // fixed logical screen resolution
	FixedWidth        int             // fixed logical screen resolution
	FixedHeight       int             // fixed logical screen resolution
	MaxResolution     bool            // set width/height to max resolution
	Title             string          // window title
	FS                io.Filesystem   // TODO: drop this
	OnReady           func(e *Engine) // function to run once the window is opened
}

NewEngineInput is the input data of NewEngine

func (*NewEngineInput) Options

func (i *NewEngineInput) Options() EngineOptions

Options will create a EngineOptions struct to be used in an *Engine

type Object added in v0.3.0

type Object interface {
	Entity() ecs.Entity
	World() *ecs.World
}

Object is the base of any Primen base ECS object

type ObjectContainer added in v0.3.0

type ObjectContainer interface {
	Children() []Object
}

ObjectContainer is an object that contains other objects

type Sprite

type Sprite struct {
	*WorldItem
	*TransformItem
	*DrawLayerItem
	// contains filtered or unexported fields
}

func NewSprite

func NewSprite(parent WorldTransform, im *ebiten.Image, layer Layer) *Sprite

func (*Sprite) ClearColorTransform added in v0.4.0

func (s *Sprite) ClearColorTransform()

func (*Sprite) SetColorHue added in v0.4.0

func (s *Sprite) SetColorHue(theta float64)

SetColorHue rotates the Hue (in radians)

func (*Sprite) SetColorTint added in v0.4.0

func (s *Sprite) SetColorTint(c color.Color)

func (*Sprite) SetCompositeMode added in v0.4.0

func (s *Sprite) SetCompositeMode(mode ebiten.CompositeMode)

func (*Sprite) SetImage added in v0.4.0

func (s *Sprite) SetImage(img *ebiten.Image)

func (*Sprite) SetOffset added in v0.4.0

func (s *Sprite) SetOffset(x, y float64)

func (*Sprite) SetOffsetX added in v0.4.0

func (s *Sprite) SetOffsetX(x float64)

func (*Sprite) SetOffsetY added in v0.4.0

func (s *Sprite) SetOffsetY(y float64)

func (*Sprite) SetOrigin added in v0.4.0

func (s *Sprite) SetOrigin(ox, oy float64)

type StepInfo

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

func (*StepInfo) Get

func (i *StepInfo) Get() (lt time.Time, frame int64)

func (*StepInfo) GetFrame

func (i *StepInfo) GetFrame() (frame int64)

func (*StepInfo) Set

func (i *StepInfo) Set(lt time.Time, frame int64)

type TileSet added in v0.4.0

type TileSet struct {
	*WorldItem
	*TransformItem
	*DrawLayerItem
	// contains filtered or unexported fields
}

func NewTileSet added in v0.4.0

func NewTileSet(parent WorldTransform, layer Layer) *TileSet

func (*TileSet) SetCellSize added in v0.4.0

func (t *TileSet) SetCellSize(w, h float64)

func (*TileSet) SetDB added in v0.4.0

func (t *TileSet) SetDB(db []*ebiten.Image)

func (*TileSet) SetOrigin added in v0.4.0

func (t *TileSet) SetOrigin(ox, oy float64)

func (*TileSet) SetTilesXY added in v0.4.0

func (t *TileSet) SetTilesXY(m2d [][]int)

func (*TileSet) SetTilesYX added in v0.4.0

func (t *TileSet) SetTilesYX(m2d [][]int)

type Transform

type Transform struct {
	*WorldItem
	*TransformItem
}

func NewTransform

func NewTransform(parent WorldTransform) *Transform

type TransformChild added in v0.4.0

type TransformChild interface {
	SetParent(parent TransformGetter)
}

TransformChild is an interface for objects with a settable parent transform

type TransformGetter added in v0.3.0

type TransformGetter interface {
	CoreTransform() *core.Transform
}

TransformGetter is the interface to get the core.Transform of an object

type TransformItem added in v0.3.0

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

TransformItem implements Transformer

func (*TransformItem) Angle added in v0.4.0

func (t *TransformItem) Angle() (radians float64)

Angle gets the local angle (in radians) of the transform

func (*TransformItem) CoreTransform added in v0.4.0

func (t *TransformItem) CoreTransform() *core.Transform

CoreTransform retrieves the lower level core.Transform

func (*TransformItem) Scale added in v0.4.0

func (t *TransformItem) Scale() (x, y float64)

func (*TransformItem) SetAngle added in v0.3.0

func (t *TransformItem) SetAngle(radians float64)

SetAngle sets the local angle (in radians) of the transform

func (*TransformItem) SetParent added in v0.3.0

func (t *TransformItem) SetParent(parent TransformGetter)

SetParent sets the parent transform

func (*TransformItem) SetPos added in v0.3.0

func (t *TransformItem) SetPos(x, y float64)

SetPos sets the transform x and y position (relative to the parent)

func (*TransformItem) SetScale added in v0.3.0

func (t *TransformItem) SetScale(sx, sy float64)

SetScale sets the x and y scale of the transform (1 = 100%; 0.0 = 0%)

func (*TransformItem) SetScale2 added in v0.3.0

func (t *TransformItem) SetScale2(s float64)

SetScale2 sets the x and y scale of the transform (1 = 100%; 0.0 = 0%)

func (*TransformItem) SetX added in v0.3.0

func (t *TransformItem) SetX(x float64)

SetX sets the X position of the transform

func (*TransformItem) SetY added in v0.3.0

func (t *TransformItem) SetY(y float64)

SetY sets the Y position of the transform

func (*TransformItem) X added in v0.4.0

func (t *TransformItem) X() float64

X gets the x position of the transform

func (*TransformItem) Y added in v0.4.0

func (t *TransformItem) Y() float64

Y gets the y position of the transform

type Transformer added in v0.3.0

type Transformer interface {
	TransformGetter
	TransformChild
}

Transformer is the interface of an object with a Transform component

type WorldItem

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

WorldItem implements Object

func (*WorldItem) Entity

func (wi *WorldItem) Entity() ecs.Entity

Entity an ID

func (*WorldItem) UpsertDrawFns added in v0.4.0

func (wi *WorldItem) UpsertDrawFns(beforefn, fn, afterfn core.DrawFn) bool

UpsertDrawFns upserts the core.DrawFn component to this object's entity

func (*WorldItem) UpsertFns

func (wi *WorldItem) UpsertFns(beforefn, fn, afterfn core.UpdateFn) bool

UpsertFns upserts the core.UpdateFn component to this object's entity

func (*WorldItem) World

func (wi *WorldItem) World() *ecs.World

World of this object instance

type WorldTag

type WorldTag = string

WorldTag is a tag used to filter systems of a world

const (
	// WorldTagDraw -> systems that draw things
	WorldTagDraw WorldTag = "draw"
	// WorldTagUpdate -> systems that update things (!= draw)
	WorldTagUpdate WorldTag = "update"
)

type WorldTransform added in v0.3.0

type WorldTransform interface {
	TransformGetter
	World() *ecs.World
}

WorldTransform is minimum interface to most objects with a transform component

Directories

Path Synopsis
cmd
aseprimen command
atlaspreview command
editor command
tcli command
Package core contains lower level component systems.
Package core contains lower level component systems.
examples
layers/res
Code generated by broccoli at 2020-06-07T18:39:46-03:00.
Code generated by broccoli at 2020-06-07T18:39:46-03:00.
transform2 command
io
os
pb
Package rx holds default resources for Primen
Package rx holds default resources for Primen

Jump to

Keyboard shortcuts

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