paunch

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2017 License: MIT Imports: 19 Imported by: 0

README

Paunch GoDoc

Paunch is a 2D game engine written in Go.

Development Status

Paunch is nearing a stable release. There may still be minor API changes, but hopefully future changes will either be bug fixes or new features.

Dependencies

Now that the GLFW bindings bundle the C library with the package, installing the GLFW3 C library is no longer required!

Paunch requires the OpenAL library to be installed. You can find a download here or from your package manager of choice.

Installation

Once you have the dependencies installed, just run go get!

go get github.com/velovix/paunch

Usage

Please take a look at the files in the examples directory if you are looking for help with getting started. The automatically generated documentation found here is also a very helpful reference. I will make an official guide to Paunch when I finish a stable release, but in the mean time, feel free to email me with any questions!

Notes

Your graphics card must support at least OpenGL 2.1 or you will get an error complaining that OpenGL could not be initialized.

Features

  • Shape drawing and texturing through OpenGL
  • Easy-to-use effects system through GLSL shaders
  • Simple window management
  • Mouse and keyboard input
  • Joystick input
  • Fast, optomized collision detection
  • Flexibly handle complex object movement with multiple forces
  • Easy event management through object polling
  • Easy menu management
  • Music and sound effect support
  • Flexible OpenGL version support

To Do

  • ???

Known Issues

  • Intel HD Graphics 4000 may not initialize OpenGL correctly

Documentation

Overview

Package paunch is a 2D game engine written in Go.

Index

Constants

View Source
const (
	Top    = Up
	Bottom = Down
)

Aliases for Direction IDs

View Source
const (
	Press   = Action(glfw.Press)
	Release = Action(glfw.Release)
	Hold    = Action(glfw.Repeat)
)

Action IDs

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

Mouse button IDs

