engo

package module
v0.0.0-...-8fc0beb Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2016 License: MIT Imports: 15 Imported by: 0

README

Engo

GoDoc License Build Status Build status Go Report Card Coverage 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, supporting Android and the inception of iOS compatibility, mobile has been be added as a release target. Web support (gopherjs) is also available.

This table shows the current state of what's working and what's not. We are aiming to turn all No columns into Yes columns.

Aspect/Target Linux Windows OSX WebGL Android iOS*
Compilation Yes Yes Yes Yes Yes ?
AudioSystem Yes No Yes No No ?
RenderSystem Yes Yes Yes Yes Yes ?
XXXXXSystem Yes Yes Yes Yes Yes ?

*iOS will not build at all (due to gomobile limitations), if it would, most of these would be supported the same way Android is.

We are working towards a 1.0 release, and making good progress. We welcome any contributions.

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

Theory: common vs engo

There are currently two major important packages within this repository: engo.io/engo and engo.io/engo/common.

The top level engo package contains the functionality of creating windows, starting the game, creating an OpenGL context and handling input. It is designed to be used with Systems designed as per engo.io/ecs specifications. The common package contains our ECS implementations of common game development Systems like a RenderSystem or CameraSystem.

Practice: Getting it to Run
  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 you'll need a gcc compiler that the go tool can use and have gcc.exe in your PATH environmental variable. We recommend Mingw since it has been tested.
  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 tutorial 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.

  • engo.PreloadedSpriteSingle is now engo.LoadedSprite
  • engo.Files.Load and engo.Files.LoadMany have been merged into one function engo.Files.Load which does the same thing as engo.Files.LoadMany allowing an indefinite ammount of parameters to be passed in.
  • engo has been split in engo (which contains stuff about creating windows, starting the game, creating an OpenGL context, input handling, etc.) - and common (which contains a lot of common System implementations for common tasks (RenderSystem, CameraSystem, AudioSystem, etc.)
  • engo.Width() and engo.Height() have been changed to engo.GameWidth() and engo.GameHeight() respectively.
  • RenderComponent.Scale is now no longer a method, but a variable you can change / access directly.
  • engo.NewRenderComponent was removed. You can now define the values you want directly by using engo.RenderComponent{}. Note that the Drawable is still required.
  • 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.
  • github.com/EngoEngine/engo -> engo.io/engo - Our packages engo, ecs and gl 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. None of this would be possible without you, and your help has been truly amazing.

These are 3rd party projects that have made engo possible.

Documentation

Index

Constants

View Source
const (
	// DefaultVerticalAxis is the name of the default vertical axis, as used internally in `engo` when `StandardInputs`
	// is defined.
	DefaultVerticalAxis = "vertical"

	// DefaultHorizontalAxis is the name of the default horizontal axis, as used internally in `engo` when `StandardInputs`
	// is defined.
	DefaultHorizontalAxis = "horizontal"
	DefaultMouseXAxis     = "mouse x"
	DefaultMouseYAxis     = "mouse y"
)
View Source
const (
	// AxisMax is the maximum value a joystick or keypress axis will reach
	AxisMax float32 = 1
	// AxisMin is the value an axis returns if there has been to state change.
	AxisNeutral float32 = 0
	// AxisMin is the minimum value a joystick or keypress axis will reach
	AxisMin float32 = -1
)
View Source
const (
	// KeyStateUp is a state for when the key is not currently being pressed
	KeyStateUp = iota
	// KeyStateDown is a state for when the key is currently being pressed
	KeyStateDown
	// KeyStateJustDown is a state for when a key was just pressed
	KeyStateJustDown
	// KeyStateJustUp is a state for when a key was just released
	KeyStateJustUp
)
View Source
const (
	// Epsilon is some tiny value that determines how precisely equal we want our
	// floats to be.
	Epsilon float32 = 1e-3
	// MinNormal is the smallest normal value possible.
	MinNormal = float32(1.1754943508222875e-38) // 1 / 2**(127 - 1)
)

Variables

View Source
var (
	// Time is the active FPS counter
	Time *Clock

	// Input handles all input: mouse, keyboard and touch
	Input *InputManager

	// Mailbox is used by all Systems to communicate
	Mailbox *MessageManager
)
View Source
var (
	// Move is an action representing mouse movement
	Move = Action(0)
	// Press is an action representing a mouse press/click
	Press = Action(1)
	// Release is an action representing a mouse a release
	Release = Action(2)
	// Neutral represents a neutral action
	Neutral = Action(99)
	// Shift represents the shift modifier.
	// It is triggered when the shift key is pressed simultaneously with another key
	Shift = Modifier(0x0001)
	// Control represents the control modifier
	// It is triggered when the ctrl key is pressed simultaneously with another key
	Control = Modifier(0x0002)
	// Alt represents the alt modifier
	// It is triggered when the alt key is pressed simultaneously with another key
	Alt = Modifier(0x0004)
	// Super represents the super modifier
	// (Windows key on Microsoft Windows, Command key on Apple OSX, and varies on Linux)
	// It is triggered when the super key is pressed simultaneously with another key
	Super = Modifier(0x0008)
)
View Source
var Files = &Formats{formats: make(map[string]FileLoader)}

Files manages global resource handling of registered file formats for game assets.

View Source
var (

	// Gl is the current OpenGL context
	Gl *gl.Context
)

Functions

func CanvasHeight

func CanvasHeight() float32

func CanvasWidth

func CanvasWidth() float32

func CreateWindow

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

func CrossProduct

func CrossProduct(this, that Point) float32

CrossProduct returns the 2 dimensional cross product of this and that, which represents the magnitude of the three dimensional cross product

func CursorPos

func CursorPos() (x, y float32)

func DestroyWindow

func DestroyWindow()

func DotProduct

func DotProduct(this, that Point) float32

DotProduct returns the dot product between this and that

func Exit

func Exit()

Exit is the safest way to close your game, as `engo` will correctly attempt to close all windows, handlers and contexts

func FloatEqual

func FloatEqual(a, b float32) bool

FloatEqual is a safe utility function to compare floats. It's Taken from http://floating-point-gui.de/errors/comparison/

It is slightly altered to not call Abs when not needed.

func FloatEqualThreshold

func FloatEqualThreshold(a, b, epsilon float32) bool

FloatEqualThreshold is a utility function to compare floats. It's Taken from http://floating-point-gui.de/errors/comparison/

It is slightly altered to not call Abs when not needed.

This differs from FloatEqual in that it lets you pass in your comparison threshold, so that you can adjust the comparison value to your specific needs

func GameHeight

func GameHeight() float32

GameHeight returns the current game height

func GameWidth

func GameWidth() float32

GameWidth returns the current game width

func Headless

func Headless() bool

Headless indicates whether or not OpenGL-calls should be made

func LineTraceFraction

func LineTraceFraction(tracer, boundary *Line) float32

LineTraceFraction returns the trace fraction of tracer through boundary 1 means no intersection 0 means tracer's origin lies on the boundary line

func RegisterScene

func RegisterScene(s Scene)

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

func Run

func Run(o RunOptions, defaultScene Scene)

Run is called to create a window, initialize everything, and start the main loop. Once this function returns, the game window has been closed already. You can supply a lot of options within `RunOptions`, and your starting `Scene` should be defined in `defaultScene`.

func RunIteration

func RunIteration()

RunIteration runs one iteration per frame

func RunPreparation

func RunPreparation(defaultScene Scene)

RunPreparation is called automatically when calling Open. It should only be called once.

func ScaleOnResize

func ScaleOnResize() bool

ScaleOnResizes indicates whether or not the screen should resize (i.e. make things look smaller/bigger) whenever the window resized. If `false`, then the size of the screen does not affect the size of the things drawn - it just makes less/more objects visible

func SetCursor

func SetCursor(c Cursor)

SetCursor sets the pointer of the mouse to the defined standard cursor

func SetFPSLimit

func SetFPSLimit(limit int) error

SetFPSLimit can be used to change the value in the given `RunOpts` after already having called `engo.Run`.

func SetHeadless

func SetHeadless(b bool)

SetHeadless sets the headless-mode variable - should be used before calling `Run`, and will be overridden by the value within the `RunOpts` once you call `engo.Run`.

func SetOverrideCloseAction

func SetOverrideCloseAction(value bool)

SetOverrideCloseAction can be used to change the value in the given `RunOpts` after already having called `engo.Run`.

func SetScaleOnResize

func SetScaleOnResize(b bool)

SetScaleOnResize can be used to change the value in the given `RunOpts` after already having called `engo.Run`.

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 WindowHeight

func WindowHeight() float32

func WindowSize

func WindowSize() (w, h int)

func WindowWidth

func WindowWidth() float32

Types

type AABB

type AABB struct {
	Min, Max Point
}

AABB describes two points of a rectangle: the upper-left corner and the lower-right corner. It should always hold that `Min.X <= Max.X` and `Min.Y <= Max.Y`.

type Action

type Action int

Action corresponds to a control action such as move, press, release

type Axis

type Axis struct {
	// Name represents the name of the axis (Horizontal, Vertical)
	Name string
	// Pairs represents the axis pairs of this acis
	Pairs []AxisPair
}

An Axis is an input which is a spectrum of values. An example of this is the horizontal movement in a game, or how far a joystick is pressed.

func (Axis) Value

func (a Axis) Value() float32

Value returns the value of an Axis.

type AxisKeyPair

type AxisKeyPair struct {
	Min Key
	Max Key
}

An AxisKeyPair is a set of Min/Max values used for detecting whether or not a key has been pressed.

func (AxisKeyPair) Value

func (keys AxisKeyPair) Value() float32

Value returns the value of a keypress.

type AxisMouse

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

AxisMouse is an axis for a single x or y component of the Mouse. The value returned from it is the delta movement, since the previous call and it is not constrained by the AxisMin and AxisMax values.

func NewAxisMouse

func NewAxisMouse(d AxisMouseDirection) *AxisMouse

NewAxisMouse creates a new Mouse Axis in either direction AxisMouseVert or AxisMouseHori.

func (*AxisMouse) Value

func (am *AxisMouse) Value() float32

Value returns the delta of a mouse movement.

type AxisMouseDirection

type AxisMouseDirection uint

AxisMouseDirection is the direction (X or Y) which the mouse is being tracked for.

const (
	// AxisMouseVert is vertical mouse axis
	AxisMouseVert AxisMouseDirection = 0
	// AxisMouseHori is vertical mouse axis
	AxisMouseHori AxisMouseDirection = 1
)

type AxisPair

type AxisPair interface {
	Value() float32
}

An AxisPair is a set of Min/Max values which could possible be used by an Axis.

type Button

type Button struct {
	Triggers []Key
	Name     string
}

A Button is an input which can be either JustPressed, JustReleased or Down. Common uses would be for, a jump key or an action key.

func (Button) Down

func (b Button) Down() bool

Down checks whether the current input is being held down.

func (Button) JustPressed

func (b Button) JustPressed() bool

JustPressed checks whether an input was pressed in the previous frame.

func (Button) JustReleased

func (b Button) JustReleased() bool

JustReleased checks whether an input was released in the previous frame.

type Clock

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

A Clock is a measurement built in `engo` to measure the actual frames per seconds (framerate).

func NewClock

func NewClock() *Clock

NewClock creates a new timer which allows you to measure ticks per seconds. Be sure to call `Tick()` whenever you want a tick to occur - it does not automatically tick each frame.

func (*Clock) Delta

func (c *Clock) Delta() float32

Delta is the amount of seconds between the last tick and the one before that

func (*Clock) FPS

func (c *Clock) FPS() float32

FPS is the amount of frames per second, computed every time a tick occurs at least a second after the previous update

func (*Clock) Tick

func (c *Clock) Tick()

Tick indicates a new tick/frame has occurred.

func (*Clock) Time

func (c *Clock) Time() float32

Time is the number of seconds the clock has been running

type Container

type Container interface {
	// Contains reports whether the container contains the given point.
	Contains(p Point) bool
}

A Container is a 2D closed shape which contains a set of points.

type Cursor

type Cursor uint8

Cursor is a reference to standard cursors, to be used in conjunction with `SetCursor`. What they look like, is different for each platform.

const (
	// CursorNone can be used to reset the cursor.
	CursorNone Cursor = iota
	// CursorArrow represents an arrow cursor
	CursorArrow
	// CursorCrosshair represents a crosshair cursor
	CursorCrosshair
	// CursorHand represents a hand cursor
	CursorHand
	// CursorIBeam represents an IBeam cursor
	CursorIBeam
	// CursorHResize represents a HResize cursor
	CursorHResize
	// CursorVResize represents a VResize cursor
	CursorVResize
)

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()
}

