Documentation ¶
Overview ¶
Gozmo is a hardware accelerated game engine based on OpenGL, and using libraries from the go-gl project.
It is built around a entity-component-renderer structure.
The main entry point is the Window type, found in window.go for desktop OSes, and in window_android.go for Android.
Index ¶
- Variables
- func CastBool(value interface{}) (bool, error)
- func CastFloat32(number interface{}) (float32, error)
- func CastInt(number interface{}) (int, error)
- func CastUInt32(number interface{}) (uint32, error)
- func DecPerFrameStats(name string, value float64)
- func GLBufferData(location uint32, bid uint32, data []float32)
- func GLClear()
- func GLDraw(mesh *Mesh, shader uint32, width float32, height float32, textureId int32, ...)
- func GLInit(width int32, height int32)
- func GLNewArray() uint32
- func GLNewBuffer() uint32
- func GLShader() uint32
- func GLTexture(rgba *image.RGBA) uint32
- func GetPerFrameStats(name string) float64
- func IncPerFrameStats(name string, value float64)
- func IsTrue(value interface{}, err error) bool
- func RegisterComponent(name string, generator func([]interface{}) Component)
- func RegisterUpdater(updater func(scene *Scene, deltaTime float32))
- func SetPerFrameStats(name string, value float64)
- func UpdatePerFrameStats()
- type Animation
- type AnimationAction
- type AnimationFrame
- type Animator
- func (animator *Animator) GetAnimation() string
- func (animator *Animator) GetAttr(attr string) (interface{}, error)
- func (animator *Animator) GetType() string
- func (animator *Animator) Play()
- func (animator *Animator) SetAnimation(name string)
- func (animator *Animator) SetAttr(attr string, value interface{}) error
- func (animator *Animator) Start(gameObject *GameObject)
- func (animator *Animator) Stop()
- func (animator *Animator) Update(gameObject *GameObject)
- type BoxRenderer
- type Cage
- type Camera
- type Component
- type ComponentAttr
- type ComponentDestroy
- type ComponentEvent
- type ComponentType
- type EngineSingleton
- type Event
- type GameObject
- func (gameObject *GameObject) AddComponent(name string, component Component) Component
- func (gameObject *GameObject) AddComponentByName(name string, componentName string, args []interface{}) Component
- func (gameObject *GameObject) AddPosition(x float32, y float32)
- func (gameObject *GameObject) AddPositionV(vec2 Vector2)
- func (gameObject *GameObject) Destroy()
- func (gameObject *GameObject) EnqueueEvent(sender *GameObject, msg string)
- func (gameObject *GameObject) GetAttr(componentName string, attr string) (interface{}, error)
- func (gameObject *GameObject) GetComponent(name string) interface{}
- func (gameObject *GameObject) GetComponentByType(name string) interface{}
- func (gameObject *GameObject) ManageEvents()
- func (gameObject *GameObject) SetAttr(componentName string, attr string, value interface{}) error
- func (gameObject *GameObject) SetEnabled(flag bool)
- func (gameObject *GameObject) SetEuler(deg float32)
- func (gameObject *GameObject) SetOrder(order int)
- func (gameObject *GameObject) SetPosition(x float32, y float32)
- func (gameObject *GameObject) SetPositionV(vec2 Vector2)
- func (gameObject *GameObject) SetRotation(rad float32)
- func (gameObject *GameObject) SetScale(x, y float32)
- func (gameObject *GameObject) String() string
- func (gameObject *GameObject) Update()
- type HitBox
- func (hitbox *HitBox) GetAttr(attr string) (interface{}, error)
- func (hitbox *HitBox) GetName() string
- func (hitbox *HitBox) Intersect(otherBox *HitBox) bool
- func (hitbox *HitBox) SetAttr(attr string, value interface{}) error
- func (hitbox *HitBox) Start(gameObject *GameObject)
- func (hitbox *HitBox) Update(gameObject *GameObject)
- type Key
- type Keyboard
- func (keyboard *Keyboard) GetAttr(attr string) (interface{}, error)
- func (keyboard *Keyboard) GetKey(key Key) bool
- func (keyboard *Keyboard) GetName() string
- func (keyboard *Keyboard) SetAttr(attr string, value interface{}) error
- func (keyboard *Keyboard) Start(gameObject *GameObject)
- func (keyboard *Keyboard) Update(gameObject *GameObject)
- type Mesh
- type Mouse
- func (mouse *Mouse) GetAttr(attr string) (interface{}, error)
- func (mouse *Mouse) GetName() string
- func (mouse *Mouse) SetAttr(attr string, value interface{}) error
- func (mouse *Mouse) Start(gameObject *GameObject)
- func (mouse *Mouse) Update(gameObject *GameObject)
- func (mouse *Mouse) X() float32
- func (mouse *Mouse) Y() float32
- type RegisteredComponent
- type Renderer
- func (renderer *Renderer) GetAttr(attr string) (interface{}, error)
- func (renderer *Renderer) GetType() string
- func (renderer *Renderer) SetAttr(attr string, value interface{}) error
- func (renderer *Renderer) SetPixelsPerUnit(pixels uint32)
- func (renderer *Renderer) Start(gameObject *GameObject)
- func (renderer *Renderer) Update(gameObject *GameObject)
- type Rewind
- func (rewind *Rewind) GetAttr(attr string) (interface{}, error)
- func (rewind *Rewind) GetName() string
- func (rewind *Rewind) OnEvent(gameObject *GameObject, event *Event)
- func (rewind *Rewind) SetAttr(attr string, value interface{}) error
- func (rewind *Rewind) Start(gameObject *GameObject)
- func (rewind *Rewind) Update(gameObject *GameObject)
- type Scene
- func (scene *Scene) AddAnimation(name string, fps int, loop bool) *Animation
- func (scene *Scene) Destroy()
- func (scene *Scene) FindGameObject(name string) *GameObject
- func (scene *Scene) NewGameObject(name string) *GameObject
- func (scene *Scene) NewTexture(name string, width uint32, height uint32)
- func (scene *Scene) NewTextureFromFile(name string, file *os.File) (*Texture, error)
- func (scene *Scene) NewTextureFromFilename(name string, fileName string) (*Texture, error)
- func (scene *Scene) Update(now float64)
- type Texture
- type TileMap
- func (tilemap *TileMap) GetAttr(attr string) (interface{}, error)
- func (tilemap *TileMap) GetType() string
- func (tilemap *TileMap) SetAttr(attr string, value interface{}) error
- func (tilemap *TileMap) SetPixelsPerUnit(pixels uint32)
- func (tilemap *TileMap) Start(gameObject *GameObject)
- func (tilemap *TileMap) Update(gameObject *GameObject)
- type Vector2
- type Window
Constants ¶
This section is empty.
Variables ¶
var KeyboardAttr map[string]Key = map[string]Key{ "A": KeyA, "D": KeyD, "S": KeyS, "W": KeyW, "Right": KeyRight, "Left": KeyLeft, "Up": KeyUp, "Down": KeyDown, }
Rather ugly mapping, but it will simplify the "compositor's" life.
Functions ¶
func CastFloat32 ¶
func CastUInt32 ¶
func DecPerFrameStats ¶
func GLBufferData ¶
func GLNewArray ¶
func GLNewArray() uint32
func GLNewBuffer ¶
func GLNewBuffer() uint32
func GetPerFrameStats ¶
func IncPerFrameStats ¶
func RegisterComponent ¶
func RegisterUpdater ¶
func SetPerFrameStats ¶
func UpdatePerFrameStats ¶
func UpdatePerFrameStats()
Types ¶
type Animation ¶
type Animation struct { Name string Fps int Frames []*AnimationFrame Loop bool }
An Animation holds data structures that change gameObject attributes.
func (*Animation) AddFrame ¶
func (animation *Animation) AddFrame(actions []*AnimationAction) *AnimationFrame
func (*Animation) AddSimpleFrame ¶
func (animation *Animation) AddSimpleFrame(componentName string, attr string, value interface{}, interpolate bool) *AnimationFrame
type AnimationAction ¶
type AnimationFrame ¶
type AnimationFrame struct {
// contains filtered or unexported fields
}
type Animator ¶
type Animator struct {
// contains filtered or unexported fields
}
The Animator component applies animations to gameObjects.
func NewAnimator ¶
func NewAnimator() *Animator
func (*Animator) GetAnimation ¶
func (*Animator) SetAnimation ¶
func (*Animator) Start ¶
func (animator *Animator) Start(gameObject *GameObject)
func (*Animator) Update ¶
func (animator *Animator) Update(gameObject *GameObject)
type BoxRenderer ¶
BoxRenderer is an alternative renderer used for simple solid-color boxes.
func NewBoxRenderer ¶
func NewBoxRenderer(width, height float32) *BoxRenderer
Boxes are created at setup.
func (*BoxRenderer) GetAttr ¶
func (box *BoxRenderer) GetAttr(attr string) (interface{}, error)
func (*BoxRenderer) GetType ¶
func (box *BoxRenderer) GetType() string
func (*BoxRenderer) SetAttr ¶
func (box *BoxRenderer) SetAttr(attr string, value interface{}) error
func (*BoxRenderer) Start ¶
func (box *BoxRenderer) Start(gameObject *GameObject)
func (*BoxRenderer) Update ¶
func (box *BoxRenderer) Update(gameObject *GameObject)
type Cage ¶
type Cage struct {
// contains filtered or unexported fields
}
The Cage component constrains the position of gameObjects to a given area. Place it after the components you want to limit.
func (*Cage) Start ¶
func (cage *Cage) Start(gameObject *GameObject)
func (*Cage) Update ¶
func (cage *Cage) Update(gameObject *GameObject)
type Camera ¶
type Camera struct{}
The Camera component sets the current view matrix for rendering, allowing different views to coexist. It ensures that cameras are always managed before other items by setting them at at lower place.
func (*Camera) Start ¶
func (camera *Camera) Start(gameObject *GameObject)
func (*Camera) Update ¶
func (camera *Camera) Update(gameObject *GameObject)
type Component ¶
type Component interface { Start(gameObject *GameObject) Update(gameObject *GameObject) }
type ComponentAttr ¶
type ComponentDestroy ¶
type ComponentDestroy interface {
Destroy(gameObject *GameObject)
}
type ComponentEvent ¶
type ComponentEvent interface {
OnEvent(gameObject *GameObject, event *Event)
}
type ComponentType ¶
type ComponentType interface {
GetType() string
}
type EngineSingleton ¶
type EngineSingleton struct { Window *Window // contains filtered or unexported fields }
An EngineSingleton is the one struct in the whole program that holds global structures like the list of registered components. TODO: possibly merge with window.go.
var Engine EngineSingleton
type Event ¶
type Event struct { Sender *GameObject Msg string }
type GameObject ¶
type GameObject struct { // TODO: is it a good idea to allow the developer to change the game object // name and mess with internal data? Name string Scene *Scene Position mgl32.Vec2 Rotation float32 Scale mgl32.Vec2 Pivot mgl32.Vec2 DeltaTime float32 // contains filtered or unexported fields }
A GameObject stores all graphic parameters.
func (*GameObject) AddComponent ¶
func (gameObject *GameObject) AddComponent(name string, component Component) Component
func (*GameObject) AddComponentByName ¶
func (gameObject *GameObject) AddComponentByName(name string, componentName string, args []interface{}) Component
func (*GameObject) AddPosition ¶
func (gameObject *GameObject) AddPosition(x float32, y float32)
func (*GameObject) AddPositionV ¶
func (gameObject *GameObject) AddPositionV(vec2 Vector2)
func (*GameObject) Destroy ¶
func (gameObject *GameObject) Destroy()
func (*GameObject) EnqueueEvent ¶
func (gameObject *GameObject) EnqueueEvent(sender *GameObject, msg string)
func (*GameObject) GetAttr ¶
func (gameObject *GameObject) GetAttr(componentName string, attr string) (interface{}, error)
func (*GameObject) GetComponent ¶
func (gameObject *GameObject) GetComponent(name string) interface{}
func (*GameObject) GetComponentByType ¶
func (gameObject *GameObject) GetComponentByType(name string) interface{}
func (*GameObject) ManageEvents ¶
func (gameObject *GameObject) ManageEvents()
iterate the GameObject event queue and call OnEvent on each component implementing it
func (*GameObject) SetAttr ¶
func (gameObject *GameObject) SetAttr(componentName string, attr string, value interface{}) error
func (*GameObject) SetEnabled ¶
func (gameObject *GameObject) SetEnabled(flag bool)
func (*GameObject) SetEuler ¶
func (gameObject *GameObject) SetEuler(deg float32)
func (*GameObject) SetOrder ¶
func (gameObject *GameObject) SetOrder(order int)
func (*GameObject) SetPosition ¶
func (gameObject *GameObject) SetPosition(x float32, y float32)
func (*GameObject) SetPositionV ¶
func (gameObject *GameObject) SetPositionV(vec2 Vector2)
func (*GameObject) SetRotation ¶
func (gameObject *GameObject) SetRotation(rad float32)
func (*GameObject) SetScale ¶
func (gameObject *GameObject) SetScale(x, y float32)
func (*GameObject) String ¶
func (gameObject *GameObject) String() string
func (*GameObject) Update ¶
func (gameObject *GameObject) Update()
type HitBox ¶
type HitBox struct {
// contains filtered or unexported fields
}
The HitBox component is a generic AABB checker that can be used for basic collisions or area triggers. It can be attached to only one GameObject.
func NewHitBoxWithEvent ¶
func (*HitBox) Start ¶
func (hitbox *HitBox) Start(gameObject *GameObject)
func (*HitBox) Update ¶
func (hitbox *HitBox) Update(gameObject *GameObject)
type Key ¶
A Key is a keyboard mapping. By default we use the glfw names, but override them to support more platforms in the future. Not bound on Android.
const ( KeyRight Key = Key(glfw.KeyRight) KeyLeft Key = Key(glfw.KeyLeft) KeyUp Key = Key(glfw.KeyUp) KeyDown Key = Key(glfw.KeyDown) KeyA Key = Key(glfw.KeyA) KeyB Key = Key(glfw.KeyB) KeyC Key = Key(glfw.KeyC) KeyD Key = Key(glfw.KeyD) KeyP Key = Key(glfw.KeyP) KeyS Key = Key(glfw.KeyS) KeyT Key = Key(glfw.KeyT) KeyW Key = Key(glfw.KeyW) KeyEsc Key = Key(glfw.KeyEscape) )
type Keyboard ¶
type Keyboard struct{}
A Keyboard works by polling at a given time.
func NewKeyboard ¶
func NewKeyboard() *Keyboard
func (*Keyboard) Start ¶
func (keyboard *Keyboard) Start(gameObject *GameObject)
func (*Keyboard) Update ¶
func (keyboard *Keyboard) Update(gameObject *GameObject)
type Mouse ¶
type Mouse struct{}
The Mouse component converts screen coordinates into game coordinates. It only handles mouse events, not touch ones, and is not bound on Android.
func (*Mouse) Start ¶
func (mouse *Mouse) Start(gameObject *GameObject)
func (*Mouse) Update ¶
func (mouse *Mouse) Update(gameObject *GameObject)
type RegisteredComponent ¶
type RegisteredComponent struct { Name string // Called whenever a registered component is instantiated. Init func(args []interface{}) Component }
A RegisteredComponent is a component that registers itself in the Engine so that data-based systems, like the JSON loader, can access it.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
A Rendered is an accelerated sprite drawer component. It supports color addition and multiplication
func NewRenderer ¶
func (*Renderer) SetPixelsPerUnit ¶
func (*Renderer) Start ¶
func (renderer *Renderer) Start(gameObject *GameObject)
func (*Renderer) Update ¶
func (renderer *Renderer) Update(gameObject *GameObject)
type Rewind ¶
type Rewind struct {
// contains filtered or unexported fields
}
The Rewind component restores the previous GameObject state when the specific event is raised
func (*Rewind) OnEvent ¶
func (rewind *Rewind) OnEvent(gameObject *GameObject, event *Event)
func (*Rewind) Start ¶
func (rewind *Rewind) Start(gameObject *GameObject)
func (*Rewind) Update ¶
func (rewind *Rewind) Update(gameObject *GameObject)
type Scene ¶
type Scene struct { // TODO: is it a good idea to expose Name? Name string // contains filtered or unexported fields }
A Scene is a group of resources (textures, animations, sounds) and instantiated gameObjects, akin to levels in games.
When a scene is destroyed, all of the allocated resources and gameObjects are destroyed too.
func NewSceneFromFilename ¶
func (*Scene) AddAnimation ¶
func (*Scene) FindGameObject ¶
func (scene *Scene) FindGameObject(name string) *GameObject
func (*Scene) NewGameObject ¶
func (scene *Scene) NewGameObject(name string) *GameObject
func (*Scene) NewTextureFromFile ¶
func (*Scene) NewTextureFromFilename ¶
type Texture ¶
type Texture struct { Name string Width uint32 Height uint32 Rows uint32 Cols uint32 // contains filtered or unexported fields }
func (*Texture) SetRowsCols ¶
type TileMap ¶
type TileMap struct {
// contains filtered or unexported fields
}
A TileMap is a simple map of tiles using a single mesh for the whole level.
func NewTileMap ¶
func (*TileMap) SetPixelsPerUnit ¶
func (*TileMap) Start ¶
func (tilemap *TileMap) Start(gameObject *GameObject)
func (*TileMap) Update ¶
func (tilemap *TileMap) Update(gameObject *GameObject)
type Window ¶
type Window struct { Projection mgl32.Mat4 View mgl32.Mat4 OrthographicSize float32 AspectRatio float32 // contains filtered or unexported fields }
The Window type interfaces with the display hardware using OpenGL. Coordinates are 0, 0 at screen center.
func OpenWindowVersion ¶
func (*Window) SetSceneByName ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
The chipmunk package allows using the Chipmunk physical engine in a game.
|
The chipmunk package allows using the Chipmunk physical engine in a game. |
examples
|
|
The lua package allows scripting the game using the Lua language.
|
The lua package allows scripting the game using the Lua language. |