View Source
const (
	KeyUnknown      = Key(glfw.KeyUnknown)
	KeySpace        = Key(glfw.KeySpace)
	KeyApostrophe   = Key(glfw.KeyApostrophe)
	KeyComma        = Key(glfw.KeyComma)
	KeyMinus        = Key(glfw.KeyMinus)
	KeyPeriod       = Key(glfw.KeyPeriod)
	KeySlash        = Key(glfw.KeySlash)
	Key0            = Key(glfw.Key0)
	Key1            = Key(glfw.Key1)
	Key2            = Key(glfw.Key2)
	Key3            = Key(glfw.Key3)
	Key4            = Key(glfw.Key4)
	Key5            = Key(glfw.Key5)
	Key6            = Key(glfw.Key6)
	Key7            = Key(glfw.Key7)
	Key8            = Key(glfw.Key8)
	Key9            = Key(glfw.Key9)
	KeySemicolon    = Key(glfw.KeySemicolon)
	KeyEqual        = Key(glfw.KeyEqual)
	KeyA            = Key(glfw.KeyA)
	KeyB            = Key(glfw.KeyB)
	KeyC            = Key(glfw.KeyC)
	KeyD            = Key(glfw.KeyD)
	KeyE            = Key(glfw.KeyE)
	KeyF            = Key(glfw.KeyF)
	KeyG            = Key(glfw.KeyG)
	KeyH            = Key(glfw.KeyH)
	KeyI            = Key(glfw.KeyI)
	KeyJ            = Key(glfw.KeyJ)
	KeyK            = Key(glfw.KeyK)
	KeyL            = Key(glfw.KeyL)
	KeyM            = Key(glfw.KeyM)
	KeyN            = Key(glfw.KeyN)
	KeyO            = Key(glfw.KeyO)
	KeyP            = Key(glfw.KeyP)
	KeyQ            = Key(glfw.KeyQ)
	KeyR            = Key(glfw.KeyR)
	KeyS            = Key(glfw.KeyS)
	KeyT            = Key(glfw.KeyT)
	KeyU            = Key(glfw.KeyU)
	KeyV            = Key(glfw.KeyV)
	KeyW            = Key(glfw.KeyW)
	KeyX            = Key(glfw.KeyX)
	KeyY            = Key(glfw.KeyY)
	KeyZ            = Key(glfw.KeyZ)
	KeyLeftBracket  = Key(glfw.KeyLeftBracket)
	KeyBackslash    = Key(glfw.KeyBackslash)
	KeyRightBracket = Key(glfw.KeyRightBracket)
	KeyGraveAccent  = Key(glfw.KeyGraveAccent)
	KeyWorld1       = Key(glfw.KeyWorld1)
	KeyWorld2       = Key(glfw.KeyWorld2)
	KeyEscape       = Key(glfw.KeyEscape)
	KeyEnter        = Key(glfw.KeyEnter)
	KeyTab          = Key(glfw.KeyTab)
	KeyBackspace    = Key(glfw.KeyBackspace)
	KeyInsert       = Key(glfw.KeyInsert)
	KeyDelete       = Key(glfw.KeyDelete)
	KeyRight        = Key(glfw.KeyRight)
	KeyLeft         = Key(glfw.KeyLeft)
	KeyDown         = Key(glfw.KeyDown)
	KeyUp           = Key(glfw.KeyUp)
	KeyPageUp       = Key(glfw.KeyPageUp)
	KeyPageDown     = Key(glfw.KeyPageDown)
	KeyHome         = Key(glfw.KeyHome)
	KeyEnd          = Key(glfw.KeyEnd)
	KeyCapsLock     = Key(glfw.KeyCapsLock)
	KeyScrollLock   = Key(glfw.KeyScrollLock)
	KeyNumLock      = Key(glfw.KeyNumLock)
	KeyPrKeyScreen  = Key(glfw.KeyPrintScreen)
	KeyPause        = Key(glfw.KeyPause)
	KeyF1           = Key(glfw.KeyF1)
	KeyF2           = Key(glfw.KeyF2)
	KeyF3           = Key(glfw.KeyF3)
	KeyF4           = Key(glfw.KeyF4)
	KeyF5           = Key(glfw.KeyF5)
	KeyF6           = Key(glfw.KeyF6)
	KeyF7           = Key(glfw.KeyF7)
	KeyF8           = Key(glfw.KeyF8)
	KeyF9           = Key(glfw.KeyF9)
	KeyF10          = Key(glfw.KeyF10)
	KeyF11          = Key(glfw.KeyF11)
	KeyF12          = Key(glfw.KeyF12)
	KeyF13          = Key(glfw.KeyF13)
	KeyF14          = Key(glfw.KeyF14)
	KeyF15          = Key(glfw.KeyF15)
	KeyF16          = Key(glfw.KeyF16)
	KeyF17          = Key(glfw.KeyF17)
	KeyF18          = Key(glfw.KeyF18)
	KeyF19          = Key(glfw.KeyF19)
	KeyF20          = Key(glfw.KeyF20)
	KeyF21          = Key(glfw.KeyF21)
	KeyF22          = Key(glfw.KeyF22)
	KeyF23          = Key(glfw.KeyF23)
	KeyF24          = Key(glfw.KeyF24)
	KeyF25          = Key(glfw.KeyF25)
	KeyKp0          = Key(glfw.KeyKp0)
	KeyKp1          = Key(glfw.KeyKp1)
	KeyKp2          = Key(glfw.KeyKp2)
	KeyKp3          = Key(glfw.KeyKp3)
	KeyKp4          = Key(glfw.KeyKp4)
	KeyKp5          = Key(glfw.KeyKp5)
	KeyKp6          = Key(glfw.KeyKp6)
	KeyKp7          = Key(glfw.KeyKp7)
	KeyKp8          = Key(glfw.KeyKp8)
	KeyKp9          = Key(glfw.KeyKp9)
	KeyKpDecimal    = Key(glfw.KeyKpDecimal)
	KeyKpDivide     = Key(glfw.KeyKpDivide)
	KeyKpMultiply   = Key(glfw.KeyKpMultiply)
	KeyKpSubtract   = Key(glfw.KeyKpSubtract)
	KeyKpAdd        = Key(glfw.KeyKpAdd)
	KeyKpEnter      = Key(glfw.KeyKpEnter)
	KeyKpEqual      = Key(glfw.KeyKpEqual)
	KeyLeftShift    = Key(glfw.KeyLeftShift)
	KeyLeftControl  = Key(glfw.KeyLeftControl)
	KeyLeftAlt      = Key(glfw.KeyLeftAlt)
	KeyLeftSuper    = Key(glfw.KeyLeftSuper)
	KeyRightShift   = Key(glfw.KeyRightShift)
	KeyRightControl = Key(glfw.KeyRightControl)
	KeyRightAlt     = Key(glfw.KeyRightAlt)
	KeyRightSuper   = Key(glfw.KeyRightSuper)
	KeyMenu         = Key(glfw.KeyMenu)
	KeyLast         = Key(glfw.KeyLast)
)