Exiter is an optional interface a Scene can implement, indicating it'll have custom behavior whenever the game get closed.

type FileLoader

type FileLoader interface {
	// Load loads the given resource into memory.
	Load(url string, data io.Reader) error

	// Unload releases the given resource from memory.
	Unload(url string) error

	// Resource returns the given resource, and an error if it didn't succeed.
	Resource(url string) (Resource, error)
}

FileLoader implements support for loading and releasing file resources.

type Formats

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

Formats manages resource handling of registered file formats.

func (*Formats) Load

func (formats *Formats) Load(urls ...string) error

Load loads the given resource(s) into memory, stopping at the first error.

func (*Formats) Register

func (formats *Formats) Register(ext string, loader FileLoader)

Register registers a resource loader for the given file format.

func (*Formats) Resource

func (formats *Formats) Resource(url string) (Resource, error)

Resource returns the given resource, and an error if it didn't succeed.

func (*Formats) SetRoot

func (formats *Formats) SetRoot(root string)

SetRoot can be used to change the default directory from `assets` to whatever you want.

Whenever `root` does not start with the directory `assets`, you will not be able to support mobile (Android/iOS) since they require you to put all resources within the `assets` directory. More information about that is available here: https://godoc.org/golang.org/x/mobile/asset

You can, however, use subfolders within the `assets` folder, and set those as `root`.

