common

package
v0.0.0-...-6c8e288 Latest Latest
Warning

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

Go to latest
Published: May 14, 2017 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package common contains the most-common System implementations according to the `engo.io/ecs` definition, to be used in conjunction with `engo.io/engo`.

interfaces.go is intended to provide a simple means of adding components to each system Getters These are added functions to each class to allow them to meet the interfaces we use with AddByInterface methods on each system Faces The interfaces that end in "Face" are all met by a specific component, which can be composed into an Entity The word Get is used because, otherwise it would collide with the name of the object, when stored anonymously in a parent entity Ables The interfaces that end in "able" are those required by a specific system, and if an an object meets this interface it can be added to that system Note: *able* is used not *er* because they don't really do thing anything Note: The names have not been contracted for consistency, the interface is *Collisionable* not *Collidable*

Index

Constants

View Source
const (
	MouseRotatorPriority     = 100
	MouseZoomerPriority      = 110
	EdgeScrollerPriority     = 120
	KeyboardScrollerPriority = 130
	EntityScrollerPriority   = 140
)
View Source
const (
	CursorNone = iota
	CursorArrow
	CursorCrosshair
	CursorHand
	CursorIBeam
	CursorHResize
	CursorVResize
)
View Source
const MouseSystemPriority = 100
View Source
const (
	RenderSystemPriority = -1000
)

Variables

View Source
var (
	MinZoom float32 = 0.25
	MaxZoom float32 = 3

	CameraBounds engo.AABB
)
View Source
var (
	DefaultShader   = &basicShader{cameraEnabled: true}
	HUDShader       = &basicShader{cameraEnabled: false}
	LegacyShader    = &legacyShader{cameraEnabled: true}
	LegacyHUDShader = &legacyShader{cameraEnabled: false}
	TextShader      = &textShader{cameraEnabled: true}
	TextHUDShader   = &textShader{cameraEnabled: false}
)
View Source
var ErrUnknownCompression = errors.New("Unknown Compression")
View Source
var ErrUnknownEncoding = errors.New("Unknown Encoding")
View Source
var MasterVolume float64 = 1
View Source
var UnicodeCap = 200

UnicodeCap is the amount of unicode characters the fonts will be able to use, starting from index 0.

Functions

func AudioSystemPreload

func AudioSystemPreload()

AudioSystemPreload has to be called before preloading any `.wav` files

func ImageToNRGBA

func ImageToNRGBA(img image.Image, width, height int) *image.NRGBA

ImageToNRGBA takes a given `image.Image` and converts it into an `image.NRGBA`. Especially useful when transforming image.Uniform to something usable by `engo`.

func IsIntersecting

func IsIntersecting(rect1 engo.AABB, rect2 engo.AABB) bool

func LoadShader

func LoadShader(vertSrc, fragSrc string) (*gl.Program, error)

LoadShader takes a Vertex-shader and Fragment-shader, compiles them and attaches them to a newly created glProgram. It will log possible compilation errors

func MinimumTranslation

func MinimumTranslation(rect1 engo.AABB, rect2 engo.AABB) engo.Point

func SetBackground

func SetBackground(c color.Color)

func UploadTexture

func UploadTexture(img Image) *gl.Texture

UploadTexture sends the image to the GPU, to be kept in GPU RAM

Types

type Animation

type Animation struct {
	Name   string
	Frames []int
	Loop   bool
}

Animation represents properties of an animation.

type AnimationComponent

type AnimationComponent struct {
	Drawables        []Drawable            // Renderables
	Animations       map[string]*Animation // All possible animations
	CurrentAnimation *Animation            // The current animation
	Rate             float32               // How often frames should increment, in seconds.
	// contains filtered or unexported fields
}

AnimationComponent tracks animations of an entity it is part of. This component should be created using NewAnimationComponent.

func NewAnimationComponent

func NewAnimationComponent(drawables []Drawable, rate float32) AnimationComponent

NewAnimationComponent creates an AnimationComponent containing all given drawables. Animations will be played using the given rate.

func (*AnimationComponent) AddAnimation

func (ac *AnimationComponent) AddAnimation(action *Animation)

AddAnimation registers an animation under its name, making it available through SelectAnimationByName.

func (*AnimationComponent) AddAnimations

func (ac *AnimationComponent) AddAnimations(actions []*Animation)

AddAnimations registers all given animations.

func (*AnimationComponent) AddDefaultAnimation

func (ac *AnimationComponent) AddDefaultAnimation(action *Animation)

AddDefaultAnimation adds an animation which is used when no other animation is playing.

func (*AnimationComponent) Cell

func (ac *AnimationComponent) Cell() Drawable

Cell returns the drawable for the current frame.

func (*AnimationComponent) GetAnimationComponent

func (c *AnimationComponent) GetAnimationComponent() *AnimationComponent

GetAnimationComponent Provides container classes ability to fulfil the interface and be accessed more simply by systems, eg in AddByInterface Methods

func (*AnimationComponent) NextFrame

func (ac *AnimationComponent) NextFrame()

NextFrame advances the current animation by one frame.

func (*AnimationComponent) SelectAnimationByAction

func (ac *AnimationComponent) SelectAnimationByAction(action *Animation)

SelectAnimationByAction sets the current animation. An nil action value selects the default animation.

func (*AnimationComponent) SelectAnimationByName

func (ac *AnimationComponent) SelectAnimationByName(name string)

SelectAnimationByName sets the current animation. The name must be registered.

type AnimationFace

type AnimationFace interface {
	GetAnimationComponent() *AnimationComponent
}

AnimationFace allows typesafe Access to an Annonymous child AnimationComponent

type AnimationSystem

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

AnimationSystem tracks AnimationComponents, advancing their current animation.

func (*AnimationSystem) Add

func (a *AnimationSystem) Add(basic *ecs.BasicEntity, anim *AnimationComponent, render *RenderComponent)

