engo

package module
v0.0.0-...-dcf2497 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2016 License: BSD-2-Clause Imports: 34 Imported by: 0

README

Engo

License Build Status

A cross-platform game engine written in Go following an interpretation of the Entity Component System paradigm. Engo is currently compilable for Mac OSX, Linux and Windows. With the release of Go 1.4, sporting Android and the inception of iOS compatibility, mobile will soon be added as a release target. Web support (gopherjs) is also planned.

Currently documentation is pretty scarce, this is because we have not completely finalized the API and are about to go through a "prettification" process in order to increase elegance and usability. For a basic up-to-date example of most features, look at the demos.

Getting in touch / Contributing

We have a gitter chat for people to join who want to further discuss engo. We are happy to discuss bugs, feature requests and would love to hear about the projects you are building!

Getting Started

  1. First, you have to install some dependencies:
  2. If you're running on Debian/Ubuntu: sudo apt-get install libopenal-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev xorg-dev libgl1-mesa-dev
  3. If you're running on Windows: download all above packages using win-builds (Open an issue to let us know about other methods)
  4. If you're on OSX, you should be OK. Open an issue if you are not
  5. Then, you can go get it: go get -u engo.io/engo
  6. Now, you have two choices:
  7. Visit our website, which hosts a full-blown toturial series on how to create your own game, and on top of that, has some conceptual explanations;
  8. Check out some demos in our demos folder.
  9. Finally, if you run into problems, if you've encountered a bug, or want to request a feature, feel free to shoot us a DM or create an issue.

Breaking Changes

Engo is currently undergoing a lot of optimizations and constantly gets new features. However, this sometimes means things break. In order to make transitioning easier for you, we have a list of those changes, with the most recent being at the top. If you run into any problems, please contact us at gitter.

  • ecs.Entity changed to ecs.BasicEntity, world.AddEntity is gone - a lot has changed here. The entire issue is described here, while this comment in particular, should help you migrate your code.
  • Renamed engo.io/webgl to engo.io/gl, because the package handles more than only webgl.
  • scene.Exit() - a Scene now also requires an Exit() function, alongside the Hide() and Show() it already required.
  • github.com/EngoEngine/engo -> engo.io/engo - Our packages engo, ecs and webgl should now be imported using the engo.io path.
  • engi.XXX -> engo.XXX - We renamed our package engi to engo.

History

Engo, originally known as Engi was written by ajhager as a general purpose Go game engine. With a desire to build it into an "ECS" game engine, it was forked to github.com/paked/engi. After passing through several iterations, it was decided that the project would be rebranded and rereleased as Engo on its own GitHub organisation.

Credits

Thank you to everyone who has worked on, or with Engo. Non of this would be possible without you, and your help has been truly amazing.

Documentation

Index

Constants

View Source
const (
	RenderSystemPriority = -1000
)

Variables

