twodee

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

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

Go to latest
Published: Dec 6, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

README

twodee

A library for 2d games using OpenGL and Go.

Under heavy development, we have been using this for Ludum Dare competitions so it changes from time to time.

Features

  • Menus
  • Sound
  • Animations
  • Fullscreen mode
  • Keyboard / Mouse / Gamepad events
  • Building on OSX / Linux / Windows
  • Game grid + pathfinding
  • Import from Tiled native file format (http://www.mapeditor.org/)
  • Some effects shaders (like Glow)

Setup

This project depends on thirdparty libraries in order to function correctly. The most consistent way to build these is to use the pikkpoiss/twodee-support library. Follow the instructions there to set things up correctly.

Documentation

Index

Constants

View Source
const (
	Step60Hz = time.Duration(16666) * time.Microsecond
	Step30Hz = Step60Hz * 2
	Step20Hz = time.Duration(50000) * time.Microsecond
	Step15Hz = Step30Hz * 2
	Step10Hz = Step20Hz * 2
	Step5Hz  = Step10Hz * 2
)
View Source
const (
	KeyUp     = KeyCode(glfw.KeyUp)
	KeyDown   = KeyCode(glfw.KeyDown)
	KeyLeft   = KeyCode(glfw.KeyLeft)
	KeyRight  = KeyCode(glfw.KeyRight)
	KeyEnter  = KeyCode(glfw.KeyEnter)
	KeyEscape = KeyCode(glfw.KeyEscape)
	KeySpace  = KeyCode(glfw.KeySpace)
	KeyA      = KeyCode(glfw.KeyA)
	KeyB      = KeyCode(glfw.KeyB)
	KeyC      = KeyCode(glfw.KeyC)
	KeyD      = KeyCode(glfw.KeyD)
	KeyE      = KeyCode(glfw.KeyE)
	KeyF      = KeyCode(glfw.KeyF)
	KeyG      = KeyCode(glfw.KeyG)
	KeyH      = KeyCode(glfw.KeyH)
	KeyI      = KeyCode(glfw.KeyI)
	KeyJ      = KeyCode(glfw.KeyJ)
	KeyK      = KeyCode(glfw.KeyK)
	KeyL      = KeyCode(glfw.KeyL)
	KeyM      = KeyCode(glfw.KeyM)
	KeyN      = KeyCode(glfw.KeyN)
	KeyO      = KeyCode(glfw.KeyO)
	KeyP      = KeyCode(glfw.KeyP)
	KeyQ      = KeyCode(glfw.KeyQ)
	KeyR      = KeyCode(glfw.KeyR)
	KeyS      = KeyCode(glfw.KeyS)
	KeyT      = KeyCode(glfw.KeyT)
	KeyU      = KeyCode(glfw.KeyU)
	KeyV      = KeyCode(glfw.KeyV)
	KeyW      = KeyCode(glfw.KeyW)
	KeyX      = KeyCode(glfw.KeyX)
	KeyY      = KeyCode(glfw.KeyY)
	KeyZ      = KeyCode(glfw.KeyZ)
	Key1      = KeyCode(glfw.Key1)
	Key2      = KeyCode(glfw.Key2)
	Key3      = KeyCode(glfw.Key3)
	Key4      = KeyCode(glfw.Key4)
	Key5      = KeyCode(glfw.Key5)
	Key6      = KeyCode(glfw.Key6)
	Key7      = KeyCode(glfw.Key7)
	Key8      = KeyCode(glfw.Key8)
	Key9      = KeyCode(glfw.Key9)
	Key0      = KeyCode(glfw.Key0)
)
View Source
const (
	Release = Action(glfw.Release)
	Press   = Action(glfw.Press)
	Repeat  = Action(glfw.Repeat)
)
View Source
const (
	MouseButton1      = MouseButton(glfw.MouseButton1)
	MouseButton2      = MouseButton(glfw.MouseButton2)
	MouseButton3      = MouseButton(glfw.MouseButton3)
	MouseButton4      = MouseButton(glfw.MouseButton4)
	MouseButton5      = MouseButton(glfw.MouseButton5)
	MouseButton6      = MouseButton(glfw.MouseButton6)
	MouseButton7      = MouseButton(glfw.MouseButton7)
	MouseButton8      = MouseButton(glfw.MouseButton8)
	MouseButtonLast   = MouseButton(glfw.MouseButtonLast)
	MouseButtonLeft   = MouseButton(glfw.MouseButtonLeft)
	MouseButtonRight  = MouseButton(glfw.MouseButtonRight)
	MouseButtonMiddle = MouseButton(glfw.MouseButtonMiddle)
)
View Source
const (
	LinearInterpolation  = InterpolationType(gl.LINEAR)
	NearestInterpolation = InterpolationType(gl.NEAREST)
)
View Source
const BATCH_FRAGMENT = `#version 150
precision mediump float;

uniform sampler2D u_TextureUnit;
uniform vec2 u_TextureOffset;
in vec2 v_TextureCoordinates;
out vec4 v_FragData;

void main()
{
    vec2 texcoords = v_TextureCoordinates + u_TextureOffset;
    v_FragData = texture(u_TextureUnit, texcoords);
    //v_FragData = vec4(1.0,0.0,0.0,1.0);
}` + "\x00"
View Source
const BATCH_VERTEX = `#version 150

in vec4 a_Position;
in vec2 a_TextureCoordinates;

uniform mat4 m_ModelViewMatrix;
uniform mat4 m_ProjectionMatrix;

out vec2 v_TextureCoordinates;

void main()
{
    v_TextureCoordinates = a_TextureCoordinates;
    gl_Position = m_ProjectionMatrix * m_ModelViewMatrix * a_Position;
}` + "\x00"
View Source
const GLOW_FRAGMENT = `#version 150
precision mediump float;

uniform sampler2D u_TextureUnit;
in vec2 v_TextureCoordinates;
uniform int Orientation;
uniform int BlurAmount;
uniform float BlurScale;
uniform float BlurStrength;
uniform vec2 BufferDimensions;
out vec4 v_FragData;
vec2 TexelSize = vec2(1.0 / BufferDimensions.x, 1.0 / BufferDimensions.y);

float Gaussian (float x, float deviation) {
  return (1.0 / sqrt(2.0 * 3.141592 * deviation)) * exp(-((x * x) / (2.0 * deviation)));
}


void main() {
  // Locals
  float halfBlur = float(BlurAmount) * 0.5;
  vec4 colour = vec4(0.0);
  vec4 texColour = vec4(0.0);

  // Gaussian deviation
  float deviation = halfBlur * 0.35;
  deviation *= deviation;
  float strength = 1.0 - BlurStrength;

  if ( Orientation == 0 ) {
    // Horizontal blur
    for (int i = 0; i < 10; ++i) {
      if ( i >= BlurAmount ) {
        break;
      }
      float offset = float(i) - halfBlur;
      texColour = texture(
        u_TextureUnit,
        v_TextureCoordinates + vec2(offset * TexelSize.x * BlurScale, 0.0)) * Gaussian(offset * strength, deviation);
      colour += texColour;
    }
  } else {
    // Vertical blur
    for (int i = 0; i < 10; ++i) {
      if ( i >= BlurAmount ) {
        break;
      }
      float offset = float(i) - halfBlur;
      texColour = texture(
        u_TextureUnit,
        v_TextureCoordinates + vec2(0.0, offset * TexelSize.y * BlurScale)) * Gaussian(offset * strength, deviation);
      colour += texColour;
    }
  }
  // Apply colour
  v_FragData = clamp(colour, 0.0, 1.0);
  v_FragData.w = 1.0;
}` + "\x00"
View Source
const GLOW_VERTEX = `#version 150

in vec4 a_Position;
in vec2 a_TextureCoordinates;

out vec2 v_TextureCoordinates;

void main() {
    v_TextureCoordinates = a_TextureCoordinates;
    gl_Position = a_Position;
}` + "\x00"
View Source
const (
	Joystick1 = Joystick(glfw.Joystick1)
)
View Source
const LINES_FRAGMENT = `#version 150
precision mediump float;

in float f_Edge;
uniform float f_Inner;
uniform vec4 v_Color;
out vec4 v_FragData;

void main() {
  float v = 1.0 - abs(f_Edge);
  v = smoothstep(0.65, 0.7, v * f_Inner);
  v_FragData = mix(v_Color, vec4(0.0), v);
}` + "\x00"
View Source
const LINES_VERTEX = `#version 150
in vec2 v_Position;
in vec2 v_Normal;
in float f_Miter;
uniform float f_Thickness;
uniform mat4 m_ModelView;
uniform mat4 m_Projection;
out float f_Edge;

void main() {
    f_Edge = sign(f_Miter);

    //push the point along its normal by half thickness
    vec2 position = v_Position.xy + vec2(v_Normal * f_Thickness/2.0 * f_Miter);
    gl_Position = m_Projection * m_ModelView * vec4(position, 0.0, 1.0);
}` + "\x00"
View Source
const SPRITE_FRAGMENT = `#version 150
precision mediump float;

uniform sampler2D TextureUnit;
in vec2 v_TextureCoordinates;
in vec4 v_BaseColor;
out vec4 v_FragData;

void main() {
  vec4 color = texture(TextureUnit, v_TextureCoordinates);
  //if (color.a < 0.1) {
  //  discard;
  //}
  // This is really hacky
  if (v_BaseColor.a > 0.1 && color.r == 1.0 && color.g == 100.0/255.0 && color.b == 1.0) {
    v_FragData = v_BaseColor;
  } else {
    v_FragData = color;
  }
}` + "\x00"
View Source
const SPRITE_VERTEX = `#version 150

in vec3 v_Translation;
in vec3 v_Rotation;
in vec3 v_Scale;
in vec4 v_Color;

in mat4 m_PointAdjustment;
in mat4 m_TextureAdjustment;

uniform mat4 m_ProjectionMatrix;

out vec4 v_BaseColor;
out vec2 v_TextureCoordinates;

const vec2 Points[] = vec2[6](
  vec2(-0.5, -0.5),
  vec2( 0.5,  0.5),
  vec2(-0.5,  0.5),
  vec2(-0.5, -0.5),
  vec2( 0.5, -0.5),
  vec2( 0.5,  0.5)
);

const vec2 TexturePoints[] = vec2[6](
  vec2(0.0, 0.0),
  vec2(1.0, 1.0),
  vec2(0.0, 1.0),
  vec2(0.0, 0.0),
  vec2(1.0, 0.0),
  vec2(1.0, 1.0)
);

void main() {
  mat4 Translation = mat4(
    vec4(1.0, 0.0, 0.0, v_Translation.x),
    vec4(0.0, 1.0, 0.0, v_Translation.y),
    vec4(0.0, 0.0, 1.0, v_Translation.z),
    vec4(0.0, 0.0, 0.0,             1.0)
  );

  mat4 Scale = mat4(
    vec4(v_Scale.x,       0.0,       0.0, 0.0),
    vec4(      0.0, v_Scale.y,       0.0, 0.0),
    vec4(      0.0,       0.0, v_Scale.z, 0.0),
    vec4(      0.0,       0.0,       0.0, 1.0)
  );

  float rotCos = float(cos(v_Rotation.x));
  float rotSin = float(sin(v_Rotation.x));

  mat4 Rotation = mat4(
    vec4(rotCos, -rotSin, 0.0, 0.0),
    vec4(rotSin,  rotCos, 0.0, 0.0),
    vec4(   0.0,     0.0, 1.0, 0.0),
    vec4(   0.0,     0.0, 0.0, 1.0)
  );

  v_BaseColor = v_Color;
  v_TextureCoordinates = (vec4(TexturePoints[gl_VertexID], 0.0, 1.0) *
     m_TextureAdjustment).xy;

  gl_Position =  m_ProjectionMatrix *
      (vec4(Points[gl_VertexID], 0.0, 1.0) *
      m_PointAdjustment *
      Scale *
      Rotation *
      Translation);
}` + "\x00"
View Source
const TEXT_FRAGMENT = `#version 150
precision mediump float;

uniform sampler2D u_TextureUnit;
in vec2 v_TextureCoordinates;
out vec4 v_FragData;

void main()
{
    v_FragData = texture(u_TextureUnit, v_TextureCoordinates);
}` + "\x00"
View Source
const TEXT_VERTEX = `#version 150

in vec4 a_Position;
in vec2 a_TextureCoordinates;

uniform mat4 m_ProjectionMatrix;
uniform vec3 v_Trans;
uniform vec3 v_Scale;
out vec2 v_TextureCoordinates;

void main()
{
    mat4 trans;
    trans[0] = vec4(1,0,0,0);
    trans[1] = vec4(0,1,0,0);
    trans[2] = vec4(0,0,1,0);
    trans[3] = vec4(v_Trans.x,v_Trans.y,v_Trans.z,1);

    mat4 scale;
    scale[0] = vec4(v_Scale.x,0,0,0);
    scale[1] = vec4(0,v_Scale.y,0,0);
    scale[2] = vec4(0,0,v_Scale.z,0);
    scale[3] = vec4(0,0,0,1);

    v_TextureCoordinates = a_TextureCoordinates;
    gl_Position = m_ProjectionMatrix * trans * scale * a_Position;
}` + "\x00"

Variables

This section is empty.

Functions

func BuildProgram

func BuildProgram(vsrc string, fsrc string) (program uint32, err error)

func CompileShader

func CompileShader(stype uint32, source string) (shader uint32, err error)

func CreateVAO

func CreateVAO() (array uint32, err error)

func CreateVBO

func CreateVBO(size int, data interface{}, usage uint32) (buffer uint32, err error)

func GetGLTexture

func GetGLTexture(img image.Image, smoothing TextureSmoothing) (t uint32, err error)

func GetInteger4

func GetInteger4(pname uint32) (v0, v1, v2, v3 int)

Convenience function for glGetIntegerv

func GetInverseMatrix

func GetInverseMatrix(m mgl32.Mat4) (out mgl32.Mat4, err error)

func GetVectorDeterminantEquation

func GetVectorDeterminantEquation(a, b Point) func(Point) float32

func LinkProgram

func LinkProgram(vertex uint32, fragment uint32) (program uint32, err error)

func MusicIsPaused

func MusicIsPaused() bool

func MusicIsPlaying

func MusicIsPlaying() bool

func PauseMusic

func PauseMusic()

func Project

func Project(proj mgl32.Mat4, x float32, y float32) (sx, sy float32)

func ResumeMusic

func ResumeMusic()

func Unproject

func Unproject(invproj mgl32.Mat4, x float32, y float32) (wx, wy float32)

func WritePNG

func WritePNG(path string, img image.Image) (err error)

Types

type Action

type Action int

type Animating

type Animating interface {
	Update(elapsed time.Duration) (done bool)
	SetCallback(callback AnimationCallback)
	HasCallback() bool
	Reset()
}

type AnimatingEntity

type AnimatingEntity struct {
	*BaseEntity
	// contains filtered or unexported fields
}

func NewAnimatingEntity

func NewAnimatingEntity(x, y, w, h, r float32, l time.Duration, f []int) *AnimatingEntity

func (*AnimatingEntity) Frame

func (e *AnimatingEntity) Frame() int

func (*AnimatingEntity) OffsetFrame

func (e *AnimatingEntity) OffsetFrame(offset int) int

func (*AnimatingEntity) SetCallback

func (e *AnimatingEntity) SetCallback(callback AnimationCallback)

func (*AnimatingEntity) SetFrames

func (e *AnimatingEntity) SetFrames(f []int)

func (*AnimatingEntity) Update

func (e *AnimatingEntity) Update(elapsed time.Duration)

type Animation

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

func NewAnimation

func NewAnimation() *Animation

func (*Animation) Callback

func (a *Animation) Callback()

func (*Animation) Elapsed

func (a *Animation) Elapsed() time.Duration

func (*Animation) HasCallback

func (a *Animation) HasCallback() bool

func (*Animation) Reset

func (a *Animation) Reset()

func (*Animation) SetCallback

func (a *Animation) SetCallback(callback AnimationCallback)

func (*Animation) Update

func (a *Animation) Update(elapsed time.Duration) (done bool)

type AnimationCallback

type AnimationCallback func()

type Animator

type Animator interface {
	SetCallback(Callback AnimatorCallback)
	IsDone() bool
	Update(elapsed time.Duration) time.Duration
	Reset()
	Delete()
}

type AnimatorCallback

type AnimatorCallback func()

type BackMenuItem

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

func NewBackMenuItem

func NewBackMenuItem(label string) (item *BackMenuItem)

func (*BackMenuItem) Active

func (mi *BackMenuItem) Active() bool

func (*BackMenuItem) Highlighted

func (mi *BackMenuItem) Highlighted() bool

func (*BackMenuItem) Label

func (mi *BackMenuItem) Label() string

func (*BackMenuItem) Parent

func (mi *BackMenuItem) Parent() MenuItem

type BaseEntity

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

func NewBaseEntity

func NewBaseEntity(x, y, w, h, r float32, frame int) *BaseEntity

func (*BaseEntity) Bounds

func (e *BaseEntity) Bounds() Rectangle

func (*BaseEntity) Frame

func (e *BaseEntity) Frame() int

func (*BaseEntity) MoveTo

func (e *BaseEntity) MoveTo(pt Point)

func (*BaseEntity) MoveToCoords

func (e *BaseEntity) MoveToCoords(x, y float32)

func (*BaseEntity) Pos

func (e *BaseEntity) Pos() Point

func (*BaseEntity) Rotation

func (e *BaseEntity) Rotation() float32

func (*BaseEntity) Update

func (e *BaseEntity) Update(elapsed time.Duration)

type BasicGameEvent

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

func NewBasicGameEvent

func NewBasicGameEvent(t GameEventType) *BasicGameEvent

func (*BasicGameEvent) GEType

func (e *BasicGameEvent) GEType() GameEventType

type Batch

type Batch struct {
	Buffer  uint32
	Texture *Texture
	Count   int
	// contains filtered or unexported fields
}

func LoadBatch

func LoadBatch(tiles []TexturedTile, metadata TileMetadata) (b *Batch, err error)

func (*Batch) Delete

func (b *Batch) Delete()

func (*Batch) SetTextureOffsetPx

func (b *Batch) SetTextureOffsetPx(x, y int)

type BatchRenderer

type BatchRenderer struct {
	*Renderer
	Program        uint32
	PositionLoc    uint32
	TextureLoc     uint32
	TextureUnitLoc int32
	ModelViewLoc   int32
	ProjectionLoc  int32
	TexOffsetLoc   int32
}

func NewBatchRenderer

func NewBatchRenderer(camera *Camera) (tr *BatchRenderer, err error)

func (*BatchRenderer) Bind

func (r *BatchRenderer) Bind() error

func (*BatchRenderer) Delete

func (tr *BatchRenderer) Delete() error

func (*BatchRenderer) Draw

func (r *BatchRenderer) Draw(batch *Batch, x, y, rot float32) error

func (*BatchRenderer) Unbind

func (tr *BatchRenderer) Unbind() error

type BoundValueMenuItem

type BoundValueMenuItem struct {
	KeyValueMenuItem
	// contains filtered or unexported fields
}

func NewBoundValueMenuItem

func NewBoundValueMenuItem(label string, val int32, dest *int32) *BoundValueMenuItem

func (*BoundValueMenuItem) Active

func (mi *BoundValueMenuItem) Active() bool

func (*BoundValueMenuItem) Highlighted

func (mi *BoundValueMenuItem) Highlighted() bool

func (*BoundValueMenuItem) IsSameAsDest

func (mi *BoundValueMenuItem) IsSameAsDest() bool

func (*BoundValueMenuItem) Label

func (mi *BoundValueMenuItem) Label() string

func (*BoundValueMenuItem) Parent

func (mi *BoundValueMenuItem) Parent() MenuItem

func (*BoundValueMenuItem) SetDest

func (mi *BoundValueMenuItem) SetDest()

type BoundedAnimation

type BoundedAnimation struct {
	Elapsed  time.Duration
	Duration time.Duration
	Callback AnimatorCallback
}

func (*BoundedAnimation) Delete

func (a *BoundedAnimation) Delete()

func (*BoundedAnimation) IsDone

func (a *BoundedAnimation) IsDone() bool

func (*BoundedAnimation) Reset

func (a *BoundedAnimation) Reset()

func (*BoundedAnimation) SetCallback

func (a *BoundedAnimation) SetCallback(Callback AnimatorCallback)

func (*BoundedAnimation) Update

func (a *BoundedAnimation) Update(elapsed time.Duration) time.Duration

type Camera

type Camera struct {
	WorldBounds  Rectangle
	ScreenBounds Rectangle
	Projection   mgl32.Mat4
	Inverse      mgl32.Mat4
}

func NewCamera

func NewCamera(world Rectangle, screen Rectangle) (c *Camera, err error)

func (*Camera) ScreenToWorldCoords

func (c *Camera) ScreenToWorldCoords(x, y float32) (wx, wy float32)

func (*Camera) SetScreenBounds

func (c *Camera) SetScreenBounds(bounds Rectangle)

func (*Camera) SetWorldBounds

func (c *Camera) SetWorldBounds(bounds Rectangle) (err error)

func (*Camera) WorldToScreenCoords

func (c *Camera) WorldToScreenCoords(x, y float32) (sx, sy float32)

type ChainedAnimation

type ChainedAnimation struct {
	Callback AnimatorCallback
	// contains filtered or unexported fields
}

func (*ChainedAnimation) Delete

func (a *ChainedAnimation) Delete()

func (*ChainedAnimation) IsDone

func (a *ChainedAnimation) IsDone() bool

func (*ChainedAnimation) Reset

func (a *ChainedAnimation) Reset()

func (*ChainedAnimation) SetCallback

func (a *ChainedAnimation) SetCallback(Callback AnimatorCallback)

func (*ChainedAnimation) Update

func (a *ChainedAnimation) Update(elapsed time.Duration) time.Duration

type Context

type Context struct {
	Events        *EventHandler
	OpenGLVersion string
	ShaderVersion string
	VAO           uint32
	// contains filtered or unexported fields
}

func NewContext

func NewContext() (context *Context, err error)

func (*Context) CreateWindow

func (c *Context) CreateWindow(w, h int, name string) (err error)

func (*Context) Delete

func (c *Context) Delete()

func (*Context) Fullscreen

func (c *Context) Fullscreen() bool

func (*Context) SetCursor

func (c *Context) SetCursor(val bool)

func (*Context) SetFullscreen

func (c *Context) SetFullscreen(val bool)

func (*Context) SetResizable

func (c *Context) SetResizable(val bool)

func (*Context) SetSwapInterval

func (c *Context) SetSwapInterval(val int)

func (*Context) ShouldClose

func (c *Context) ShouldClose() bool

func (*Context) SwapBuffers

func (c *Context) SwapBuffers()

type ContinuousAnimation

type ContinuousAnimation struct {
	*Animation
	// contains filtered or unexported fields
}

func NewContinuousAnimation

func NewContinuousAnimation(f ContinuousFunc) *ContinuousAnimation

func (*ContinuousAnimation) Value

func (a *ContinuousAnimation) Value() float32

type ContinuousFunc

type ContinuousFunc func(elapsed time.Duration) float32

func SineDecayFunc

func SineDecayFunc(duration time.Duration, amplitude, frequency, decay float32, callback AnimationCallback) ContinuousFunc

type Counter

type Counter struct {
	Count int64
	Total float64
	Last  float64
	Avg   float32
}

func NewCounter

func NewCounter() *Counter

func (*Counter) Incr

func (c *Counter) Incr()

type EaseOutAnimation

type EaseOutAnimation struct {
	BoundedAnimation
	// contains filtered or unexported fields
}

func NewEaseOutAnimation

func NewEaseOutAnimation(target *float32, from, to float32, duration time.Duration) *EaseOutAnimation

func (*EaseOutAnimation) Update

func (a *EaseOutAnimation) Update(elapsed time.Duration) (remainder time.Duration)

type Entity

type Entity interface {
	Pos() Point
	Bounds() Rectangle
	Frame() int
	Rotation() float32
	MoveTo(Point)
	MoveToCoords(x, y float32)
	Update(elapsed time.Duration)
}

type Event

type Event interface{}

type EventHandler

type EventHandler struct {
	Events chan Event
	// contains filtered or unexported fields
}

func NewEventHandler

func NewEventHandler(w *glfw.Window) (e *EventHandler)

func (*EventHandler) GetKey

func (e *EventHandler) GetKey(code KeyCode) Action

func (*EventHandler) JoystickAxes

func (e *EventHandler) JoystickAxes(joystick Joystick) []float32

func (*EventHandler) JoystickButtons

func (e *EventHandler) JoystickButtons(joystick Joystick) []byte

func (*EventHandler) JoystickPresent

func (e *EventHandler) JoystickPresent(joystick Joystick) bool

func (*EventHandler) Poll

func (e *EventHandler) Poll()

type FontFace

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

func NewFontFace

func NewFontFace(path string, size float64, fg, bg color.Color) (fontface *FontFace, err error)

func (*FontFace) GetText

func (ff *FontFace) GetText(text string) (t *Texture, err error)

type FrameAnimation

type FrameAnimation struct {
	*Animation
	FrameLength time.Duration
	Sequence    []int
	Current     int
}

func NewFrameAnimation

func NewFrameAnimation(length time.Duration, frames []int) *FrameAnimation

func (*FrameAnimation) OffsetFrame

func (a *FrameAnimation) OffsetFrame(offset int) int

func (*FrameAnimation) SetSequence

func (a *FrameAnimation) SetSequence(seq []int)

func (*FrameAnimation) Update

func (a *FrameAnimation) Update(elapsed time.Duration) (done bool)

type FrameConfig

type FrameConfig struct {
	PointAdjustment   mgl32.Mat4
	TextureAdjustment mgl32.Mat4
}

type GETyper

type GETyper interface {
	GEType() GameEventType
}

type GameEventCallback

type GameEventCallback func(GETyper)

type GameEventHandler

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

func NewGameEventHandler

func NewGameEventHandler(numGameEventTypes int) (h *GameEventHandler)

func (*GameEventHandler) AddObserver

func (h *GameEventHandler) AddObserver(t GameEventType, c GameEventCallback) (id int)

func (*GameEventHandler) Enqueue

func (h *GameEventHandler) Enqueue(e GETyper)

func (*GameEventHandler) Poll

func (h *GameEventHandler) Poll()

func (*GameEventHandler) RemoveObserver

func (h *GameEventHandler) RemoveObserver(t GameEventType, id int)

type GameEventType

type GameEventType int

type GameEventTypeObservers

type GameEventTypeObservers map[int]GameEventCallback

type GlowRenderer

type GlowRenderer struct {
	GlowFb  uint32
	GlowTex uint32
	BlurFb  uint32
	BlurTex uint32
	// contains filtered or unexported fields
}

func NewGlowRenderer

func NewGlowRenderer(w, h int, blur int, strength float32, scale float32) (r *GlowRenderer, err error)

func (*GlowRenderer) Bind

func (r *GlowRenderer) Bind() error

func (*GlowRenderer) Delete

func (r *GlowRenderer) Delete() error

func (*GlowRenderer) DisableOutput

func (r *GlowRenderer) DisableOutput()

func (*GlowRenderer) Draw

func (r *GlowRenderer) Draw() (err error)

func (*GlowRenderer) EnableOutput

func (r *GlowRenderer) EnableOutput()

func (*GlowRenderer) GetError

func (r *GlowRenderer) GetError() error

func (*GlowRenderer) SetStrength

func (r *GlowRenderer) SetStrength(s float32)

func (*GlowRenderer) Unbind

func (r *GlowRenderer) Unbind() error

type Grid

type Grid struct {
	Width     int32
	Height    int32
	BlockSize float32
	// contains filtered or unexported fields
}

func NewGrid

func NewGrid(w, h, blocksize int32) *Grid

func (*Grid) CanSee

func (g *Grid) CanSee(from, to mgl32.Vec2) bool

func (*Grid) FixMove

func (g *Grid) FixMove(bounds mgl32.Vec4, move mgl32.Vec2) (out mgl32.Vec2)

func (*Grid) Get

func (g *Grid) Get(x, y int32) GridItem

func (*Grid) GetImage

func (g *Grid) GetImage(fg, bg color.Color) *image.NRGBA

func (*Grid) GetIndex

func (g *Grid) GetIndex(index int32) GridItem

func (*Grid) GetPath

func (g *Grid) GetPath(x1, y1, x2, y2 int32) (out []GridPoint, err error)

Pretty much a direct A* implementation from http://theory.stanford.edu/~amitp/GameProgramming/ImplementationNotes.html

func (*Grid) GridAligned

func (g *Grid) GridAligned(x float32) float32

func (*Grid) GridPosition

func (g *Grid) GridPosition(v float32) int32

func (*Grid) Index

func (g *Grid) Index(x, y int32) int32

func (*Grid) InversePosition

func (g *Grid) InversePosition(i int32) float32

func (*Grid) Set

func (g *Grid) Set(x, y int32, val GridItem)

func (*Grid) SetIndex

func (g *Grid) SetIndex(index int32, val GridItem)

type GridItem

type GridItem interface {
	Passable() bool
	Opaque() bool
}

type GridPoint

type GridPoint struct {
	X, Y int32
}

type GroupedAnimation

type GroupedAnimation struct {
	Callback AnimatorCallback
	// contains filtered or unexported fields
}

func (*GroupedAnimation) Delete

func (a *GroupedAnimation) Delete()

func (*GroupedAnimation) IsDone

func (a *GroupedAnimation) IsDone() bool

func (*GroupedAnimation) Reset

func (a *GroupedAnimation) Reset()

func (*GroupedAnimation) SetCallback

func (a *GroupedAnimation) SetCallback(Callback AnimatorCallback)

func (*GroupedAnimation) Update

func (a *GroupedAnimation) Update(elapsed time.Duration) time.Duration

type InterpolationType

type InterpolationType uint32

type Joystick

type Joystick int

type KeyCode

type KeyCode int

type KeyEvent

type KeyEvent struct {
	Code KeyCode
	Type Action
}

type KeyValueMenuItem

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

func NewKeyValueMenuItem

func NewKeyValueMenuItem(label string, key, value int32) *KeyValueMenuItem

func (*KeyValueMenuItem) Active

func (mi *KeyValueMenuItem) Active() bool

func (*KeyValueMenuItem) Data

func (mi *KeyValueMenuItem) Data() *MenuItemData

func (*KeyValueMenuItem) Highlighted

func (mi *KeyValueMenuItem) Highlighted() bool

func (*KeyValueMenuItem) Label

func (mi *KeyValueMenuItem) Label() string

func (*KeyValueMenuItem) Parent

func (mi *KeyValueMenuItem) Parent() MenuItem

type Layer

type Layer interface {
	Render()
	Update(elapsed time.Duration)
	Delete()
	HandleEvent(evt Event) bool
	Reset() error
}

type Layers

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

func NewLayers

func NewLayers() *Layers

func (*Layers) Delete

func (l *Layers) Delete()

func (*Layers) HandleEvent

func (l *Layers) HandleEvent(evt Event) bool

func (*Layers) Pop

func (l *Layers) Pop() (layer Layer)

func (*Layers) Push

func (l *Layers) Push(layer Layer)

func (*Layers) Render

func (l *Layers) Render()

func (*Layers) Reset

func (l *Layers) Reset() (err error)

func (*Layers) Update

func (l *Layers) Update(elapsed time.Duration)

type LineGeometry

type LineGeometry struct {
	Points   []TexturedPoint
	Vertices []TexturedPoint
	Indices  []uint32
}

func NewLineGeometry

func NewLineGeometry(path []mgl32.Vec2, closed bool) (out *LineGeometry)

type LineStyle

type LineStyle struct {
	Thickness float32
	Color     color.Color
	Inner     float32
}

type LinearAnimation

type LinearAnimation struct {
	BoundedAnimation
	// contains filtered or unexported fields
}

func NewLinearAnimation

func NewLinearAnimation(target *float32, from, to float32, duration time.Duration) *LinearAnimation

func (*LinearAnimation) Update

func (a *LinearAnimation) Update(elapsed time.Duration) (remainder time.Duration)

type LinesRenderer

type LinesRenderer struct {
	*Renderer
	// contains filtered or unexported fields
}

func NewLinesRenderer

func NewLinesRenderer(camera *Camera) (lr *LinesRenderer, err error)

func (*LinesRenderer) Bind

func (lr *LinesRenderer) Bind() (err error)

func (*LinesRenderer) Delete

func (lr *LinesRenderer) Delete() (err error)

func (*LinesRenderer) Draw

func (lr *LinesRenderer) Draw(line *LineGeometry, mv mgl32.Mat4, style *LineStyle) (err error)

func (*LinesRenderer) Unbind

func (lr *LinesRenderer) Unbind() (err error)
type Menu struct {
	// contains filtered or unexported fields
}

func NewMenu

func NewMenu(items []MenuItem) (menu *Menu, err error)
func (m *Menu) HighlightItem(h MenuItem)
func (m *Menu) Items() []MenuItem
func (m *Menu) Next()
func (m *Menu) Prev()
func (m *Menu) Reset()
func (m *Menu) Select() *MenuItemData
func (m *Menu) SelectItem(item MenuItem) *MenuItemData
type MenuItem interface {
	Highlighted() bool
	Label() string

	Parent() MenuItem

	Active() bool
	// contains filtered or unexported methods
}
type MenuItemData struct {
	Key   int32
	Value int32
}

type ModelViewConfig

type ModelViewConfig struct {
	X         float32
	Y         float32
	Z         float32
	RotationX float32
	RotationY float32
	RotationZ float32
	ScaleX    float32
	ScaleY    float32
	ScaleZ    float32
}

type MouseButton

type MouseButton int

type MouseButtonEvent

type MouseButtonEvent struct {
	Button MouseButton
	Type   Action
}

type MouseMoveEvent

type MouseMoveEvent struct {
	X float32
	Y float32
}

type Music

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

func NewMusic

func NewMusic(path string) (m *Music, err error)

func (*Music) Delete

func (m *Music) Delete()

func (*Music) Play

func (m *Music) Play(times int)

type Normal

type Normal struct {
	Vector mgl32.Vec2
	Length float32
}

type ParentMenuItem

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

func NewParentMenuItem

func NewParentMenuItem(label string, children []MenuItem) (item *ParentMenuItem)

func (*ParentMenuItem) Active

func (mi *ParentMenuItem) Active() bool

func (*ParentMenuItem) Children

func (mi *ParentMenuItem) Children() []MenuItem

func (*ParentMenuItem) Highlighted

func (mi *ParentMenuItem) Highlighted() bool

func (*ParentMenuItem) Label

func (mi *ParentMenuItem) Label() string

func (*ParentMenuItem) Parent

func (mi *ParentMenuItem) Parent() MenuItem

type Point

type Point struct {
	mgl32.Vec2
}

func Pt

func Pt(x, y float32) Point

func (Point) Add

func (p Point) Add(pt Point) Point

func (Point) DistanceTo

func (p Point) DistanceTo(pt Point) float32

func (Point) Scale

func (p Point) Scale(a float32) Point

func (Point) Sub

func (p Point) Sub(pt Point) Point

type Rectangle

type Rectangle struct {
	Min Point
	Max Point
}

func Rect

func Rect(x1, y1, x2, y2 float32) Rectangle

func (Rectangle) ContainsPoint

func (r Rectangle) ContainsPoint(a Point) bool

func (Rectangle) IntersectedBy

func (r Rectangle) IntersectedBy(a, b Point) bool

Returns true if r is intersection by the line a, b.

func (Rectangle) Midpoint

func (r Rectangle) Midpoint() Point

func (Rectangle) Overlaps

func (r Rectangle) Overlaps(s Rectangle) bool

type Renderer

type Renderer struct {
	Camera *Camera
}

func NewRenderer

func NewRenderer(camera *Camera) (r *Renderer)

type Scripting

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

func NewScripting

func NewScripting() (s *Scripting, err error)

func (*Scripting) LoadScript

func (s *Scripting) LoadScript(path string) (err error)

func (*Scripting) TriggerEvent

func (s *Scripting) TriggerEvent(eventName string, rawArguments ...interface{}) (err error)

type SoundEffect

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

func NewSoundEffect

func NewSoundEffect(path string) (s *SoundEffect, err error)

func (*SoundEffect) Delete

func (s *SoundEffect) Delete()

func (*SoundEffect) IsPlaying

func (s *SoundEffect) IsPlaying(channel int) int

func (*SoundEffect) Play

func (s *SoundEffect) Play(times int)

func (*SoundEffect) PlayChannel

func (s *SoundEffect) PlayChannel(channel int, times int)

func (*SoundEffect) SetVolume

func (s *SoundEffect) SetVolume(volume int)

type SpriteConfig

type SpriteConfig struct {
	View  ModelViewConfig
	Frame FrameConfig
	Color mgl32.Vec4
}

type SpriteRenderer

type SpriteRenderer struct {
	*Renderer
	// contains filtered or unexported fields
}

func NewSpriteRenderer

func NewSpriteRenderer(camera *Camera) (tr *SpriteRenderer, err error)

func (*SpriteRenderer) Delete

func (tr *SpriteRenderer) Delete() error

func (*SpriteRenderer) Draw

func (tr *SpriteRenderer) Draw(instances []SpriteConfig) error

type Spritesheet

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

func NewSpritesheet

func NewSpritesheet(path string) *Spritesheet

func ParseTexturePackerJSONArrayString

func ParseTexturePackerJSONArrayString(contents string, pxPerUnit float32) (s *Spritesheet, err error)

func (*Spritesheet) AddFrame

func (s *Spritesheet) AddFrame(name string, config SpritesheetFrameConfig)

func (*Spritesheet) GetFrame

func (s *Spritesheet) GetFrame(name string) *SpritesheetFrame

type SpritesheetFrame

type SpritesheetFrame struct {
	Frame  FrameConfig
	Width  float32 // In units
	Height float32 // In units
}

type SpritesheetFrameConfig

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

func (SpritesheetFrameConfig) ToSpritesheetFrame

func (c SpritesheetFrameConfig) ToSpritesheetFrame() *SpritesheetFrame

type TextCache

type TextCache struct {
	Text    string
	Texture *Texture
	// contains filtered or unexported fields
}

func NewTextCache

func NewTextCache(fontface *FontFace) *TextCache

func (*TextCache) Clear

func (tc *TextCache) Clear()

func (*TextCache) Delete

func (tc *TextCache) Delete()

func (*TextCache) SetText

func (tc *TextCache) SetText(text string) (err error)

type TextRenderer

type TextRenderer struct {
	*Renderer
	VBO            uint32
	Program        uint32
	Texture        uint32
	PositionLoc    uint32
	TextureLoc     uint32
	ScaleLoc       int32
	TransLoc       int32
	ProjectionLoc  int32
	TextureUnitLoc int32

	Width  float32
	Height float32
	// contains filtered or unexported fields
}

func NewTextRenderer

func NewTextRenderer(camera *Camera) (tr *TextRenderer, err error)

func (*TextRenderer) Bind

func (tr *TextRenderer) Bind() error

func (*TextRenderer) Delete

func (tr *TextRenderer) Delete() error

func (*TextRenderer) Draw

func (tr *TextRenderer) Draw(tex *Texture, x, y, scale float32) (err error)

func (*TextRenderer) Unbind

func (tr *TextRenderer) Unbind() error

type Texture

type Texture struct {
	Texture        uint32
	Width          int
	Height         int
	OriginalWidth  int
	OriginalHeight int
}

func GetTexture

func GetTexture(img image.Image, smoothing TextureSmoothing) (texture *Texture, err error)

func GetTruncatedTexture

func GetTruncatedTexture(img image.Image, smoothing TextureSmoothing, w, h int) (texture *Texture, err error)

func LoadTexture

func LoadTexture(path string, smoothing TextureSmoothing) (texture *Texture, err error)

func (*Texture) Bind

func (t *Texture) Bind()

func (*Texture) Delete

func (t *Texture) Delete()

func (*Texture) Unbind

func (t *Texture) Unbind()

type TextureSmoothing

type TextureSmoothing int
const (
	Nearest TextureSmoothing = gl.NEAREST
	Linear  TextureSmoothing = gl.LINEAR
)

type TexturedPoint

type TexturedPoint struct {
	X        float32
	Y        float32
	Z        float32
	TextureX float32
	TextureY float32
}

type TexturedTile

type TexturedTile interface {
	ScaledBounds(ratio float32) (x, y, w, h float32)
	ScaledTextureBounds(rx float32, ry float32) (x, y, w, h float32)
}

type TileMetadata

type TileMetadata struct {
	Path          string
	PxPerUnit     int
	TileWidth     int
	TileHeight    int
	FramesWide    int
	FramesHigh    int
	Interpolation InterpolationType
}

Jump to

Keyboard shortcuts

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