func (*Formats) Unload

func (formats *Formats) Unload(url string) error

Unload releases the given resource from memory.

type Hider

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

Hider is an optional interface a Scene can implement, indicating it'll have custom behavior whenever the Scene get hidden to make room fr other Scenes.

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 InputManager

type InputManager struct {
	// Mouse is InputManager's reference to the mouse. It is recommended to use the
	// Axis and Button system if at all possible.
	Mouse Mouse
	// contains filtered or unexported fields
}

InputManager contains information about all forms of input.

func NewInputManager

func NewInputManager() *InputManager

NewInputManager holds onto anything input related for engo

func (*InputManager) Axis

func (im *InputManager) Axis(name string) Axis

Axis retrieves an Axis with a specified name.

func (*InputManager) Button

func (im *InputManager) Button(name string) Button

Button retrieves a Button with a specified name.

func (*InputManager) RegisterAxis

func (im *InputManager) RegisterAxis(name string, pairs ...AxisPair)

RegisterAxis registers a new axis which can be used to retrieve inputs which are spectrums.

func (*InputManager) RegisterButton

func (im *InputManager) RegisterButton(name string, keys ...Key)

RegisterButton registers a new button input.

type Key

type Key int

Key correspends to a keyboard key

var (
	// Grave represents the '`' keyboard key
	Grave Key = 192
	// Dash represents the '-' keyboard key
	Dash Key = 189
	// Apostrophe represents the `'` keyboard key
	Apostrophe Key = 222
	// Semicolon represents the ';' keyboard key
	Semicolon Key = 186
	// Equals reprsents the '=' keyboard key
	Equals Key = 187
	// Comma represents the ',' keyboard key
	Comma Key = 188
	// Period represents the '.' keyboard key
	Period Key = 190
	// Slash represents the '/' keyboard key
	Slash Key = 191
	// Backslash represents the '\' keyboard key
	Backslash Key = 220
	//Backspace represents the backspace keyboard key
	Backspace Key = 8
	// Tab represents the tab keyboard key
	Tab Key = 9
	// CapsLock represents the caps lock keyboard key
	CapsLock Key = 20
	// Space represents the space keyboard key
	Space Key = 32
	// Enter represents the enter keyboard key
	Enter Key = 13
	// Escape represents the escape keyboard key
	Escape Key = 27
	// Insert represents the insert keyboard key
	Insert Key = 45
	// PrintScreen represents the print screen keyboard key often
	// represented by 'Prt Scrn', 'Prt Scn', or 'Print Screen'
	PrintScreen Key = 42
	// Delete represents the delete keyboard key
	Delete Key = 46
	// PageUp represents the page up keyboard key
	PageUp Key = 33
	// PageDown represents the page down keyboard key
	PageDown Key = 34
	// Home represents the home keyboard key
	Home Key = 36
	// End represents the end keyboard key
	End Key = 35
	// Pause represents the pause keyboard key
	Pause Key = 19
	// ScrollLock represents the scroll lock keyboard key
	ScrollLock Key = 145
	// AllowLeft represents the arrow left keyboard key
	ArrowLeft Key = 37
	// ArrowRight represents the arrow right keyboard key
	ArrowRight Key = 39
	// ArrowDown represents the down arrow keyboard key
	ArrowDown Key = 40
	// ArrowUp represents the up arrow keyboard key
	ArrowUp Key = 38
	// LeftBracket represents the '[' keyboard key
	LeftBracket Key = 219
	// LeftShift represents the left shift keyboard key
	LeftShift Key = 16
	// LeftControl represents the left control keyboard key
	LeftControl Key = 17
	// LeftSuper represents the left super keyboard key
	// (Windows key on Microsoft Windows, Command key on Apple OSX, and varies on Linux)
	LeftSuper Key = 73
	// LeftAlt represents the left alt keyboard key
	LeftAlt Key = 18
	// RightBracket represents the ']' keyboard key
	RightBracket Key = 221
	// RightShift represents the right shift keyboard key
	RightShift Key = 16
	// RightControl represents the right control keyboard key
	RightControl Key = 17
	// RightSuper represents the right super keyboard key
	// (Windows key on Microsoft Windows, Command key on Apple OSX, and varies on Linux)
	RightSuper Key = 73
	// RightAlt represents the left alt keyboard key
	RightAlt Key = 18
	// Zero represents the '0' keyboard key
	Zero Key = 48
	// One represents the '1' keyboard key
	One Key = 49
	// Two represents the '2' keyboard key
	Two Key = 50
	// Three represents the '3' keyboard key
	Three Key = 51
	// Four represents the '4' keyboard key
	Four Key = 52
	// Five represents the '5' keyboard key
	Five Key = 53
	// Six represents the '6' keyboard key
	Six Key = 54
	// Seven represents the '7' keyboard key
	Seven Key = 55
	// Eight represents the '8' keyboard key
	Eight Key = 56
	// Nine represents the  '9' keyboard key
	Nine Key = 57
	// F1 represents the 'F1' keyboard key
	F1 Key = 112
	// F2 represents the 'F2' keyboard key
	F2 Key = 113
	// F3 represents the 'F3' keyboard key
	F3 Key = 114
	// F4 represents the 'F4' keyboard key
	F4 Key = 115
	// F5 represents the 'F5' keyboard key
	F5 Key = 116
	// F6 represents the 'F6' keyboard key
	F6 Key = 117
	// F7 represents the 'F7' keyboard key
	F7 Key = 118
	// F8 represents the 'F8' keyboard key
	F8 Key = 119
	// F9 represents the 'F9' keyboard key
	F9 Key = 120
	// F10 represents the 'F10' keyboard key
	F10 Key = 121
	// F11 represents the 'F11' keyboard key
	F11 Key = 122
	// F12 represents the 'F12' keyboard key
	F12 Key = 123
	// A represents the 'A' keyboard key
	A Key = 65
	// B represents the 'B' keyboard key
	B Key = 66
	// C represents the 'C' keyboard key
	C Key = 67
	// D represents the 'D' keyboard key '
	D Key = 68
	// E represents the 'E' keyboard key
	E Key = 69
	// F represents the 'F' keyboard key
	F Key = 70
	// G represents the 'G' keyboard key
	G Key = 71
	// H represents the 'H' keyboard key
	H Key = 72
	// I represents the 'I' keyboard key
	I Key = 73
	// J represents the 'J' keyboard key
	J Key = 74
	// K represents the 'K' keyboard key
	K Key = 75
	// L represents the 'L' keyboard key
	L Key = 76
	// M represents the 'M' keyboard key
	M Key = 77
	// N represents the 'N' keyboard key
	N Key = 78
	// O represents the 'O' keyboard key
	O Key = 79
	// P represents the 'P' keyboard key
	P Key = 80
	// Q represents the 'Q' keyboard key
	Q Key = 81
	// R represents the 'R' keyboard key
	R Key = 82
	// S represents the 'S' keyboard key
	S Key = 83
	// T represents the 'T' keyboard key
	T Key = 84
	// U represents the 'U' keyboard key
	U Key = 85
	// V represents the 'V' keyboard key
	V Key = 86
	// W represents the 'W' keyboard key
	W Key = 87
	// X represents the 'X' keyboard key
	X Key = 88
	// Y represents the 'Y' keyboard key
	Y Key = 89
	// Z represents the 'Z' keyboard key
	Z Key = 90
	// NumLock represents the NumLock keyboard key on the numpad
	NumLock Key = 144
	// NumMultiply represents the NumMultiply keyboard key on the numpad
	NumMultiply Key = 106
	// NumDivide represents the NumDivide keyboard key on the numpad
	NumDivide Key = 111
	// NumAdd represents the NumAdd keyboard key on the numpad
	NumAdd Key = 107
	// NumSubtract represents the NumSubtract keyboard key on the numpad
	NumSubtract Key = 109
	// NumZero represents the NumZero keyboard key on the numpad
	NumZero Key = 96
	// NumOne represents the NumOne keyboard key on the numpad
	NumOne Key = 97
	// NumTwo represents the NumTwo keyboard key on the numpad
	NumTwo Key = 98
	// NumThree represents the NumThree keyboard key on the numpad
	NumThree Key = 99
	// NumFour represents the NumFour keyboard key on the numpad
	NumFour Key = 100
	// NumFive represents the NumFive keyboard key on the numpad
	NumFive Key = 101
	// NumSiz represents the NumSix keyboard key on the numpad
	NumSix Key = 102
	// NumSeven represents the NumSeven keyboard key on the numpad
	NumSeven Key = 103
	// NumEight represents the NumEight keyboard key on the numpad
	NumEight Key = 104
	// NumNine represents the NumNine keyboard key on the numpad
	NumNine Key = 105
	// NumDecimal represents the NumDecimal keyboard key on the numpad
	NumDecimal Key = 110
	// NumEnter represents the NumEnter keyboard key on the numpad
	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

type KeyManager

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

KeyManager tracks which keys are pressed and released at the current point of time.

func NewKeyManager

func NewKeyManager() *KeyManager

NewKeyManager creates a new KeyManager.

func (*KeyManager) Get

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

Get retrieves a keys state.

func (*KeyManager) Set

func (km *KeyManager) Set(k Key, state bool)

Set is used for updating whether or not a key is held down, or not held down.

type KeyState

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

KeyState is used for detecting the state of a key press.

func (KeyState) Down

func (key KeyState) Down() bool

Down returns wether a key is being pressed

func (KeyState) JustPressed

func (key KeyState) JustPressed() bool

JustPressed returns whether a key was just pressed

func (KeyState) JustReleased

func (key KeyState) JustReleased() bool

JustReleased returns whether a key was just released

func (*KeyState) State

func (key *KeyState) State() int

State returns the raw state of a key.

func (KeyState) Up

func (key KeyState) Up() bool

Up returns wheter a key is not being pressed

type Line

type Line struct {
	P1 Point
	P2 Point
}

Line describes a line segment on a 2 dimensional euclidean space it can also be thought of as a 2 dimensional vector with an offset

func (*Line) Angle

func (l *Line) Angle() float32

Angle returns the euclidean angle of l relative to Y = 0

func (*Line) Normal

func (l *Line) Normal() Point

Normal returns the left hand normal of the line segment l

func (*Line) PointDistance

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

PointDistance Returns the squared euclidean distance from the point p to the line segment l

func (*Line) PointDistanceSquared

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

PointDistanceSquared returns the squared euclidean distance from the point p to the line segment l

func (*Line) PointSide

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

PointSide returns which side of the line l the point p sits on

type Message

type Message interface {
	Type() string
}

A Message is used to send messages within the MessageManager

type MessageHandler

type MessageHandler func(msg Message)

A MessageHandler is used to dispatch a message to the subscribed handler.

type MessageManager

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

MessageManager manages messages and subscribed handlers

func (*MessageManager) Dispatch

func (mm *MessageManager) Dispatch(message Message)

Dispatch sends a message to all subscribed handlers of the message's type

func (*MessageManager) Listen

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

Listen subscribes to the specified message type and calls the specified handler when fired

type Modifier

type Modifier int

Modifier represents a special key pressed along with another key

type Mouse

type Mouse struct {
	X, Y             float32
	ScrollX, ScrollY float32
	Action           Action
	Button           MouseButton
	Modifer          Modifier
}

type MouseButton

type MouseButton int

MouseButton corresponds to a mouse button.

const (
	// MouseButtonLeft represents the left mouse button
	MouseButtonLeft MouseButton = 0
	// MouseButtonRight represents the right mouse button
	MouseButtonRight MouseButton = 1
	// MouseButtonMiddle represent the middle mosue button
	MouseButtonMiddle MouseButton = 2
	// MouseButton4 represents the 4th mouse button
	MouseButton4 MouseButton = 3
	// MouseButton5 represents the 5th mouse button
	MouseButton5 MouseButton = 4
	// MouseButton6 represents the 6th mouse button
	MouseButton6 MouseButton = 5
	// MouseButton7 represents the 7th mouse button
	MouseButton7 MouseButton = 6
	// MouseButton4 represents the last mouse button
	MouseButtonLast MouseButton = 7
)

Mouse buttons

type MouseState

type MouseState struct {
	// X and Y are the coordinates of the Mouse, relative to the `Canvas`.
	X, Y float32
	// ScrollX and ScrollY are the amount of scrolling the user has done with his mouse wheel in the respective directions.
	ScrollX, ScrollY float32
	// Action indicates what the gamer currently has done with his mouse.
	Action Action
	// Button indicates which button is being pressed by the gamer (if any).
	Button MouseButton
	// Modifier indicates which modifier (shift, alt, etc.) has been pressed during the Action.
	Modifier Modifier
}

MouseState represents the current state of the Mouse (or latest Touch-events).

type Point

type Point struct {
	X, Y float32
}

Point describes a coordinate in a 2 dimensional euclidean space it can also be thought of as a 2 dimensional vector from the origin

func LineIntersection

func LineIntersection(one, two *Line) Point

LineIntersection returns the point where the line segments one and two intersect

func (*Point) Add

func (p *Point) Add(p2 Point)

Add sets the components of p to the pointwise summation of p + p2

func (*Point) AddScalar

func (p *Point) AddScalar(s float32)

AddScalar adds s to each component of p

func (*Point) Equal

func (p *Point) Equal(p2 Point) bool

Equal indicates whether two points have the same value, avoiding issues with float precision

func (*Point) Multiply

func (p *Point) Multiply(p2 Point)

Multiply sets the components of p to the pointwise product of p * p2

func (*Point) MultiplyScalar

func (p *Point) MultiplyScalar(s float32)

MultiplyScalar multiplies each component of p by s

func (*Point) Normalize

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

Normalize returns the unit vector from a, and its magnitude. if you try to normalize the null vector, the return value will be null values

func (*Point) PointDistance

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

PointDistance returns the euclidean distance between p and p2

func (*Point) PointDistanceSquared

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

PointDistanceSquared returns the squared euclidean distance between p and p2

func (*Point) ProjectOnto

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

ProjectOnto returns the vector produced by projecting a on to b

func (*Point) Set

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

Set sets the coordinates of p to x and y

func (*Point) Subtract

func (p *Point) Subtract(p2 Point)

Subtract sets the components of p to the pointwise difference of p - p2

func (*Point) SubtractScalar

func (p *Point) SubtractScalar(s float32)

SubtractScalar subtracts s from each component of p

func (Point) Within

func (p Point) Within(c Container) bool

Within reports whether the point is contained within the given container.

type Resource

type Resource interface {
	// URL returns the uniform resource locator of the given resource.
	URL() string
}

Resource represents a game resource, such as an image or a sound.

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 indicates the game should run in fullscreen mode if run on a desktop
	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

	// StandardInputs is an easy way to map common inputs to actions, such as "jump" being <SPACE>, and "action" being
	// <ENTER>.
	StandardInputs bool

	// MSAA indicates the amount of samples that should be taken. Leaving it blank will default to 1, and you may
	// use any positive value you wish. It may be possible that the operating system / environment doesn't support
	// the requested amount. In that case, GLFW will (hopefully) pick the highest supported sampling count. The higher
	// the value, the bigger the performance cost.
	//
	// Our `RenderSystem` automatically calls `gl.Enable(gl.MULTISAMPLE)` (which is required to make use of it), but
	// if you're going to use your own rendering `System` instead, you will have to call it yourself.
	//
	// Also note that this value is entirely ignored in WebGL - most browsers enable it by default when available, and
	// none of them (at time of writing) allow you to tune it.
	//
	// More info at https://www.opengl.org/wiki/Multisampling
	// "With multisampling, each pixel at the edge of a polygon is sampled multiple times."
	MSAA int

	// AssetsRoot is the path where all resources (images, audio files, fonts, etc.) can be found. Leaving this at
	// empty-string, will default this to `assets`.
	//
	// Whenever using any value that does not start with the directory `assets`, you will not be able to support
	// mobile (Android/iOS), because they **require** all assets to be within the `assets` directory. You may however
	// use any subfolder-structure within that `assets` directory.
	AssetsRoot string
}

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 Shower

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

Shower is an optional interface a Scene can implement, indicating it'll have custom behavior whenever the Scene gets shown again after being hidden (due to switching to other Scenes)

type Trace

type Trace struct {
	Fraction    float32
	EndPosition Point
	*Line
}

Trace describes all the values computed from a line trace

func LineTrace

func LineTrace(tracer *Line, boundaries []*Line) Trace

LineTrace runs a series of line traces from tracer to each boundary line and returns the nearest trace values

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

Type returns the type of the current object "WindowResizeMessage"

Directories

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

Jump to

Keyboard shortcuts

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