Add starts tracking the given entity.

func (*AnimationSystem) AddByInterface

func (a *AnimationSystem) AddByInterface(o Animationable)

AddByInterface Allows an Entity to be added directly using the Animtionable interface. which every entity containing the BasicEntity,AnimationComponent,and RenderComponent anonymously, automatically satisfies.

func (*AnimationSystem) Remove

func (a *AnimationSystem) Remove(basic ecs.BasicEntity)

Remove stops tracking the given entity.

func (*AnimationSystem) Update

func (a *AnimationSystem) Update(dt float32)

Update advances the animations of all tracked entities.

type Animationable

type Animationable interface {
	BasicFace
	AnimationFace
	RenderFace
}

Animationable is the required interface for AnimationSystem.AddByInterface method

type AudioComponent

type AudioComponent struct {
	File       string
	Repeat     bool
	Background bool

	RawVolume float64
	// contains filtered or unexported fields
}

AudioComponent is a Component which is used by the AudioSystem

func (*AudioComponent) GetAudioComponent

func (c *AudioComponent) GetAudioComponent() *AudioComponent

GetAudioComponent Provides container classes ability to fulfil the interface and be accessed more simply by systems, eg in AddByInterface Methods

func (*AudioComponent) SetVolume

func (ac *AudioComponent) SetVolume(volume float64)

type AudioFace

type AudioFace interface {
	GetAudioComponent() *AudioComponent
}

AudioFace allows typesafe access to an anonymouse child AudioComponent

type AudioResource

type AudioResource struct {
	Player *Player
	// contains filtered or unexported fields
}

AudioResource is a wrapper for `*Player` which is being passed by the the `engo.Files.Resource` method in the case of `.wav` files.

func (AudioResource) URL

func (f AudioResource) URL() string

type AudioSystem

type AudioSystem struct {
	HeightModifier float32
	// contains filtered or unexported fields
}

AudioSystem is a System that allows for sound effects and / or music

func (*AudioSystem) Add

func (a *AudioSystem) Add(basic *ecs.BasicEntity, audio *AudioComponent, space *SpaceComponent)

Add adds a new entity to the AudioSystem. AudioComponent is always required, and the SpaceComponent is required as soon as AudioComponent.Background is false. (So if it's not a background noise, we want to know where it's originated from)

func (*AudioSystem) AddByInterface

func (a *AudioSystem) AddByInterface(o Audioable)

AddByInterface adds an entity to the system using the Audioable interface. This allows for entities to be added without specifying each component If you do not wish to add a SpaceComponent, call Add, with the basic, then audio components, followed by nil

func (*AudioSystem) New

func (a *AudioSystem) New(w *ecs.World)

func (*AudioSystem) Remove

func (a *AudioSystem) Remove(basic ecs.BasicEntity)

func (*AudioSystem) Update

func (a *AudioSystem) Update(dt float32)

type Audioable

type Audioable interface {
	BasicFace
	AudioFace
	SpaceFace
}

Audioable is the required interface for the AudioSystem.AddByInterface method

type BasicFace

type BasicFace interface {
	ID() uint64
	GetBasicEntity() *ecs.BasicEntity
}

BasicFace is the means of accessing the ecs.BasicEntity class , it also has the ID method, to simplfy, finding an item within a system

type ByFirstgid

type ByFirstgid []TMXTileset

func (ByFirstgid) Len

func (t ByFirstgid) Len() int

Len returns the length of t

func (ByFirstgid) Less

func (t ByFirstgid) Less(i, j int) bool

Less returns if t's i Firstgid is less than t's j

func (ByFirstgid) Swap

func (t ByFirstgid) Swap(i, j int)

Swap exchanges t's elements i and j

type CameraAxis

type CameraAxis uint8

CameraAxis is the axis at which the Camera can/has to move

const (
	XAxis CameraAxis = iota
	YAxis
	ZAxis
	Angle
)

type CameraMessage

type CameraMessage struct {
	Axis        CameraAxis
	Value       float32
	Incremental bool
	Duration    time.Duration
	// contains filtered or unexported fields
}

CameraMessage is a message that can be sent to the Camera (and other Systemers), to indicate movement

func (CameraMessage) Type

func (CameraMessage) Type() string

type CameraSystem

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

CameraSystem is a System that manages the state of the virtual camera

func (*CameraSystem) Angle

func (cam *CameraSystem) Angle() float32

Angle returns the angle (in degrees) at which the Camera is rotated

func (*CameraSystem) FollowEntity

func (cam *CameraSystem) FollowEntity(basic *ecs.BasicEntity, space *SpaceComponent)

func (*CameraSystem) New

func (cam *CameraSystem) New(*ecs.World)

func (*CameraSystem) Remove

func (cam *CameraSystem) Remove(ecs.BasicEntity)

func (*CameraSystem) Update

func (cam *CameraSystem) Update(dt float32)

func (*CameraSystem) X

func (cam *CameraSystem) X() float32

X returns the X-coordinate of the location of the Camera

func (*CameraSystem) Y

func (cam *CameraSystem) Y() float32

Y returns the Y-coordinate of the location of the Camera

func (*CameraSystem) Z

func (cam *CameraSystem) Z() float32

Z returns the Z-coordinate of the location of the Camera

type Circle

type Circle struct {
	BorderWidth float32
	BorderColor color.Color
}

Circle is a basic circular form; the dimensions / radius are controlled via the `SpaceComponent`. This was made possible by the shared knowledge of Olivier Gagnon (@hydroflame).

func (Circle) Close

func (Circle) Close()

func (Circle) Height

func (Circle) Height() float32

func (Circle) Texture

func (Circle) Texture() *gl.Texture

func (Circle) View

func (Circle) View() (float32, float32, float32, float32)

func (Circle) Width

func (Circle) Width() float32

type CollisionComponent