Keyboard key IDs

View Source
const (
	Initial = SoundState(al.Initial)
	Playing = SoundState(al.Playing)
	Paused  = SoundState(al.Paused)
	Stopped = SoundState(al.Stopped)
)

Sound state IDs

Shader type IDs

View Source
const (
	ShapePoints        = ShapeType(gl.POINTS)
	ShapeLines         = ShapeType(gl.LINES)
	ShapeLineStrip     = ShapeType(gl.LINE_STRIP)
	ShapeLineLoop      = ShapeType(gl.LINE_LOOP)
	ShapeTriangles     = ShapeType(gl.TRIANGLES)
	ShapeTriangleStrip = ShapeType(gl.TRIANGLE_STRIP)
	ShapeTriangleFan   = ShapeType(gl.TRIANGLE_FAN)
	ShapePolygon       = ShapeType(gl.POLYGON)
)

Shape IDs

Variables

This section is empty.

Functions

func Clear

func Clear() error

Clear clears the pixels on screen. This should probably be called before every new frame.

func Collides

func Collides(collider1, collider2 Collider) bool

Collides checks if two Collider-satisfying objects are overlapping.

func DisableEffects

func DisableEffects()

DisableEffects disables all effects.

func SetClearColor

func SetClearColor(r uint8, g uint8, b uint8)

SetClearColor sets the color the screen will become after a call to the Clear function.

func SetNativeWindowSize

func SetNativeWindowSize(nativeWidth, nativeHeight int)

SetNativeWindowSize sets the native width and height of the Paunch window. The native width and height are values representing what size the window must be at for one screen pixel to equal one pixel in your program. If these values are not set, Paunch will make these values equal to the size of the window at the time Start() is called.

func SetWindowFullScreen

func SetWindowFullScreen(fullscreen bool)

SetWindowFullScreen sets whether or not the Paunch window is full screen. The window will not be full screen by default.

func SetWindowNativeMousePos

func SetWindowNativeMousePos(shouldBeNative bool)

SetWindowNativeMousePos changes the behavior of the reported mouse position. If enabled, supplied mouse positions are made relative to the native width and native height of the Window object. This is useful for applications that stretch to larger window sizes, so that mouse position behavior remains the same regardless of window size.

func SetWindowSize

func SetWindowSize(width, height int)

SetWindowSize sets the width and height of the Paunch window. Width and height MUST be set before calling Start(). Any number below zero is not a valid width or height value.

func SetWindowTitle

func SetWindowTitle(title string)

SetWindowTitle sets the title of the Paunch window, which is generally the text that's shown at the top of the window. The default string is empty.

func ShouldClose

func ShouldClose() bool

ShouldClose returns whether or not the user has attempted to close the window. Will always return false if the Window object has not been opened.

func Start

func Start() error

Start starts the Paunch system by opening the window and beginning to recieve input. Some Paunch operations may fail if this function has not yet been called, including all drawing commands.

func Stop

func Stop()

Stop safely closes the Paunch instance.

func UpdateDisplay

func UpdateDisplay() error

UpdateDisplay updates the window to display whatever has been drawn to the framebuffer.

func UpdateEvents

func UpdateEvents() error

UpdateEvents updates events.

func UseEffect

func UseEffect(effect *Effect) error

UseEffect sets the given Effect object for use in the following draw commands.

Types

type Action

type Action int

Action corresponds to a key or button action.

type Axis

type Axis int

Axis corresponds to an axis value.

const (
	X Axis
	Y
)

