gozmo

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

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

Go to latest
Published: Mar 12, 2016 License: MIT Imports: 18 Imported by: 0

README

gozmo

Gozmo is a hardware accelerated game engine written in the Go language. It is based on OpenGL and uses libraries from the go-gl project.

Status

The project is undergoing heavy development, and is not yet suitable for writing games.

Trying it out

After installing it with go get as usual, have a look at the examples/ directory.

Docs

See the embedded documentation.

License

MIT, see the LICENSE file.

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

Constants

This section is empty.

Variables

View Source
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 CastBool

func CastBool(value interface{}) (bool, error)

func CastFloat32

func CastFloat32(number interface{}) (float32, error)

func CastInt

func CastInt(number interface{}) (int, error)

func CastUInt32

func CastUInt32(number interface{}) (uint32, error)

func DecPerFrameStats

func DecPerFrameStats(name string, value float64)

func GLBufferData

func GLBufferData(location uint32, bid uint32, data []float32)

func GLClear

func GLClear()

func GLDraw

func GLDraw(mesh *Mesh, shader uint32, width float32, height float32, textureId int32, uvx, uvy, uvw, uvh float32, ortho mgl32.Mat4)

func GLInit

func GLInit(width int32, height int32)

OpenGL 4.1 wrappers.

func GLNewArray

func GLNewArray() uint32

func GLNewBuffer

func GLNewBuffer() uint32

func GLShader

func GLShader() uint32

func GLTexture

func GLTexture(rgba *image.RGBA) uint32

func GetPerFrameStats

func GetPerFrameStats(name string) float64

func IncPerFrameStats

func IncPerFrameStats(name string, value float64)

func IsTrue

func IsTrue(value interface{}, err error) bool

func RegisterComponent

func RegisterComponent(name string, generator func([]interface{}) Component)

func RegisterUpdater

func RegisterUpdater(updater func(scene *Scene, deltaTime float32))

func SetPerFrameStats

func SetPerFrameStats(name string, value float64)

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 AnimationAction struct {
	ComponentName string
	Attr          string
	Value         interface{}
	Interpolate   bool
}

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 *Animator) GetAnimation() string

func (*Animator) GetAttr

func (animator *Animator) GetAttr(attr string) (interface{}, error)

func (*Animator) GetType

func (animator *Animator) GetType() string

func (*Animator) Play

func (animator *Animator) Play()

func (*Animator) SetAnimation

func (animator *Animator) SetAnimation(name string)

func (*Animator) SetAttr

func (animator *Animator) SetAttr(attr string, value interface{}) error

func (*Animator) Start

func (animator *Animator) Start(gameObject *GameObject)

func (*Animator) Stop

func (animator *Animator) Stop()

func (*Animator) Update

func (animator *Animator) Update(gameObject *GameObject)

type BoxRenderer

type BoxRenderer struct {
	Width  float32
	Height float32
	// contains filtered or unexported fields
}

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 NewCage

func NewCage(top, left, bottom, right float32) *Cage

func (*Cage) GetAttr

func (cage *Cage) GetAttr(attr string) (interface{}, error)

func (*Cage) GetName

func (cage *Cage) GetName() string

func (*Cage) SetAttr

func (cage *Cage) SetAttr(attr string, value interface{}) error

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 NewCamera

func NewCamera() *Camera

func (*Camera) GetAttr

func (camera *Camera) GetAttr(attr string) (interface{}, error)

func (*Camera) GetName

func (camera *Camera) GetName() string

func (*Camera) SetAttr

func (camera *Camera) SetAttr(attr string, value interface{}) error

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 ComponentAttr interface {
	SetAttr(attr string, value interface{}) error
	GetAttr(attr string) (interface{}, error)
}

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 NewHitBox

func NewHitBox(xOffset, yOffset, width, height float32) *HitBox

func NewHitBoxWithEvent

func NewHitBoxWithEvent(xOffset, yOffset, width, height float32, event string) *HitBox

func (*HitBox) GetAttr

func (hitbox *HitBox) GetAttr(attr string) (interface{}, error)

func (*HitBox) GetName

func (hitbox *HitBox) GetName() string

func (*HitBox) Intersect

func (hitbox *HitBox) Intersect(otherBox *HitBox) bool

func (*HitBox) SetAttr

func (hitbox *HitBox) SetAttr(attr string, value interface{}) error

func (*HitBox) Start

func (hitbox *HitBox) Start(gameObject *GameObject)

func (*HitBox) Update

func (hitbox *HitBox) Update(gameObject *GameObject)

type Key

type Key glfw.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) GetAttr

func (keyboard *Keyboard) GetAttr(attr string) (interface{}, error)

TODO: what if the user specifies an unknown key?

func (*Keyboard) GetKey

func (keyboard *Keyboard) GetKey(key Key) bool

func (*Keyboard) GetName