type CollisionComponent struct {
	Solid, Main bool
	Extra       engo.Point
	Collides    bool // Collides is true if the component is colliding with something during this pass
}

func (*CollisionComponent) GetCollisionComponent

func (c *CollisionComponent) GetCollisionComponent() *CollisionComponent

GetCollisionComponent Provides container classes ability to fulfil the interface and be accessed more simply by systems, eg in AddByInterface Methods

type CollisionFace

type CollisionFace interface {
	GetCollisionComponent() *CollisionComponent
}

CollisionFace allows typesafe access to an anonymous CollisionComponent

type CollisionMessage

type CollisionMessage struct {
	Entity collisionEntity
	To     collisionEntity
}

func (CollisionMessage) Type

func (CollisionMessage) Type() string

type CollisionSystem

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

func (*CollisionSystem) Add

func (c *CollisionSystem) Add(basic *ecs.BasicEntity, collision *CollisionComponent, space *SpaceComponent)

func (*CollisionSystem) AddByInterface

func (c *CollisionSystem) AddByInterface(o Collisionable)

AddByInterface Provides a simple way to add an entity to the system that satisfies Collisionable. Any entity containing, BasicEntity,CollisionComponent, and SpaceComponent anonymously, automatically does this.

func (*CollisionSystem) Remove

func (c *CollisionSystem) Remove(basic ecs.BasicEntity)

func (*CollisionSystem) Update

func (cs *CollisionSystem) Update(dt float32)

type Collisionable

type Collisionable interface {
	BasicFace
	CollisionFace
	SpaceFace
}

Collisionable is the required interface for the CollisionSystem.AddByInterface method

type ComplexTriangles

type ComplexTriangles struct {
	// Points are the points the form is made of. They should be defined on a scale from 0 to 1, where (0, 0) starts
	// at the top-left of the area (as defined by the `SpaceComponent`.
	// You should use a multitude of 3 points, because each triangle is defined by defining 3 points.
	Points []engo.Point

	// BorderWidth indicates the width of the border, around EACH of the Triangles it is made out of
	BorderWidth float32
	// BorderColor indicates the color of the border, around EACH of the Triangles it is made out of
	BorderColor color.Color
}

ComplexTriangles is a complex form, made out of triangles.

func (ComplexTriangles) Close

func (ComplexTriangles) Close()

func (ComplexTriangles) Height

func (ComplexTriangles) Height() float32

func (ComplexTriangles) Texture

func (ComplexTriangles) Texture() *gl.Texture

func (ComplexTriangles) View

func (ComplexTriangles) Width

func (ComplexTriangles) Width() float32

type Cursor

type Cursor uint8

Cursor is a reference to a GLFW-cursor - to be used with the `SetCursor` method.

type Drawable

type Drawable interface {
	Texture() *gl.Texture
	Width() float32
	Height() float32
	View() (float32, float32, float32, float32)
	Close()
}

type EdgeScroller

type EdgeScroller struct {
	ScrollSpeed float32
	EdgeMargin  float32
}

EdgeScroller is a System that allows for scrolling when the cursor is near the edges of the window

func (*EdgeScroller) Priority

func (*EdgeScroller) Priority() int

func (*EdgeScroller) Remove

func (*EdgeScroller) Remove(ecs.BasicEntity)

func (*EdgeScroller) Update

func (c *EdgeScroller) Update(dt float32)

TODO: Warning doesn't get the cursor position

type EntityScroller

type EntityScroller struct {
	*SpaceComponent
	TrackingBounds engo.AABB
}

EntityScroller scrolls the camera to the position of a entity using its space component

func (*EntityScroller) New

func (c *EntityScroller) New(*ecs.World)

New adjusts CameraBounds to the bounds of EntityScroller

func (*EntityScroller) Priority

func (*EntityScroller) Priority() int

func (*EntityScroller) Remove

func (*EntityScroller) Remove(ecs.BasicEntity)

func (*EntityScroller) Update

func (c *EntityScroller) Update(dt float32)

Update moves the camera to the center of the space component Values are automatically clamped to TrackingBounds by the camera

type Font

type Font struct {
	URL  string
	Size float64
	BG   color.Color
	FG   color.Color
	TTF  *truetype.Font
}

func (*Font) Create

func (f *Font) Create() error

Create is for loading fonts from the disk, given a location

func (*Font) CreatePreloaded

func (f *Font) CreatePreloaded() error

CreatePreloaded is for loading fonts which have already been defined (and loaded) within Preload

func (*Font) Render

func (f *Font) Render(text string) Texture

func (*Font) RenderNRGBA

func (f *Font) RenderNRGBA(text string) *image.NRGBA

func (*Font) TextDimensions

func (f *Font) TextDimensions(text string) (int, int, int)

type FontAtlas

type FontAtlas struct {
	Texture *gl.Texture
	// XLocation contains the X-coordinate of the starting position of all characters
	XLocation []float32
	// YLocation contains the Y-coordinate of the starting position of all characters
	YLocation []float32
	// Width contains the width in pixels of all the characters, including the spacing between characters
	Width []float32
	// Height contains the height in pixels of all the characters
	Height []float32
	// TotalWidth is the total amount of pixels the `FontAtlas` is wide; useful for determining the `Viewport`,
	// which is relative to this value.
	TotalWidth float32
	// TotalHeight is the total amount of pixels the `FontAtlas` is high; useful for determining the `Viewport`,
	// which is relative to this value.
	TotalHeight float32
}

A FontAtlas is a representation of some of the Font characters, as an image

type FontResource

type FontResource struct {
	Font *truetype.Font
	// contains filtered or unexported fields
}

FontResource is a wrapper for `*truetype.Font` which is being passed by the the `engo.Files.Resource` method in the case of `.ttf` files.

func (FontResource) URL

func (f FontResource) URL() string

type Format

type Format int

Format represents a PCM data format.