View Source
var (
	MinZoom float32 = 0.25
	MaxZoom float32 = 3
)
View Source
var (
	Time        *Clock
	Files       *Loader
	Gl          *gl.Context
	WorldBounds AABB

	Mailbox *MessageManager
)
View Source
var (
	Arrow     *glfw.Cursor
	IBeam     *glfw.Cursor
	Crosshair *glfw.Cursor
	Hand      *glfw.Cursor
	HResize   *glfw.Cursor
	VResize   *glfw.Cursor
)
View Source
var (
	Mouse mouse

	MOVE    = Action(0)
	PRESS   = Action(1)
	RELEASE = Action(2)
	NEUTRAL = Action(99)
	SHIFT   = Modifier(0x0001)
	CONTROL = Modifier(0x0002)
	ALT     = Modifier(0x0004)
	SUPER   = Modifier(0x0008)
)
View Source
var (
	Dash         = Key(189)
	Apostrophe   = Key(222)
	Semicolon    = Key(186)
	Equals       = Key(187)
	Comma        = Key(188)
	Period       = Key(190)
	Slash        = Key(191)
	Backslash    = Key(220)
	Backspace    = Key(8)
	Tab          = Key(9)
	CapsLock     = Key(20)
	Space        = Key(32)
	Enter        = Key(13)
	Escape       = Key(27)
	Insert       = Key(45)
	PrintScreen  = Key(42)
	Delete       = Key(46)
	PageUp       = Key(33)
	PageDown     = Key(34)
	Home         = Key(36)
	End          = Key(35)
	Pause        = Key(19)
	ScrollLock   = Key(145)
	ArrowLeft    = Key(37)
	ArrowRight   = Key(39)
	ArrowDown    = Key(40)
	ArrowUp      = Key(38)
	LeftBracket  = Key(219)
	LeftShift    = Key(16)
	LeftControl  = Key(17)
	LeftSuper    = Key(73)
	LeftAlt      = Key(18)
	RightBracket = Key(221)
	RightShift   = Key(16)
	RightControl = Key(17)
	RightSuper   = Key(73)
	RightAlt     = Key(18)
	Zero         = Key(48)
	One          = Key(49)
	Two          = Key(50)
	Three        = Key(51)
	Four         = Key(52)
	Five         = Key(53)
	Six          = Key(54)
	Seven        = Key(55)
	Eight        = Key(56)
	Nine         = Key(57)
	F1           = Key(112)
	F2           = Key(113)
	F3           = Key(114)
	F4           = Key(115)
	F5           = Key(116)
	F6           = Key(117)
	F7           = Key(118)
	F8           = Key(119)
	F9           = Key(120)
	F10          = Key(121)
	F11          = Key(122)
	F12          = Key(123)
	A            = Key(65)
	B            = Key(66)
	C            = Key(67)
	D            = Key(68)
	E            = Key(69)
	F            = Key(70)
	G            = Key(71)
	H            = Key(72)
	I            = Key(73)
	J            = Key(74)
	K            = Key(75)
	L            = Key(76)
	M            = Key(77)
	N            = Key(78)
	O            = Key(79)
	P            = Key(80)
	Q            = Key(81)
	R            = Key(82)
	S            = Key(83)
	T            = Key(84)
	U            = Key(85)
	V            = Key(86)
	W            = Key(87)
	X            = Key(88)
	Y            = Key(89)
	Z            = Key(90)
	NumLock      = Key(144)
	NumMultiply  = Key(106)
	NumDivide    = Key(111)
	NumAdd       = Key(107)
	NumSubtract  = Key(109)
	NumZero      = Key(96)
	NumOne       = Key(97)
	NumTwo       = Key(98)
	NumThree     = Key(99)
	NumFour      = Key(100)
	NumFive      = Key(101)
	NumSix       = Key(102)
	NumSeven     = Key(103)
	NumEight     = Key(104)
	NumNine      = Key(105)
	NumDecimal   = Key(110)
	NumEnter     = Key(13)
)

those are default values for engo_js defined here because some of them are shared with engo_glfw. engo_glfw redefines the variables it needs to other values during init() so

View Source
var (
	KEY_STATE_UP        string = "up"
	KEY_STATE_DOWN      string = "down"
	KEY_STATE_JUST_DOWN string = "justdown"
	KEY_STATE_JUST_UP   string = "justup"

	Keys KeyManager
)
View Source
var (
	DefaultShader = &defaultShader{}
	HUDShader     = &hudShader{}
)
View Source
var MasterVolume float64 = 1

Functions

func CreateWindow

func CreateWindow(title string, width, height int, fullscreen bool)

func DestroyWindow

func DestroyWindow()

func Exit

func Exit()

func Height

func Height() float32

func ImageToNRGBA

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

func IsIntersecting

func IsIntersecting(rect1 AABB, rect2 AABB) bool

func LoadShader

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

func RegisterScene

func RegisterScene(s Scene)

RegisterScene registers the `Scene`, so it can later be used by `SetSceneByName`

func Run

func Run(opts RunOptions, defaultScene Scene)

func RunIteration

func RunIteration()

RunIteration runs one iteration / frame

func RunPreparation

func RunPreparation(defaultScene Scene)

RunPreparation is called only once, and is called automatically when calling Open It is only here for benchmarking in combination with OpenHeadlessNoRun

func SetBackground

