tinygametools

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2020 License: Unlicense Imports: 3 Imported by: 12

README

GoDoc Go report card GolangCI CircleCI](https://circleci.com/gh/Galaco/tinyGameTools/tree/master) codecov

TinyGameTools

What is it?

TinyGameTools is a lightweight package for getting started with Go game development.

It does not provide any sort of engine, only a set of lightweight utilities for creating and interacting with an OpenGL 4.1 window.

Features
  • Window. A simple to use glfw window creation wrapper. Will create an OpenGL 4.1 ready window
  • Keyboard. Hooks into Window, and allows for querying button state, and custom input callbacks
  • Mouse. Hooks into Window, and allows for query Mouse state, and custom input callbacks
  • Event bus. A simple event bus for subscribing and publishing messages. Custom messages should fulfil the Event interface, and away you go.
Examples
package main

import (
	"github.com/galaco/tinyGameTools"
)

func main() {
	// Create a window
	win,_ := tinygametools.NewWindow(640, 480, "My Window!")
	
	// Create a keyboard, then register callbacks
	kb := tinygametools.NewKeyboard()
	kb.RegisterCallbacks(win)
	
	// Create the mouse handler, then register callbacks
	mouse := tinyGameTools.NewMouse()
	mouse.RegisterCallbacks(win)
}

@TODO more documentation as features get added

Documentation

Index

Constants

View Source
const (
	KeyUnknown      = Key(glfw.KeyUnknown)
	KeyEscape       = Key(glfw.KeyEscape)
	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)
	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)
	Key0            = Key(glfw.Key0)
	KeySemicolon    = Key(glfw.KeySemicolon)
	KeyMinus        = Key(glfw.KeyMinus)
	KeyEqual        = Key(glfw.KeyEqual)
	KeyBackspace    = Key(glfw.KeyBackspace)
	KeyTab          = Key(glfw.KeyTab)
	KeyQ            = Key(glfw.KeyQ)
	KeyW            = Key(glfw.KeyW)
	KeyE            = Key(glfw.KeyE)
	KeyR            = Key(glfw.KeyR)
	KeyT            = Key(glfw.KeyT)
	KeyY            = Key(glfw.KeyY)
	KeyU            = Key(glfw.KeyU)
	KeyI            = Key(glfw.KeyI)
	KeyO            = Key(glfw.KeyO)
	KeyP            = Key(glfw.KeyP)
	KeyLeftBracket  = Key(glfw.KeyLeftBracket)
	KeyRightBracket = Key(glfw.KeyRightBracket)
	KeyGraveAccent  = Key(glfw.KeyGraveAccent)
	KeyWorld1       = Key(glfw.KeyWorld1)
	KeyWorld2       = Key(glfw.KeyWorld2)
	KeyBackslash    = Key(glfw.KeyBackslash)
	KeyCapsLock     = Key(glfw.KeyCapsLock)
	KeyA            = Key(glfw.KeyA)
	KeyS            = Key(glfw.KeyS)
	KeyD            = Key(glfw.KeyD)
	KeyF            = Key(glfw.KeyF)
	KeyG            = Key(glfw.KeyG)
	KeyH            = Key(glfw.KeyH)
	KeyJ            = Key(glfw.KeyJ)
	KeyK            = Key(glfw.KeyK)
	KeyL            = Key(glfw.KeyL)
	KeySemiColon    = Key(glfw.KeySemicolon)
	KeyApostrophe   = Key(glfw.KeyApostrophe)
	KeyEnter        = Key(glfw.KeyEnter)
	KeyLeftShift    = Key(glfw.KeyLeftShift)
	KeyZ            = Key(glfw.KeyZ)
	KeyX            = Key(glfw.KeyX)
	KeyC            = Key(glfw.KeyC)
	KeyV            = Key(glfw.KeyV)
	KeyB            = Key(glfw.KeyB)
	KeyN            = Key(glfw.KeyN)
	KeyM            = Key(glfw.KeyM)
	KeyComma        = Key(glfw.KeyComma)
	KeyPeriod       = Key(glfw.KeyPeriod)
	KeySlash        = Key(glfw.KeySlash)
	KeyRightShift   = Key(glfw.KeyRightShift)
	KeyLeftCtrl     = Key(glfw.KeyLeftControl)
	KeyLeftAlt      = Key(glfw.KeyLeftAlt)
	KeySpace        = Key(glfw.KeySpace)
	KeyRightAlt     = Key(glfw.KeyRightAlt)
	KeyRightCtrl    = Key(glfw.KeyRightControl)
	KeyDelete       = Key(glfw.KeyDelete)
	KeyInsert       = Key(glfw.KeyInsert)
	KeyUp           = Key(glfw.KeyUp)
	KeyLeft         = Key(glfw.KeyLeft)
	KeyDown         = Key(glfw.KeyDown)
	KeyRight        = Key(glfw.KeyRight)
	KeyPageUp       = Key(glfw.KeyPageUp)
	KeyPageDown     = Key(glfw.KeyPageDown)
	KeyHome         = Key(glfw.KeyHome)
	KeyEnd          = Key(glfw.KeyEnd)
	KeyScrollLock   = Key(glfw.KeyScrollLock)
	KeyNumLock      = Key(glfw.KeyNumLock)
	KeyPrintScreen  = Key(glfw.KeyPrintScreen)
	KeyPause        = Key(glfw.KeyPause)
	KeyLeftSuper    = Key(glfw.KeyLeftSuper)
	KeyRightSuper   = Key(glfw.KeyRightSuper)
	KeyMenu         = Key(glfw.KeyMenu)
	KeyLast         = Key(glfw.KeyLast)
)
View Source
const (
	MouseButton1      = Key(glfw.MouseButton1)
	MouseButton2      = Key(glfw.MouseButton2)
	MouseButton3      = Key(glfw.MouseButton3)
	MouseButton4      = Key(glfw.MouseButton4)
	MouseButton5      = Key(glfw.MouseButton5)
	MouseButton6      = Key(glfw.MouseButton6)
	MouseButton7      = Key(glfw.MouseButton7)
	MouseButton8      = Key(glfw.MouseButton8)
	MouseButtonLast   = Key(glfw.MouseButtonLast)
	MouseButtonLeft   = Key(glfw.MouseButtonLeft)
	MouseButtonRight  = Key(glfw.MouseButtonRight)
	MouseButtonMiddle = Key(glfw.MouseButtonMiddle)
)