const (
	Mono8 Format = iota + 1
	Mono16
	Stereo8
	Stereo16
)

func (Format) String

func (f Format) String() string

type FragmentShaderCompilationError

type FragmentShaderCompilationError struct {
	OpenGLError string
}

FragmentShaderCompilationError is returned whenever the `LoadShader` method was unable to compile your Fragment-shader (GLSL)

func (FragmentShaderCompilationError) Error

type Image

type Image interface {
	Data() interface{}
	Width() int
	Height() int
}

type ImageLayer

type ImageLayer struct {
	// Name defines the name of the image layer given in the TMX XML / Tiled
	Name string
	// Width is the integer width of each image in this layer
	Width int
	// Height is the integer height of each image in this layer
	Height int
	// Source contains the original image filename
	Source string
	// Images contains the list of all image tiles
	Images []*tile
}

ImageLayer contains a list of its images plus all default Tiled attributes

type ImageObject

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

ImageObject is a pure Go implementation of a `Drawable`

func NewImageObject

func NewImageObject(img *image.NRGBA) *ImageObject

NewImageObject creates a new ImageObject given the image.NRGBA reference

func (*ImageObject) Data

func (i *ImageObject) Data() interface{}

Data returns the entire image.NRGBA object

func (*ImageObject) Height

func (i *ImageObject) Height() int

Height returns the maximum Y coordinate of the image

func (*ImageObject) Width

func (i *ImageObject) Width() int

Width returns the maximum X coordinate of the image

type KeyboardScroller

type KeyboardScroller struct {
	ScrollSpeed float32
	// contains filtered or unexported fields
}

KeyboardScroller is a System that allows for scrolling when certain keys are pressed

func NewKeyboardScroller

func NewKeyboardScroller(scrollSpeed float32, hori, vert string) *KeyboardScroller

func (*KeyboardScroller) BindKeyboard

func (c *KeyboardScroller) BindKeyboard(hori, vert string)

func (*KeyboardScroller) Priority

func (*KeyboardScroller) Priority() int

func (*KeyboardScroller) Remove

func (*KeyboardScroller) Remove(ecs.BasicEntity)

func (*KeyboardScroller) Update

func (c *KeyboardScroller) Update(dt float32)

type Level

type Level struct {
	// Orientation is the parsed level orientation from the TMX XML, like orthogonal, isometric, etc.
	Orientation string
	// RenderOrder is the in Tiled specified TileMap render order, like right-down, right-up, etc.
	RenderOrder string

	// TileWidth defines the width of each tile in the level
	TileWidth int
	// TileHeight defines the height of each tile in the level
	TileHeight int
	// NextObjectId is the next free Object ID defined by Tiled
	NextObjectId int
	// TileLayers contains all TileLayer of the level
	TileLayers []*TileLayer
	// ImageLayers contains all ImageLayer of the level
	ImageLayers []*ImageLayer
	// ObjectLayers contains all ObjectLayer of the level
	ObjectLayers []*ObjectLayer
	// contains filtered or unexported fields
}

Level is a parsed TMX level containing all layers and default Tiled attributes

func (*Level) Bounds

func (l *Level) Bounds() engo.AABB

Bounds returns the level boundaries as an engo.AABB object

func (*Level) Height

func (l *Level) Height() int

Height returns the integer height of the level

func (*Level) Width

func (l *Level) Width() int

Width returns the integer width of the level

type Mouse

type Mouse struct {
	// X is the current x position of the mouse in the game
	X float32
	// Y is the current y position of the mouse in the game
	Y float32
	// ScrollX is the current scrolled position on the x component
	ScrollX float32
	// ScrollY is the current scrolled position on the y component
	ScrollY float32
	// Action is the currently active Action
	Action engo.Action
	// Button is which button is being pressed on the mouse
	Button engo.MouseButton
	// Modifier is whether any modifier mouse buttons are being pressed
	Modifer engo.Modifier
}

Mouse is the representation of the physical mouse

type MouseComponent

type MouseComponent struct {
	// Clicked is true whenever the Mouse was clicked over
	// the entity space in this frame
	Clicked bool
	// Released is true whenever the left mouse button is released over the
	// entity space in this frame
	Released bool
	// Hovered is true whenever the Mouse is hovering
	// the entity space in this frame. This does not necessarily imply that
	// the mouse button was pressed down in your entity space.
	Hovered bool
	// Dragged is true whenever the entity space was clicked,
	// and then the mouse started moving (while holding)
	Dragged bool
	// RightClicked is true whenever the entity space was right-clicked
	// in this frame
	RightClicked bool
	// RightReleased is true whenever the right mouse button is released over
	// the entity space in this frame. This does not necessarily imply that
	// the mouse button was pressed down in your entity space.
	RightReleased bool
	// Enter is true whenever the Mouse entered the entity space in that frame,
	// but wasn't in that space during the previous frame
	Enter bool
	// Leave is true whenever the Mouse was in the space on the previous frame,
	// but now isn't
	Leave bool
	// Position of the mouse at any moment this is generally used
	// in conjunction with Track = true
	MouseX float32
	MouseY float32
	// Set manually this to true and your mouse component will track the mouse
	// and your entity will always be able to receive an updated mouse
	// component even if its space is not under the mouse cursor
	// WARNING: you MUST know why you want to use this because it will
	// have serious performance impacts if you have many entities with
	// a MouseComponent in tracking mode.
	// This is ideally used for a really small number of entities
	// that must really be aware of the mouse details event when the
	// mouse is not hovering them
	Track bool
	// Modifier is used to store the eventual modifiers that were pressed during
	// the same time the different click events occurred
	Modifier engo.Modifier
	// contains filtered or unexported fields
}

MouseComponent is the location for the MouseSystem to store its results; to be used / viewed by other Systems

func (*MouseComponent) GetMouseComponent

func (c *MouseComponent) GetMouseComponent() *MouseComponent