func SetBackground(c color.Color)

func SetCursor

func SetCursor(c *glfw.Cursor)

func SetFPSLimit

func SetFPSLimit(limit int) error

func SetOverrideCloseAction

func SetOverrideCloseAction(value bool)

func SetScaleOnResize

func SetScaleOnResize(b bool)

func SetScene

func SetScene(s Scene, forceNewWorld bool)

SetScene sets the currentScene to the given Scene, and optionally forcing to create a new ecs.World that goes with it.

func SetSceneByName

func SetSceneByName(name string, forceNewWorld bool) error

SetSceneByName does a lookup for the `Scene` where its `Type()` equals `name`, and then sets it as current `Scene`

func SetTitle

func SetTitle(title string)

func SetVSync

func SetVSync(enabled bool)

func Width

func Width() float32

func WindowHeight

func WindowHeight() float32

func WindowWidth

func WindowWidth() float32

Types

type AABB

type AABB struct {
	Min, Max Point
}

type Action

type Action int

type AnimationAction

type AnimationAction struct {
	Name   string
	Frames []int
}

type AnimationComponent

type AnimationComponent struct {
	Rate float32 // How often frames should increment, in seconds.

	Drawables        []Drawable       // Renderables
	Animations       map[string][]int // All possible animations
	CurrentAnimation []int            // The current animation
	// contains filtered or unexported fields
}

Component that controls animation in rendering entities

func NewAnimationComponent

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

func (*AnimationComponent) AddAnimationAction

func (ac *AnimationComponent) AddAnimationAction(action *AnimationAction)

func (*AnimationComponent) AddAnimationActions

func (ac *AnimationComponent) AddAnimationActions(actions []*AnimationAction)

func (*AnimationComponent) Cell

func (ac *AnimationComponent) Cell() Drawable

func (*AnimationComponent) NextFrame

func (ac *AnimationComponent) NextFrame()

func (*AnimationComponent) SelectAnimationByAction

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

func (*AnimationComponent) SelectAnimationByName

func (ac *AnimationComponent) SelectAnimationByName(name string)

type AnimationSystem

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

func (*AnimationSystem) Add

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

func (*AnimationSystem) Remove

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

func (*AnimationSystem) Update

func (a *AnimationSystem) Update(dt float32)

type Assets

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

func NewAssets

func NewAssets() *Assets

func (*Assets) Get

func (a *Assets) Get(path string) Image

func (*Assets) Image

func (a *Assets) Image(path string)

func (*Assets) Load

func (a *Assets) Load(onFinish func())

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) SetVolume

func (ac *AudioComponent) SetVolume(volume float64)

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) New

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

func (*AudioSystem) Remove

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

func (*AudioSystem) Update

func (a *AudioSystem) Update(dt float32)

type ByFirstgid

type ByFirstgid []TMXTileset

func (ByFirstgid) Len

func (t ByFirstgid) Len() int

func (ByFirstgid) Less

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

func (ByFirstgid) Swap

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

type CameraAxis

type CameraAxis uint8

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

const (
	XAxis CameraAxis = iota
	YAxis
	ZAxis
)

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 Clock

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

func NewClock

func NewClock() *Clock

func (*Clock) Delta

func (c *Clock) Delta() float32

func (*Clock) Fps

func (c *Clock) Fps() float32

func (*Clock) Tick

func (c *Clock) Tick()

func (*Clock) Time

func (c *Clock) Time() float32

type CollisionComponent

type CollisionComponent struct {
	Solid, Main bool
	Extra       Point
}

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) Remove

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

func (*CollisionSystem) Update

func (cs *CollisionSystem) Update(dt float32)

type Drawable

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

type EdgeScroller

type EdgeScroller struct {
	ScrollSpeed float32
	EdgeMargin  float64
}

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)

type Exiter

type Exiter interface {
	// Exit is called when the user or the system requests to close the game
	// This should be used to cleanup or prompt user if they're sure they want to close
	// To prevent the default action (close/exit) make sure to set OverrideCloseAction in
	// your RunOpts to `true`. You should then handle the exiting of the program by calling
	//    engo.Exit()
	Exit() bool
}