Axis IDs

type CharacterEventResponder

type CharacterEventResponder interface {
	OnCharacter(character rune)
}

CharacterEventResponder is an interface that requires methods that allow an EventManager to call on the OnCharacter method of an object when the user inputs a valid unicode character. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

type Collider

type Collider interface {

	// Move moves the Collider object the specified distance.
	Move(x, y float64)
	// SetPosition sets the position of the Collider.
	SetPosition(x, y float64)
	// Position returns the x, y coordinates of the Collider object's
	// current position.
	Position() (float64, float64)
	// DistanceToTangentPoint returns the x, y coordinates of the nearest point
	// tangent to the Collider object. This method is useful for position
	// correction when objects have sunk into each other.
	DistanceToTangentPoint(float64, float64, Direction) (float64, float64)
	// contains filtered or unexported methods
}

Collider is an object that represents a shape that can be tested for collision against another Collider.

func NewCollider

func NewCollider(coords []float64) Collider

NewCollider creates a new Collider object. The supplied coordinates should be in an "x1, y1, x2, y2..." format. Colliders work differently internally depending on the shape the coordinate describes. Collision detection is faster for singular points and bounding boxes than with lines and polygons.

type CollisionEventResponder

type CollisionEventResponder interface {
	GetColliders() []Collider
	OnCollision(c1, c2 Collider, culprit interface{})
}

CollisionEventResponder is an interface that requires methods that allow an EventManager to check the object's Collider objects against those of other objects. Objects that implement this interface will automatically be checked when added to an EventManager.

type Direction

type Direction int

Direction corresponds to a directional value.

const (
	Up Direction
	Down
	Left
	Right
)

Direction IDs

type DrawEventResponder

type DrawEventResponder interface {
	OnDraw()
}

DrawEventResponder is an interface that requires methods that allow an EventManager to draw an object at every frame. Objects that implement this interface will be autmatically called on every frame.

type Effect

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

Effect is an object that manages shaders.

func NewEffectFromDirectory

func NewEffectFromDirectory(directory string) (*Effect, error)

NewEffectFromDirectory creates a new Effect object based on the shader directory given.

func NewEffectFromFiles

func NewEffectFromFiles(filenames []string) (*Effect, error)

NewEffectFromFiles creates a new Effect object based on the shader file names given.

func NewEffectFromStrings

func NewEffectFromStrings(text []string, types []ShaderType) (*Effect, error)

NewEffectFromStrings creates a new Effect object based on the given strings containing GLSL shader script. The types values should correlate with the type of shader the script is describing.

func (*Effect) SetVariable2f

func (effect *Effect) SetVariable2f(variable string, val1 float32, val2 float32) error

SetVariable2f sets a specified variable to the two supplied integers to be passed into an effect.

func (*Effect) SetVariable2i

func (effect *Effect) SetVariable2i(variable string, val1 int, val2 int) error

SetVariable2i sets a specified variable to the two supplied integers to be passed into an effect.

func (*Effect) SetVariable3f

func (effect *Effect) SetVariable3f(variable string, val1 float32, val2 float32, val3 float32) error

SetVariable3f sets a specified variable to the three supplied integers to be passed into an effect.

func (*Effect) SetVariable3i

func (effect *Effect) SetVariable3i(variable string, val1 int, val2 int, val3 int) error

SetVariable3i sets a specified variable to the three supplied integers to be passed into an effect.

func (*Effect) SetVariable4f

func (effect *Effect) SetVariable4f(variable string, val1 float32, val2 float32, val3 float32, val4 float32) error

SetVariable4f sets a specified variable to the four supplied integers to be passed into an effect.

func (*Effect) SetVariable4i

func (effect *Effect) SetVariable4i(variable string, val1 int, val2 int, val3 int, val4 int) error

SetVariable4i sets a specified variable to the four supplied integers to be passed into an effect.

func (*Effect) SetVariablef

func (effect *Effect) SetVariablef(variable string, val float32) error

SetVariablef sets a specified variable to the supplied integer to be passed into an effect.

func (*Effect) SetVariablei

func (effect *Effect) SetVariablei(variable string, val int) error