GetMouseComponent Provides container classes ability to fulfil the interface and be accessed more simply by systems, eg in AddByInterface Methods

type MouseFace

type MouseFace interface {
	GetMouseComponent() *MouseComponent
}

MouseFace allows typesafe access to an Anonymous child MouseComponent

type MouseRotator

type MouseRotator struct {
	// RotationSpeed indicates the speed at which the rotation should happen. This is being used together with the
	// movement by the mouse on the X-axis, to compute the actual rotation.
	RotationSpeed float32
	// contains filtered or unexported fields
}

MouseRotator is a System that allows for zooming when the scroll wheel is used

func (*MouseRotator) Priority

func (*MouseRotator) Priority() int

func (*MouseRotator) Remove

func (*MouseRotator) Remove(ecs.BasicEntity)

func (*MouseRotator) Update

func (c *MouseRotator) Update(float32)

type MouseSystem

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

MouseSystem listens for mouse events, and changes value for MouseComponent accordingly

func (*MouseSystem) Add

func (m *MouseSystem) Add(basic *ecs.BasicEntity, mouse *MouseComponent, space *SpaceComponent, render *RenderComponent)

Add adds a new entity to the MouseSystem.

  • RenderComponent is only required if you're using the HUDShader on this Entity.
  • SpaceComponent is required whenever you want to know specific mouse-events on this Entity (like hover, click, etc.). If you don't need those, then you can omit the SpaceComponent.
  • MouseComponent is always required.
  • BasicEntity is always required.

func (*MouseSystem) AddByInterface

func (m *MouseSystem) AddByInterface(o Mouseable)

AddByInterface adds the Entity to the system as long as it satisfies, Mouseable. Any Entity containing a BasicEntity,MouseComponent, and RenderComponent, automatically does this.

func (*MouseSystem) New

func (m *MouseSystem) New(w *ecs.World)

func (*MouseSystem) Priority

func (m *MouseSystem) Priority() int

Priority returns a priority higher than most, to ensure that this System runs before all others

func (*MouseSystem) Remove

func (m *MouseSystem) Remove(basic ecs.BasicEntity)

func (*MouseSystem) Update

func (m *MouseSystem) Update(dt float32)

type MouseZoomer

type MouseZoomer struct {
	ZoomSpeed float32
}

MouseZoomer is a System that allows for zooming when the scroll wheel is used

func (*MouseZoomer) Priority

func (*MouseZoomer) Priority() int

func (*MouseZoomer) Remove

func (*MouseZoomer) Remove(ecs.BasicEntity)

func (*MouseZoomer) Update

func (c *MouseZoomer) Update(float32)

type Mouseable

type Mouseable interface {
	BasicFace
	MouseFace
	SpaceFace
	RenderFace
}

Mouseable is the required interface for the MouseSystem AddByInterface method

type Object

type Object struct {
	// Id is the unique ID of each object defined by Tiled
	Id int
	// Name defines the name of the object given in Tiled
	Name string
	// Type contains the string type which was given in Tiled
	Type string
	// X holds the X float64 coordinate of the object in the map
	X float64
	// X holds the X float64 coordinate of the object in the map
	Y float64
	// Width is the integer width of the object
	Width int
	// Height is the integer height of the object
	Height int
}

Object is a standard TMX object with all its default Tiled attributes

type ObjectLayer

type ObjectLayer struct {
	// Name defines the name of the object layer given in the TMX XML / Tiled
	Name string
	// OffSetX is the parsed X offset for the object layer
	OffSetX float32
	// OffSetY is the parsed Y offset for the object layer
	OffSetY float32
	// Objects contains the list of (regular) Object objects
	Objects []*Object
	// PolyObjects contains the list of PolylineObject objects
	PolyObjects []*PolylineObject
}

ObjectLayer contains a list of its standard objects as well as a list of all its polyline objects

type Player

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

Player is a basic audio player that plays PCM data. Operations on a nil *Player are no-op, a nil *Player can be used for testing purposes.

func NewPlayer

func NewPlayer(src ReadSeekCloser, format Format, samplesPerSecond int64) (*Player, error)

NewPlayer returns a new Player. It initializes the underlying audio devices and the related resources. If zero values are provided for format and sample rate values, the player determines them from the source's WAV header. An error is returned if the format and sample rate can't be determined.

The audio package is only designed for small audio sources.

func (*Player) Close

func (p *Player) Close() error

Close closes the device and frees the underlying resources used by the player. It should be called as soon as the player is not in-use anymore.

func (*Player) Current

func (p *Player) Current() time.Duration

Current returns the current playback position of the audio that is being played.

func (*Player) Pause

func (p *Player) Pause() error

Pause pauses the player.

func (*Player) Play

func (p *Player) Play(background bool) error

Play buffers the source audio to the audio device and starts to play the source. If the player paused or stopped, it reuses the previously buffered resources to keep playing from the time it has paused or stopped.

func (*Player) Seek

func (p *Player) Seek(background bool, offset time.Duration) error

Seek moves the play head to the given offset relative to the start of the source.

func (*Player) SetVolume

func (p *Player) SetVolume(vol float64)

SetVolume sets the volume of the player. The range of the volume is [0, 1].

func (*Player) State

func (p *Player) State() State

State returns the player's current state.

func (*Player) Stop

func (p *Player) Stop() error

Stop stops the player.

func (*Player) Total

func (p *Player) Total(background bool) time.Duration

Total returns the total duration of the audio source.

func (*Player) Volume

func (p *Player) Volume() float64

Volume returns the current player volume. The range of the volume is [0, 1].

type PolylineObject