type Font

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

TODO FG and BG color config

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 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 Hider

type Hider interface {
	// Hide is called when an other Scene becomes active
	Hide()
}

type Image

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

func LoadImage

func LoadImage(data interface{}) Image

type ImageObject

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

func NewImageObject

func NewImageObject(img *image.NRGBA) *ImageObject

func (*ImageObject) Data

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

func (*ImageObject) Height

func (i *ImageObject) Height() int

func (*ImageObject) Width

func (i *ImageObject) Width() int

type ImageRGBA

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

func NewImageRGBA

func NewImageRGBA(img *image.RGBA) *ImageRGBA

func (*ImageRGBA) Data

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

func (*ImageRGBA) Height

func (i *ImageRGBA) Height() int

func (*ImageRGBA) Width

func (i *ImageRGBA) Width() int

type Key

type Key int

type KeyManager

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

func (*KeyManager) Get

func (km *KeyManager) Get(k Key) KeyState

type KeyState

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

func (KeyState) Down

func (key KeyState) Down() bool

func (KeyState) JustPressed

func (key KeyState) JustPressed() bool

func (KeyState) JustReleased

func (key KeyState) JustReleased() bool

func (*KeyState) State

func (key *KeyState) State() string

func (KeyState) Up

func (key KeyState) Up() bool

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, up, right, down, left Key) *KeyboardScroller

func (*KeyboardScroller) BindKeyboard

func (c *KeyboardScroller) BindKeyboard(up, right, down, left Key)

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 {
	Width      int
	Height     int
	TileWidth  int
	TileHeight int
	Tiles      []*tile
	LineBounds []Line
	Images     []*tile
}

type Line

type Line struct {
	P1 Point
	P2 Point
}

func (*Line) Angle

func (l *Line) Angle() float32

Returns the line's angle relative to Y = 0

func (*Line) LineIntersection

func (l *Line) LineIntersection(l2 Line) Point

Returns the point where the two lines intersect

func (*Line) PointDistance

func (l *Line) PointDistance(point Point) float32

Returns the squared euclidean distance from a point to a line *segment*

func (*Line) PointDistanceSquared

func (l *Line) PointDistanceSquared(point Point) float32

Returns the squared euclidean distance from a point to a line *segment*

func (*Line) PointSide

func (l *Line) PointSide(point Point) bool

Returns which side of the line the point is on This is useful if you have a point of reference

type Loader

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

func NewLoader

func NewLoader() *Loader

func (*Loader) Add

func (l *Loader) Add(urls ...string)

func (*Loader) AddFromDir

func (l *Loader) AddFromDir(url string, recurse bool)

func (*Loader) Image

func (l *Loader) Image(name string) *Texture

func (*Loader) Json

func (l *Loader) Json(name string) string

func (*Loader) Level

func (l *Loader) Level(name string) *Level

func (*Loader) Load

func (l *Loader) Load(onFinish func())

func (*Loader) Sound

func (l *Loader) Sound(name string) ReadSeekCloser

type Message

type Message interface {
	Type() string
}

type MessageHandler

type MessageHandler func(msg Message)

type MessageManager

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

func (*MessageManager) Dispatch

func (mm *MessageManager) Dispatch(message Message)

func (*MessageManager) Listen

func (mm *MessageManager) Listen(messageType string, handler MessageHandler)

type Modifier

type Modifier int

type MouseButton

type MouseButton int

MouseButton corresponds to a mouse button.

const (
	MouseButton1      MouseButton = 0 // left button
	MouseButton2      MouseButton = 1 // right button
	MouseButton3      MouseButton = 2 // middle button
	MouseButton4      MouseButton = 3
	MouseButton5      MouseButton = 4
	MouseButton6      MouseButton = 5
	MouseButton7      MouseButton = 6
	MouseButton8      MouseButton = 7
	MouseButtonLast   MouseButton = 7
	MouseButtonLeft   MouseButton = 0 // equivalent for MouseButton1
	MouseButtonRight  MouseButton = 1 // equivalent for MouseButton2
	MouseButtonMiddle MouseButton = 2 // equivalent for MouseButton3
)