SetVariablei sets a specified variable to the supplied integer to be passed into an effect.

type EventManager

type EventManager struct {
	Objects []interface{}
}

EventManager triggers methods with the On- prefix when appropriate given the objects supplied to it.

func NewEventManager

func NewEventManager() *EventManager

NewEventManager creates a new EventManager.

func (*EventManager) Collides

func (eventManager *EventManager) Collides(collider Collider) bool

Collides checks if the supplied Collider collides with any of the EventManager's objects.

func (*EventManager) GetUserEvents

func (eventManager *EventManager) GetUserEvents(getting bool)

GetUserEvents sets whether or not the EventManager object should be recieving user events. The default value is false.

func (*EventManager) RunCharacterEvent

func (eventManager *EventManager) RunCharacterEvent(character rune)

RunCharacterEvent simulates a character event, triggering the expected response from the EventManager's objects.

func (*EventManager) RunCollisionEvent

func (eventManager *EventManager) RunCollisionEvent()

RunCollisionEvent checks for collisions between the EventManager's objects and triggers appropriate methods.

func (*EventManager) RunDrawEvent

func (eventManager *EventManager) RunDrawEvent()

RunDrawEvent runs a draw event, triggering the expected response from the EventManager's objects.

func (*EventManager) RunJoystickAxisEvent

func (eventManager *EventManager) RunJoystickAxisEvent(device int, value float64)

RunJoystickAxisEvent simulates a joystick axis event, triggering the expected response from the EventManager's objects.

func (*EventManager) RunJoystickButtonEvent

func (eventManager *EventManager) RunJoystickButtonEvent(button int, action Action)

RunJoystickButtonEvent simulates a joystick button event, triggering the expected response from the EventManager's objects.

func (*EventManager) RunKeyEvent

func (eventManager *EventManager) RunKeyEvent(key Key, action Action)

RunKeyEvent simulates a key event, triggering the expected response from the EventManager's objects.

func (*EventManager) RunMouseButtonEvent

func (eventManager *EventManager) RunMouseButtonEvent(button MouseButton, action Action, x, y float64)

RunMouseButtonEvent simulates a mouse button event, triggering the expected response from the EventManager's objects.

func (*EventManager) RunMouseEnterWindowEvent

func (eventManager *EventManager) RunMouseEnterWindowEvent(x, y float64, entered bool)

RunMouseEnterWindowEvent simulates a mouse enter window event, triggering the expected response from the EventManager's objects.

func (*EventManager) RunMousePositionEvent

func (eventManager *EventManager) RunMousePositionEvent(x, y float64)

RunMousePositionEvent simulates a mouse position event, triggering the expected response from the EventManager's objects.

func (*EventManager) RunScrollEvent

func (eventManager *EventManager) RunScrollEvent(xOffset, yOffset float64)

func (*EventManager) RunTickEvent

func (eventManager *EventManager) RunTickEvent()

RunTickEvent runs a tick event, triggering the expected response from the EventManager's objects.

func (*EventManager) RunWindowFocusEvent

func (eventManager *EventManager) RunWindowFocusEvent(focused bool)

RunWindowFocusEvent simulates a window focus event, triggering the expected response from the EventManager's objects.

func (*EventManager) RunWindowResizeEvent

func (eventManager *EventManager) RunWindowResizeEvent(width, height int)

RunWindowResizeEvent simulates a window resize event, triggering the expected response from the EventManager's objects.

type Font

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

Font represents a font file. Most common font files are supported.

func NewFont

func NewFont(fontFile string) (*Font, error)

NewFont creates a new Font object based on the font file provided.

type JoystickAxisEventResponder

type JoystickAxisEventResponder interface {
	OnJoystickAxis(device int, value float64)
}

JoystickAxisEventResponder is an interface that requires methods that allow an EventManager to call on the OnJoystickAxis method of an object when the user has at least on analog device on their joystick. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

type JoystickButtonEventResponder

type JoystickButtonEventResponder interface {
	OnJoystickButton(button int, action Action)
}

JoystickButtonEventResponder is an interface that requires methods that allow an EventManager to call on the OnJoystickButton method of an object when the user presses, holds, or releases a joystick button. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