type PolylineObject struct {
	// Id is the unique ID of each polyline object defined by Tiled
	Id int
	// Name defines the name of the polyline object given in Tiled
	Name string
	// Type contains the string type which was given in Tiled
	Type string
	// X holds the X float64 coordinate of the polyline in the map
	X float64
	// Y holds the Y float64 coordinate of the polyline in the map
	Y float64
	// Points contains the original, unaltered points string from the TMZ XML
	Points string
	// LineBounds is the list of engo.Line objects generated from the points string
	LineBounds []*engo.Line
}

PolylineObject is a TMX polyline object with all its default Tiled attributes

type ReadSeekCloser

type ReadSeekCloser interface {
	io.ReadSeeker
	io.Closer
}

ReadSeekCloser is an io.ReadSeeker and io.Closer.

type Rectangle

type Rectangle struct {
	BorderWidth float32
	BorderColor color.Color
}

Rectangle is a basic rectangular form; the dimensions are controlled via the `SpaceComponent`.

func (Rectangle) Close

func (Rectangle) Close()

func (Rectangle) Height

func (Rectangle) Height() float32

func (Rectangle) Texture

func (Rectangle) Texture() *gl.Texture

func (Rectangle) View

func (Rectangle) View() (float32, float32, float32, float32)

func (Rectangle) Width

func (Rectangle) Width() float32

type RenderComponent

type RenderComponent struct {
	// Hidden is used to prevent drawing by OpenGL
	Hidden bool
	// Scale is the scale at which to render, in the X and Y axis. Not defining Scale, will default to engo.Point{1, 1}
	Scale engo.Point
	// Color defines how much of the color-components of the texture get used
	Color color.Color
	// Drawable refers to the Texture that should be drawn
	Drawable Drawable
	// Repeat defines how to repeat the Texture if the viewport of the texture is larger than the texture itself
	Repeat TextureRepeating
	// contains filtered or unexported fields
}

func (*RenderComponent) GetRenderComponent

func (c *RenderComponent) GetRenderComponent() *RenderComponent

GetRenderComponent Provides container classes ability to fulfil the interface and be accessed more simply by systems, eg in AddByInterface Methods

func (*RenderComponent) SetShader

func (r *RenderComponent) SetShader(s Shader)

func (*RenderComponent) SetZIndex

func (r *RenderComponent) SetZIndex(index float32)

type RenderFace

type RenderFace interface {
	GetRenderComponent() *RenderComponent
}

RenderFace allows typesafe access to an anonymous RenderComponent

type RenderSystem

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

func (*RenderSystem) Add

func (rs *RenderSystem) Add(basic *ecs.BasicEntity, render *RenderComponent, space *SpaceComponent)

func (*RenderSystem) AddByInterface

func (rs *RenderSystem) AddByInterface(o Renderable)

AddByInterface adds any Renderable to the render system. Any Entity containing a BasicEntity,RenderComponent, and SpaceComponent anonymously does this automatically

func (*RenderSystem) New

func (rs *RenderSystem) New(w *ecs.World)

func (*RenderSystem) Priority

func (*RenderSystem) Priority() int

func (*RenderSystem) Remove

func (rs *RenderSystem) Remove(basic ecs.BasicEntity)

func (*RenderSystem) Update

func (rs *RenderSystem) Update(dt float32)

type Renderable

type Renderable interface {
	BasicFace
	RenderFace
	SpaceFace
}

Renderable is the required interface for the RenderSystem.AddByInterface method

type Shader

type Shader interface {
	Setup(*ecs.World) error
	Pre()
	Draw(*RenderComponent, *SpaceComponent)
	Post()
}

type SpaceComponent

type SpaceComponent struct {
	Position engo.Point
	Width    float32
	Height   float32
	Rotation float32 // angle in degrees for the rotation to apply clockwise
}

func (SpaceComponent) AABB

func (sc SpaceComponent) AABB() engo.AABB

AABB returns the minimum and maximum point for the given SpaceComponent. It hereby takes into account the rotation of the Component - it may very well be that the Minimum as given by engo.AABB, is smaller than the Position of the object (i.e. when rotated).

This basically returns the "outer rectangle" of the plane defined by the `SpaceComponent`. Since this returns two points, a minimum and a maximum, the "rectangle" resulting from this `AABB`, is not rotated in any way. However, depending on the rotation of the `SpaceComponent`, this `AABB` may be larger than the original `SpaceComponent`.

func (*SpaceComponent) Center

func (sc *SpaceComponent) Center() engo.Point

Center gets the center position of the space component instead of its top-left point (this avoids doing the same math each time in your systems)

func (SpaceComponent) Contains

func (sc SpaceComponent) Contains(p engo.Point) bool

Contains indicates whether or not the given point is within the rectangular plane as defined by this `SpaceComponent`. If it's on the border, it is considered "not within".

func (SpaceComponent) Corners

func (sc SpaceComponent) Corners() (points [4]engo.Point)

Corners returns the location of the four corners of the rectangular plane defined by the `SpaceComponent`, taking into account any possible rotation.

func (*SpaceComponent) GetSpaceComponent

func (c *SpaceComponent) GetSpaceComponent() *SpaceComponent

GetSpaceComponent Provides container classes ability to fulfil the interface and be accessed more simply by systems, eg in AddByInterface Methods

func (*SpaceComponent) SetCenter

func (sc *SpaceComponent) SetCenter(p engo.Point)

SetCenter positions the space component according to its center instead of its top-left point (this avoids doing the same math each time in your systems)

type SpaceFace

type SpaceFace interface {
	GetSpaceComponent() *SpaceComponent
}

SpaceFace allows typesafe access to an anonymous SpaceComponent

type Spritesheet

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

Spritesheet is a class that stores a set of tiles from a file, used by tilemaps and animations

func NewSpritesheetFromFile

func NewSpritesheetFromFile(textureName string, cellWidth, cellHeight int) *Spritesheet

NewSpritesheetFromFile is a simple handler for creating a new spritesheet from a file textureName is the name of a texture already preloaded with engo.Files.Add

func NewSpritesheetFromTexture