Mouse buttons

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 Modifier
}

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

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) Priority

func (m *MouseSystem) Priority() int

Priority returns a priority of 10 (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(dt float32)

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 Point

type Point struct {
	X, Y float32
}

func MinimumTranslation

func MinimumTranslation(rect1 AABB, rect2 AABB) Point

func (*Point) Add

func (p *Point) Add(p2 Point)

func (*Point) AddScalar

func (p *Point) AddScalar(s float32)

func (*Point) Multiply

func (p *Point) Multiply(p2 Point)

func (*Point) MultiplyScalar

func (p *Point) MultiplyScalar(s float32)

func (*Point) Normalize

func (a *Point) Normalize() (Point, float32)

Returns the unit vector from a, and it's magnitude

func (*Point) PointDistance

func (p *Point) PointDistance(p2 Point) float32

func (*Point) PointDistanceSquared

func (p *Point) PointDistanceSquared(p2 Point) float32

func (*Point) ProjectOnto

func (a *Point) ProjectOnto(b Point) Point

Returns the vector produced by projecting a on to b

func (*Point) Set

func (p *Point) Set(x, y float32)

func (*Point) SetTo

func (p *Point) SetTo(v float32)

func (*Point) Subtract

func (p *Point) Subtract(p2 Point)

func (*Point) SubtractScalar

func (p *Point) SubtractScalar(s float32)

type ReadSeekCloser

type ReadSeekCloser interface {
	io.ReadSeeker
	io.Closer
}

ReadSeekCloser is an io.ReadSeeker and io.Closer.

type Region

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

func NewRegion

func NewRegion(texture *Texture, x, y, w, h float32) *Region

func (*Region) Height

func (r *Region) Height() float32

func (*Region) Texture

func (r *Region) Texture() *gl.Texture

func (*Region) View

func (r *Region) View() (float32, float32, float32, float32)

func (*Region) Width

func (r *Region) Width() float32

type RenderComponent

type RenderComponent struct {
	// Hidden is used to prevent drawing by OpenGL
	Hidden bool

	// Transparency is the level of transparency that is used to draw the texture
	Transparency float32

	Color color.Color
	// contains filtered or unexported fields
}

func NewRenderComponent

func NewRenderComponent(d Drawable, scale Point, label string) RenderComponent

func (*RenderComponent) Drawable

func (r *RenderComponent) Drawable() Drawable

func (*RenderComponent) Scale

func (r *RenderComponent) Scale() Point

func (*RenderComponent) SetDrawable

func (r *RenderComponent) SetDrawable(d Drawable)

func (*RenderComponent) SetScale

func (r *RenderComponent) SetScale(scale Point)

func (*RenderComponent) SetShader

func (r *RenderComponent) SetShader(s Shader)

func (*RenderComponent) SetZIndex

func (r *RenderComponent) SetZIndex(index float32)

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) 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 Resource

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

func NewResource

func NewResource(url string) Resource

type RunOptions

type RunOptions struct {
	// NoRun indicates the Open function should return immediately, without looping
	NoRun bool

	// Title is the Window title
	Title string

	// HeadlessMode indicates whether or not OpenGL calls should be made
	HeadlessMode bool

	Fullscreen bool

	Width, Height int

	// VSync indicates whether or not OpenGL should wait for the monitor to swp the buffers
	VSync bool

	// ScaleOnResize indicates whether or not engo should make things larger/smaller whenever the screen resizes
	ScaleOnResize bool

	// FPSLimit indicates the maximum number of frames per second
	FPSLimit int

	// OverrideCloseAction indicates that (when true) engo will never close whenever the gamer wants to close the
	// game - that will be your responsibility
	OverrideCloseAction bool
}

type Scene

type Scene interface {
	// Preload is called before loading resources
	Preload()

	// Setup is called before the main loop
	Setup(*ecs.World)

	// Type returns a unique string representation of the Scene, used to identify it
	Type() string
}

Scene represents a screen ingame. i.e.: main menu, settings, but also the game itself

func CurrentScene

func CurrentScene() Scene