type Key

type Key int

Key corresponds to a key on the keyboard.

type KeyboardEventResponder

type KeyboardEventResponder interface {
	OnKeyboard(key Key, action Action)
}

KeyboardEventResponder is an interface that requires methods that allow an EventManager to call the OnKeyboard method of an object when a keyboard event happens. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

type MouseButton

type MouseButton int

MouseButton corresponds to a mouse button.

type MouseButtonEventResponder

type MouseButtonEventResponder interface {
	OnMouseButton(button MouseButton, action Action, x, y float64)
}

MouseButtonEventResponder is an interface that requires methods that allow an EventManager to call the OnMouseButton method of an object when a mouse button event happens. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

type MouseEnterWindowResponder

type MouseEnterWindowResponder interface {
	OnMouseEnterWindow(x, y float64, entered bool)
}

MouseEnterWindowResponder is an interface that requires methods that allow an EventManager to call on the OnMouseEnterWindow method of an object when a mouse enters or leaves a window. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

type MousePositionEventResponder

type MousePositionEventResponder interface {
	OnMousePosition(x, y float64)
}

MousePositionEventResponder is an interface that requires methods that allow an EventManager to call the OnMousePosition method of an object when a mouse position event happens. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

type Mover

type Mover interface {
	Move(x, y float64)
	SetPosition(x, y float64)
	Position() (x, y float64)
}

The Mover interface represents an object that can move and report it's positions.

type OpenGLError

type OpenGLError struct {
	ErrorCodes []gl.Enum
}

OpenGLError is an error-implementing object describing sets of OpenGL errors.

func (OpenGLError) Error

func (err OpenGLError) Error() string

Error returns a descriptive string.

type Physics

type Physics struct {
	Movers []Mover
	// contains filtered or unexported fields
}

Physics is an object meant to make the Movement of multiple related Movers, such as a Renderable and a Collision, easier. It also allows for easy management of multiple forces of Movement at once.

func NewPhysics

func NewPhysics() *Physics

NewPhysics creates a new Physics object.

func (*Physics) Accelerate

func (physics *Physics) Accelerate(forceX, forceY float64)

Accelerate exerts a specified force upon the Physics object the next time the Calculate method is called.

func (*Physics) Acceleration

func (physics *Physics) Acceleration() (float64, float64)

Acceleration returns the X and Y acceleration of the Physics object.

func (*Physics) AddForce

func (physics *Physics) AddForce(name string, forceX, forceY float64)

AddForce adds a constant force to the Physics object, which is taken into account every time the Calculate method is called. The force is disabled by default.

func (*Physics) Calculate

func (physics *Physics) Calculate()

Calculate Moves the Physics object given any specified constant forces, calls to the Accelerate method, and any leftover acceleration. Then, friction is applied to the resulting acceleration value.

func (*Physics) DeleteForce

func (physics *Physics) DeleteForce(name string)

DeleteForce reMoves a constant force from the Physics object.

func (*Physics) DisableForce

func (physics *Physics) DisableForce(name string)

DisableForce makes the specified force inactive for future calls to the Calculate method.

func (*Physics) EnableForce

func (physics *Physics) EnableForce(name string)

EnableForce makes the specified force active for future calls to the Calculate method.

func (*Physics) Move

func (physics *Physics) Move(x, y float64)

Move Moves all the members of the Physics object a specified distance.

func (*Physics) Position

func (physics *Physics) Position() (x, y float64)

Position returns the position of the Physics object's first Mover.

func (*Physics) SetAcceleration

func (physics *Physics) SetAcceleration(force float64, axis Axis)

SetAcceleration sets the acceleration of the Physics object on the specified axis.

func (*Physics) SetFriction

func (physics *Physics) SetFriction(forceX, forceY float64)

SetFriction sets the friction value of the Physics object. Friction is a force that enfluences acceleration to Move toward zero. This might be used to simulate the natural slowdown of an object rubbing against a surface.

func (*Physics) SetMaxAcceleration

func (physics *Physics) SetMaxAcceleration(force float64, axis Axis)