func NewSpritesheetFromTexture(tr *TextureResource, cellWidth, cellHeight int) *Spritesheet

func (*Spritesheet) Cell

func (s *Spritesheet) Cell(index int) Texture

Cell gets the region at the index i, updates and pulls from cache if need be

func (*Spritesheet) CellCount

func (s *Spritesheet) CellCount() int

func (*Spritesheet) Cells

func (s *Spritesheet) Cells() []Texture

func (*Spritesheet) Drawable

func (s *Spritesheet) Drawable(index int) Drawable

func (*Spritesheet) Drawables

func (s *Spritesheet) Drawables() []Drawable

func (Spritesheet) Height

func (s Spritesheet) Height() float32

Height is the amount of tiles on the y-axis of the spritesheet

func (Spritesheet) Width

func (s Spritesheet) Width() float32

Width is the amount of tiles on the x-axis of the spritesheet

type State

type State int

State indicates the current playing state of the player.

const (
	Unknown State = iota
	Initial
	Playing
	Paused
	Stopped
)

func (State) String

func (s State) String() string

type TMXData

type TMXData struct {
	// Encoding defines the fomat of the Data field; Valid values are
	// one of "", "base64", or "csv"
	Encoding string `xml:"encoding,attr"`
	// Compression defines the compression applied to base64 data
	// valid values are one of "", "zlib", "gzip"
	Compression string `xml:"compression,attr"`
	// Data contains an encoded list of uint32 guids defining
	// the tile layout of a layer
	Data string `xml:",innerxml,"`
	// Tiles is an array of tiles containing guids. Not set if
	// other encodings are used
	Tiles []TMXTile `xml:tile`
}

TMXData represents custom properties which "Can be used as a child of the map, tileset, tile (when part of a tileset), layer, objectgroup, object and imagelayer elements"

func (*TMXData) Decode

func (d *TMXData) Decode() ([]uint32, error)

Decode takes the encoded data from a tmx map file and unpacks it an arrary of uint32 guids

type TMXImageLayer

type TMXImageLayer struct {
	// Name of the image layer in Tiled
	Name string `xml:"name,attr"`
	// X holds the defined X coordinate in Tiled
	X float64 `xml:"x,attr"`
	// Y holds the defined Y coordinate in Tiled
	Y float64 `xml:"y,attr"`
	// ImageSrc contains the TMXImageSrc which defines the image filename
	ImageSrc TMXImageSrc `xml:"image"`
}

TMXImageLayer represents an image layer parsed from the TileMap XML

type TMXImageSrc

type TMXImageSrc struct {
	// Source holds the URI of the image
	Source string `xml:"source,attr"`
	// Width is the integer width of the image
	Width int `xml:"width,attr"`
	// Height is the integer height of the image
	Height int `xml:"height,attr"`
}

TMXImageSrc represents the actual image source of an image layer

type TMXLevel

type TMXLevel struct {
	// Orientation is the parsed level orientation from the TMX XML, like orthogonal
	Orientation string `xml:"orientation,attr"`
	// RenderOrder is the in Tiled specified TileMap render order, like right-down
	RenderOrder string `xml:"renderorder,attr"`
	// Width is the integer width of the parsed level
	Width int `xml:"width,attr"`
	// Height is the integer height of the parsed level
	Height int `xml:"height,attr"`
	// TileWidth defines the width of each tile in the level
	TileWidth int `xml:"tilewidth,attr"`
	// TileHeight defines the height of each tile in the level
	TileHeight int `xml:"tileheight,attr"`
	// NextObjectId is the next free Object ID defined by Tiled
	NextObjectId int `xml:"nextobjectid,attr"`
	// Tilesets conatins a list of all parsed TMXTileset objects
	Tilesets []TMXTileset `xml:"tileset"`
	// TileLayers conatins a list of all parsed TMXTileLayer objects
	TileLayers []TMXTileLayer `xml:"layer"`
	// ImageLayers conatins a list of all parsed TMXImageLayer objects
	ImageLayers []TMXImageLayer `xml:"imagelayer"`
	// ObjectLayers conatins a list of all parsed TMXObjectLayer objects
	ObjectLayers []TMXObjectLayer `xml:"objectgroup"`
}

TMXLevel containing all layers and default Tiled attributes

type TMXObject

type TMXObject struct {
	// Id is the unique ID of each object defined by Tiled
	Id int `xml:"id,attr"`
	// Name defines the name of the object given in Tiled
	Name string `xml:"name,attr"`
	// Type contains the string type which was given in Tiled
	Type string `xml:"type,attr"`
	// X holds the X float64 coordinate of the object in the map
	X float64 `xml:"x,attr"`
	// Y holds the Y float64 coordinate of the object in the map
	Y float64 `xml:"y,attr"`
	// Width is the integer width of the object
	Width int `xml:"width,attr"`
	// Height is the integer height of the object
	Height int `xml:"height,attr"`
	// Polyline contains the TMXPolyline object if the parsed object has a polyline points string
	Polyline TMXPolyline `xml:"polyline"`
}

TMXObject represents a TMX object with all default Tiled attributes

type TMXObjectLayer

type TMXObjectLayer struct {
	// Name of the object layer in Tiled
	Name string `xml:"name,attr"`
	// Objects contains the list all objects in this layer
	Objects []TMXObject `xml:"object"`
	// OffSetX is the parsed X offset for the object layer
	OffSetX float32 `xml:"offsetx"`
	// OffSetY is the parsed Y offset for the object layer
	OffSetY float32 `xml:"offsety"`
}

TMXObjectLayer following the Object Layer naming convention in Tiled

type TMXPolyline

type TMXPolyline struct {
	// Points contains the original, unaltered points string from the TMZ XML
	Points string `xml:"points,attr"`
}

TMXPolyline represents a TMX Polyline object with its Points values

type TMXResource