CurrentScene returns the SceneWorld that is currently active

type Shader

type Shader interface {
	Initialize(width, height float32)
	Pre()
	Draw(texture *gl.Texture, buffer *gl.Buffer, x, y, rotation float32)
	Post()
}

type Shower

type Shower interface {
	// Show is called whenever the other Scene becomes inactive, and this one becomes the active one
	Show()
}

type SpaceComponent

type SpaceComponent struct {
	Position Point
	Width    float32
	Height   float32
}

func (SpaceComponent) AABB

func (sc SpaceComponent) AABB() AABB

func (*SpaceComponent) Center

func (sc *SpaceComponent) Center(p Point)

Center 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 Sprite

type Sprite struct {
	Position *Point
	Scale    *Point
	Anchor   *Point
	Rotation float32
	Color    color.Color
	Alpha    float32
	Region   *Region
}

func NewSprite

func NewSprite(region *Region, x, y float32) *Sprite

type Spritesheet

type Spritesheet struct {
	CellWidth, CellHeight int // The dimensions of the cells
	// 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(texture *Texture, cellWidth, cellHeight int) *Spritesheet

func (*Spritesheet) Cell

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

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() []*Region

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 TMXImgLayer

type TMXImgLayer struct {
	Name   string    `xml:"name,attr"`
	X      float64   `xml:"x,attr"`
	Y      float64   `xml:"y,attr"`
	ImgSrc TMXImgSrc `xml:"image"`
}

type TMXImgSrc

type TMXImgSrc struct {
	Source string `xml:"source,attr"`
}

type TMXLayer

type TMXLayer struct {
	Name        string `xml:"name,attr"`
	Width       int    `xml:"width,attr"`
	Height      int    `xml:"height,attr"`
	TileMapping []uint32
	// This variable doesn't need to persist, used to fill TileMapping
	CompData []byte `xml:"data"`
}

type TMXLevel

type TMXLevel struct {
	Width      int           `xml:"width,attr"`
	Height     int           `xml:"height,attr"`
	TileWidth  int           `xml:"tilewidth,attr"`
	TileHeight int           `xml:"tileheight,attr"`
	Tilesets   []TMXTileset  `xml:"tileset"`
	Layers     []TMXLayer    `xml:"layer"`
	ObjGroups  []TMXObjGroup `xml:"objectgroup"`
	ImgLayers  []TMXImgLayer `xml:"imagelayer"`
}

type TMXObj

type TMXObj struct {
	X         float64       `xml:"x,attr"`
	Y         float64       `xml:"y,attr"`
	Polylines []TMXPolyline `xml:"polyline"`
}

type TMXObjGroup

type TMXObjGroup struct {
	Name    string   `xml:"name,attr"`
	Objects []TMXObj `xml:"object"`
}

type TMXPolyline

type TMXPolyline struct {
	Points string `xml:"points,attr"`
}

type TMXTileset

type TMXTileset struct {
	Firstgid   int           `xml:"firstgid,attr"`
	Name       string        `xml:"name,attr"`
	TileWidth  int           `xml:"tilewidth,attr"`
	TileHeight int           `xml:"tileheight,attr"`
	ImageSrc   TMXTilesetSrc `xml:"image"`
	Image      *Texture
}

type TMXTilesetSrc

type TMXTilesetSrc struct {
	Source string `xml:"source,attr"`
	Width  int    `xml:"width,attr"`
	Height int    `xml:"height,attr"`
}

Just used to create levelTileset->Image

type Texture

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

func NewTexture

func NewTexture(img Image) *Texture

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 WindowResizeMessage

type WindowResizeMessage struct {
	OldWidth, OldHeight int
	NewWidth, NewHeight int
}

WindowResizeMessage is a message that's being dispatched whenever the game window is being resized by the gamer

func (WindowResizeMessage) Type

func (WindowResizeMessage) Type() string

Directories

Path Synopsis
demos
animation command
audio command
edgescroller command
exit command
falling command
headless command
hello-world command
hide command
hud command
mouse command
pong command
scale command
scenes command
zoom command

Jump to

Keyboard shortcuts

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