SetMaxAcceleration sets the maximum allowed acceleration of the Physics object on the specified axis. In situations where the object would normally go faster than the specified value, it will be set to the value instead.

func (*Physics) SetMinAcceleration

func (physics *Physics) SetMinAcceleration(force float64, axis Axis)

SetMinAcceleration sets the minimum allowed acceleration of the Physics object on the specified axis. In situations where the object would normally go slower than the specified value, it will be set to the value instead.

func (*Physics) SetPosition

func (physics *Physics) SetPosition(x, y float64)

SetPosition sets the position of the Physics object relative to the Physics object's first Mover.

type ScrollResponder

type ScrollResponder interface {
	OnScroll(xOffset, yOffset float64)
}

ScrollResponder is an interface that requires methods that allow an EventManager to call the OnScroll method of an object when a scrolling event happens. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

type ShaderType

type ShaderType int

ShaderType is a value that represents a shader type.

type Shape

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

Shape is an object that represents a vector shape, such as a triangle or other polygon, that can be drawn on screen.

func NewShape

func NewShape(shapeType ShapeType, verticies []float64) (*Shape, error)

NewShape creates a new Shape object based on the verticies and shape type.

func NewShapeFromShape

func NewShapeFromShape(copyShape *Shape) (*Shape, error)

NewShapeFromShape creates a copy of an existing Shape object.

func (*Shape) Draw

func (shape *Shape) Draw() error

Draw draws the Shape object.

func (*Shape) Move

func (shape *Shape) Move(x, y float64)

Move moves the Shape object a specified distance.

func (*Shape) Position

func (shape *Shape) Position() (x, y float64)

Position returns the X and Y position relative to the first specified vertex.

func (*Shape) SetPosition

func (shape *Shape) SetPosition(x, y float64)

SetPosition sets the position of the Shape object relative to first specified vertex.

func (*Shape) SetScaling

func (shape *Shape) SetScaling(scaleX, scaleY float64)

SetScaling sets the scaling factor of the Shape object. For instance, an x and y scale value of two will make the Shape object twice as large.

type ShapeType

type ShapeType int

ShapeType is a value that represents a shape type.

type Sound

type Sound struct {
	SampleRate  int32
	NumChannels int32
	// contains filtered or unexported fields
}

Sound represents a playable sound clip.

func NewSound

func NewSound(filename string) (*Sound, error)

NewSound returns a new Sound object based on the provided file. As of right now, NewSound only supports standard WAV files.

func (*Sound) Channels

func (sound *Sound) Channels() uint

Channels returns the number of channels.

func (*Sound) Destroy

func (sound *Sound) Destroy()

Destroy cleans up the Sound object, which will no longer be playable. This should be done after the Sound object is no longer needed.

func (*Sound) Frequency

func (sound *Sound) Frequency() uint

Frequency returns the frequency of the sound in Hertz.

func (*Sound) Gain

func (sound *Sound) Gain() float32

Gain returns the gain (volume) of the Sound object.

func (*Sound) Length

func (sound *Sound) Length() float32

Length returns the total length of the Sound object in seconds.

func (*Sound) Offset

func (sound *Sound) Offset() float32

Offset returns the current playing position of the Sound object in seconds.

func (*Sound) Pause

func (sound *Sound) Pause()

Pause pauses the Sound object at it's current time. The Play method will resume from where the Pause method left off.

func (*Sound) Play

func (sound *Sound) Play()

Play plays the Sound object from it's current time. If the Sound has never been played, that time will be at the beginning.

func (*Sound) Playing

func (sound *Sound) Playing() SoundState

Playing returns a SoundState value reflecting the playing state of the Sound object.

func (*Sound) SetGain

func (sound *Sound) SetGain(gain float32)

SetGain sets the gain (volume) of the Sound object. 1 is the default value.

func (*Sound) SetLoop

func (sound *Sound) SetLoop(willLoop bool)

SetLoop sets whether or not the Sound object should loop at the end of it's sample. The default value is false.

func (*Sound) SetOffset

func (sound *Sound) SetOffset(seconds float32)

SetOffset sets the playing position of the Sound object in seconds.