type TMXResource struct {
	// Level holds the reference to the parsed TMX level
	Level *Level
	// contains filtered or unexported fields
}

TMXResource contains a level created from a Tile Map XML

func (TMXResource) URL

func (r TMXResource) URL() string

URL retrieves the url to the .tmx file

type TMXTile

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

TMXTile represents a single tile on a tile layer.

type TMXTileLayer

type TMXTileLayer struct {
	// Name of the tile layer in Tiled
	Name string `xml:"name,attr"`
	// Width is the integer width of each tile in this layer
	Width int `xml:"width,attr"`
	// Height is the integer height of each tile in this layer
	Height int `xml:"height,attr"`
	// TileMapping contains the generated tilemapping list
	TileMapping []uint32
	// TMXData is the encoded tile layer grid
	Data TMXData `xml:"data"`
}

TMXTileLayer represents a tile layer parsed from the TileMap XML

type TMXTileset

type TMXTileset struct {
	// Firstgid is the first assigned gid of the tileset
	Firstgid int `xml:"firstgid,attr"`
	// Name of the tileset in Tiled
	Name string `xml:"name,attr"`
	// TileWidth defines the width of each tile
	TileWidth int `xml:"tilewidth,attr"`
	// TileHeight defines the height of each tile
	TileHeight int `xml:"tileheight,attr"`
	// TileCount holds the total tile count in this tileset
	TileCount int `xml:"tilecount,attr"`
	// ImageSrc contains the TMXTilesetSrc which defines the tileset image
	ImageSrc TMXTilesetSrc `xml:"image"`
	// Image holds the reference of the tileset's TextureResource
	Image *TextureResource
}

TMXTileset contains the tileset resource parsed from the TileMap XML

type TMXTilesetSrc

type TMXTilesetSrc struct {
	// Source holds the URI of the tileset image
	Source string `xml:"source,attr"`
	// Width of each tile in the tileset image
	Width int `xml:"width,attr"`
	// Height of each tile in the tileset image
	Height int `xml:"height,attr"`
}

TMXTilesetSrc is just used to create levelTileset->Image

type Text

type Text struct {
	// Font is the reference to the font you're using to render this. This includes the color, as well as the font size.
	Font *Font
	// Text is the actual text you want to draw. This may include newlines (\n).
	Text string
	// LineSpacing is the amount of additional spacing there is between the lines (when `Text` consists of multiple lines),
	// relative to the `Size` of the `Font`.
	LineSpacing float32
	// LetterSpacing is the amount of additional spacing there is between the characters, relative to the `Size` of
	// the `Font`.
	LetterSpacing float32
	// RightToLeft is an experimental variable used to indicate that subsequent characters come to the left of the
	// previous character.
	RightToLeft bool
}

Text represents a string drawn onto the screen, as used by the `TextShader`.

func (Text) Close

func (Text) Close()

func (Text) Height

func (Text) Height() float32

func (Text) Texture

func (Text) Texture() *gl.Texture

func (Text) View

func (Text) View() (float32, float32, float32, float32)

func (Text) Width

func (Text) Width() float32

type Texture

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

Texture represents a texture loaded in the GPU RAM (by using OpenGL), which defined dimensions and viewport

func LoadedSprite

func LoadedSprite(url string) (*Texture, error)

LoadedSprite loads the texture-reference from `engo.Files`, and wraps it in a `*Texture`. This method is intended for image-files which represent entire sprites.

func NewTextureSingle

func NewTextureSingle(img Image) Texture

NewTextureSingle sends the image to the GPU and returns a `Texture` with a viewport for single-sprite images

func (Texture) Close

func (r Texture) Close()

func (Texture) Height

func (t Texture) Height() float32

Height returns the height of the texture.

func (Texture) Texture

func (t Texture) Texture() *gl.Texture

func (Texture) View

func (r Texture) View() (float32, float32, float32, float32)

func (Texture) Width

func (t Texture) Width() float32

Width returns the width of the texture.

type TextureRepeating

type TextureRepeating uint8
const (
	ClampToEdge TextureRepeating = iota
	ClampToBorder
	Repeat
	MirroredRepeat
)

type TextureResource

type TextureResource struct {
	Texture *gl.Texture
	Width   float32
	Height  float32
	// contains filtered or unexported fields
}

func NewTextureResource

func NewTextureResource(img Image) TextureResource

NewTextureResource sends the image to the GPU and returns a `TextureResource` for easy access

func (TextureResource) URL

func (t TextureResource) URL() string

type TileLayer

type TileLayer struct {
	// Name defines the name of the tile layer given in the TMX XML / Tiled
	Name string
	// Width is the integer width of each tile in this layer
	Width int
	// Height is the integer height of each tile in this layer
	Height int
	// Tiles contains the list of tiles
	Tiles []*tile
}

TileLayer contains a list of its tiles plus all default Tiled attributes

type Triangle

type Triangle struct {
	TriangleType TriangleType

	BorderWidth float32
	BorderColor color.Color
}

Triangle is a basic triangular form; the "point" of the triangle is pointing to the top

func (Triangle) Close

func (Triangle) Close()

func (Triangle) Height

func (Triangle) Height() float32

func (Triangle) Texture

func (Triangle) Texture() *gl.Texture

func (Triangle) View

func (Triangle) View() (float32, float32, float32, float32)

func (Triangle) Width

func (Triangle) Width() float32

type TriangleType

type TriangleType uint8
const (
	// Indicates a Triangle where two sides have equal length
	TriangleIsosceles TriangleType = iota
	// Indicates a Triangles where one angle is at 90 degrees
	TriangleRight
)

type VertexShaderCompilationError

type VertexShaderCompilationError struct {
	OpenGLError string
}

VertexShaderCompilationError is returned whenever the `LoadShader` method was unable to compile your Vertex-shader (GLSL)

func (VertexShaderCompilationError) Error

Jump to

Keyboard shortcuts

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