func (keyboard *Keyboard) GetName() string

func (*Keyboard) SetAttr

func (keyboard *Keyboard) SetAttr(attr string, value interface{}) error

func (*Keyboard) Start

func (keyboard *Keyboard) Start(gameObject *GameObject)

func (*Keyboard) Update

func (keyboard *Keyboard) Update(gameObject *GameObject)

type Mesh

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

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 NewMouse

func NewMouse() *Mouse

func (*Mouse) GetAttr

func (mouse *Mouse) GetAttr(attr string) (interface{}, error)

TODO: what if the user specifies an unknown key?

func (*Mouse) GetName

func (mouse *Mouse) GetName() string

func (*Mouse) SetAttr

func (mouse *Mouse) SetAttr(attr string, value interface{}) error

func (*Mouse) Start

func (mouse *Mouse) Start(gameObject *GameObject)

func (*Mouse) Update

func (mouse *Mouse) Update(gameObject *GameObject)

func (*Mouse) X

func (mouse *Mouse) X() float32

func (*Mouse) Y

func (mouse *Mouse) Y() float32

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 NewRenderer(texture *Texture) *Renderer

func (*Renderer) GetAttr

func (renderer *Renderer) GetAttr(attr string) (interface{}, error)

func (*Renderer) GetType

func (renderer *Renderer) GetType() string

func (*Renderer) SetAttr

func (renderer *Renderer) SetAttr(attr string, value interface{}) error

func (*Renderer) SetPixelsPerUnit

func (renderer *Renderer) SetPixelsPerUnit(pixels uint32)

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 NewRewind

func NewRewind(event string) *Rewind

func (*Rewind) GetAttr

func (rewind *Rewind) GetAttr(attr string) (interface{}, error)

func (*Rewind) GetName

func (rewind *Rewind) GetName() string

func (*Rewind) OnEvent

func (rewind *Rewind) OnEvent(gameObject *GameObject, event *Event)

func (*Rewind) SetAttr

func (rewind *Rewind) SetAttr(attr string, value interface{}) error

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 NewScene

func NewScene(name string) *Scene

func NewSceneFromFilename

func NewSceneFromFilename(fileName string) *Scene

func (*Scene) AddAnimation

func (scene *Scene) AddAnimation(name string, fps int, loop bool) *Animation

func (*Scene) Destroy

func (scene *Scene) Destroy()

func (*Scene) FindGameObject

func (scene *Scene) FindGameObject(name string) *GameObject

func (*Scene) NewGameObject

func (scene *Scene) NewGameObject(name string) *GameObject

func (*Scene) NewTexture

func (scene *Scene) NewTexture(name string, width uint32, height uint32)

func (*Scene) NewTextureFromFile

func (scene *Scene) NewTextureFromFile(name string, file *os.File) (*Texture, error)

func (*Scene) NewTextureFromFilename

func (scene *Scene) NewTextureFromFilename(name string, fileName string) (*Texture, error)

func (*Scene) Update

func (scene *Scene) Update(now float64)

type Texture

type Texture struct {
	Name   string
	Width  uint32
	Height uint32
	Rows   uint32
	Cols   uint32
	// contains filtered or unexported fields
}

func (*Texture) Destroy

func (texture *Texture) Destroy()

func (*Texture) SetCols

func (texture *Texture) SetCols(cols uint32)

func (*Texture) SetRows

func (texture *Texture) SetRows(rows uint32)

func (*Texture) SetRowsCols

func (texture *Texture) SetRowsCols(rows, cols uint32)

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 NewTileMap(texture *Texture) *TileMap

func NewTileMapFromCSVFilename

func NewTileMapFromCSVFilename(fileName string, texture *Texture) *TileMap

func (*TileMap) GetAttr

func (tilemap *TileMap) GetAttr(attr string) (interface{}, error)

func (*TileMap) GetType

func (tilemap *TileMap) GetType() string

func (*TileMap) SetAttr

func (tilemap *TileMap) SetAttr(attr string, value interface{}) error

func (*TileMap) SetPixelsPerUnit

func (tilemap *TileMap) SetPixelsPerUnit(pixels uint32)

func (*TileMap) Start

func (tilemap *TileMap) Start(gameObject *GameObject)

func (*TileMap) Update

func (tilemap *TileMap) Update(gameObject *GameObject)

type Vector2

type Vector2 mgl32.Vec2

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 OpenWindow

func OpenWindow(width int32, height int32, title string) *Window

func OpenWindowVersion

func OpenWindowVersion(width int32, height int32, title string, major int, minor int) *Window

func (*Window) Run

func (window *Window) Run()

func (*Window) SetScene

func (window *Window) SetScene(scene *Scene)

func (*Window) SetSceneByName

func (window *Window) SetSceneByName(sceneName string)

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.

Jump to

Keyboard shortcuts

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