func (*Sound) SetPitch

func (sound *Sound) SetPitch(pitch float32)

SetPitch sets the pitch modulation of the Sound object. 1 is the default value. A reduction in pitch by half is equal to lowering the sound by one octave, and vice versa when doubling pitch.

func (*Sound) Size

func (sound *Sound) Size() uint

Size returns the size of the sound data in bytes.

func (*Sound) Stop

func (sound *Sound) Stop()

Stop pauses the Sound object and brings it's time to the beginning.

type SoundState

type SoundState int

SoundState is a value that can be retured by Sound.GetPlaying().

type Sprite

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

Sprite is a textured object, an object that is displayed on the screen using image data.

func NewSprite

func NewSprite(x, y, width, height float64, data []byte, clip int) (*Sprite, error)

NewSprite creates a new Sprite object using the given data, which is expected to be in RGBA format. If you use PNG image files, you can use the NewSpriteFromImage shortcut function instead.

func NewSpriteFromImage

func NewSpriteFromImage(x, y float64, filename string, clip int) (*Sprite, error)

NewSpriteFromImage creates a new Sprite object using the given PNG image file.

func NewSpriteFromSprite

func NewSpriteFromSprite(sprite *Sprite) (*Sprite, error)

NewSpriteFromSprite creates a new Sprite object that uses the same image data as the supplied Sprite object. This can serve to save a lot of GPU memory when dealing with Sprite objects that use image data.

func (*Sprite) Draw

func (sprite *Sprite) Draw(frame int) error

Draw draws the Sprite object.

func (*Sprite) Move

func (sprite *Sprite) Move(x, y float64)

Move moves the Sprite object a specified distance.

func (*Sprite) Position

func (sprite *Sprite) Position() (x, y float64)

Position returns the X and Y position of the bottom-left corner of the Sprite object.

func (*Sprite) SetPosition

func (sprite *Sprite) SetPosition(x, y float64)

SetPosition sets the position of the Sprite object relative to the bottom- left corner.

func (*Sprite) SetScaling

func (sprite *Sprite) SetScaling(xScale, yScale float64)

SetScaling sets the scaling factor of the Sprite object. For instance, an x and y scale value of two will make the Sprite object twice as large.

type Text

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

Text is an object that represents drawable text.

func NewText

func NewText(x, y float64, font *Font, fontSize float64, message string) (*Text, error)

NewText creates a new Text object. The x and y positions represent the left and bottom of text without tails.

func (*Text) Draw

func (text *Text) Draw()

Draw draws the Text object.

func (*Text) Message

func (text *Text) Message() string

Message returns the current message displayed by the Text object.

func (*Text) Move

func (text *Text) Move(x, y float64)

Move moves the Text object the specified distance.

func (*Text) Position

func (text *Text) Position() (float64, float64)

Position returns the position of the Text object.

func (*Text) SetColor

func (text *Text) SetColor(r, g, b, a uint8) error

SetColor sets the color of the Text object. The default is black (0, 0, 0, 255).

func (*Text) SetMessage

func (text *Text) SetMessage(message string) error

SetMessage changes the message displayed by the Text object.

func (*Text) SetPosition

func (text *Text) SetPosition(x, y float64)

SetPosition sets the Text object's position to the specified point.

func (*Text) Size

func (text *Text) Size() (float64, float64)

Size returns the width and height of the Text object.

type TickEventResponder

type TickEventResponder interface {
	OnTick()
}

TickEventResponder is an interface that requires methods that allow an EventManager to call on the OnTick method with every tick of the EventManager. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

type WindowFocusEventResponder

type WindowFocusEventResponder interface {
	OnWindowFocus(focused bool)
}

WindowFocusEventResponder is an interface that requires methods that allow an EventManager to call on the OnWindowFocus method of an object when the user changes the focus of a window. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

type WindowResizeEventResponder

type WindowResizeEventResponder interface {
	OnWindowResize(width, height int)
}

WindowResizeEventResponder is an interface that requires methods that allow an EventManager to call on the OnWindowResize method of an object when the user changes the size of a window. Objects that implement this interface will automatically be called when appropriate after being added to an EventManager.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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