Variables

View Source
var (
	// ErrorAlreadyUnsubscribed
	ErrorAlreadyUnsubscribed = errors.New("already unsubscribed, or never subscribed")
)

Functions

This section is empty.

Types

type Event

type Event interface {
	// Type returns the event identifier
	Type() EventName
	// Message returns the payload of the event. Its up the the receiver to know
	// the intended format
	Message() interface{}
}

Event

type EventManager

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

EventManager provides a lightweight pub/sub utility for passing events around.

func NewEventManager

func NewEventManager() *EventManager

NewEventManager returns a new EventManager

func (*EventManager) Publish

func (service *EventManager) Publish(event Event) error

Publish takes an Event and executes all callbacks associated with the passed event.Type()

func (*EventManager) Subscribe

func (service *EventManager) Subscribe(eventName EventName, callback func(event Event), owner interface{}) error

Subscribe takes a callback function and bind it with an EventName. When an event of that EventName is published, the callback will be executed.

func (*EventManager) Unsubscribe

func (service *EventManager) Unsubscribe(eventName EventName, owner interface{}) error

Unsubscribe unassociated a particular callback from an EventName

type EventName

type EventName string

EventName

type Key

type Key int

Key maps to an integer value of a keyboard key (glfw values)

type Keyboard

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

Keyboard provides the current state of the keyboard

func NewKeyboard

func NewKeyboard() *Keyboard

NewKeyboard returns a new keyboard.

func (*Keyboard) AddCharInputCallback

func (keyboard *Keyboard) AddCharInputCallback(callback glfw.CharCallback)

AddCharInputCallback add a custom callback for the true character press. See glfw docs to distinguish between this and KeyCallback

func (*Keyboard) AddKeyCallback

func (keyboard *Keyboard) AddKeyCallback(callback glfw.KeyCallback)

AddKeyCallback add a custom callback to when a key is pressed

func (*Keyboard) IsKeyDown

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

IsKeyDown returns whether a particular key is pressed.

func (*Keyboard) RegisterCallbacks

func (keyboard *Keyboard) RegisterCallbacks(win *Window)

RegisterCallbacks will set the passed windows event callbacks to this instance

type Mouse

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

Mouse is a small wrapper for handling mouse information flow between an application and glfw

func NewMouse

func NewMouse() *Mouse

NewMouse returns a new Mouse

func (*Mouse) AddMouseButtonCallback

func (mouse *Mouse) AddMouseButtonCallback(callback glfw.MouseButtonCallback)

AddMouseButtonCallback

func (*Mouse) AddMousePosCallback

func (mouse *Mouse) AddMousePosCallback(callback glfw.CursorPosCallback)

AddMousePosCallback

func (*Mouse) AddMouseScrollCallback

func (mouse *Mouse) AddMouseScrollCallback(callback glfw.ScrollCallback)

AddMouseScrollCallback

func (*Mouse) IsButtonPressed

func (mouse *Mouse) IsButtonPressed(key Key) bool

IsButtonPressed returns if a particular mouse button has been pressed.

func (*Mouse) RegisterCallbacks

func (mouse *Mouse) RegisterCallbacks(win *Window)

RegisterCallbacks will set the passed windows event callbacks to this instance

func (*Mouse) X

func (mouse *Mouse) X() float64

X returns mouse X coordinate

func (*Mouse) Y

func (mouse *Mouse) Y() float64

Y returns mouse Y coordinate

type Window

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

Window

func NewWindow

func NewWindow(width int, height int, name string) (*Window, error)

NewWindow constructs a new GLFW Window

func (*Window) Handle

func (w *Window) Handle() *glfw.Window

Handle returns internal glfwHandle handle

Jump to

Keyboard shortcuts

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