engine

package
v0.0.0-...-9989d13 Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

type Game struct {
	States map[string]State
	// contains filtered or unexported fields
}

func (*Game) CurrentStateID

func (game *Game) CurrentStateID() string

func (*Game) Objects

func (game *Game) Objects() map[string][]Object

func (*Game) ReceiveKeyEvent

func (game *Game) ReceiveKeyEvent(event KeyEvent)

func (*Game) ReceiveMouseEvent

func (game *Game) ReceiveMouseEvent(event MouseEvent)

func (*Game) Tick

func (game *Game) Tick(ms int)

func (*Game) Transition

func (game *Game) Transition(nextStateKey string)

type KeyEvent

type KeyEvent struct {
	Type KeyEventType

	Alt   bool
	Ctrl  bool
	Shift bool

	Key string
}

type KeyEventTarget

type KeyEventTarget interface {
	HandleKeyEvent(event KeyEvent) *Transition
}

KeyEventTarget can be implemented by States to receive key events.

type KeyEventType

type KeyEventType string
const (
	KeyUp    KeyEventType = "up"
	KeyDown  KeyEventType = "down"
	KeyPress KeyEventType = "press"
)

type MouseEvent

type MouseEvent struct {
	Type MouseEventType

	Alt   bool
	Ctrl  bool
	Shift bool

	X int
	Y int

	// Button is the button pressed for mouse up and down events. Do not use this
	// directly, instead use PrimaryButton(), ...
	Button int
}

func (MouseEvent) AuxiliaryButton

func (event MouseEvent) AuxiliaryButton() bool

AuxiliaryButton checks wether the auxiliary button (usually middle / mouse wheel) was the cause of an up or down event.

func (MouseEvent) PrimaryButton

func (event MouseEvent) PrimaryButton() bool

PrimaryButton checks wether the primary button (usually left) was the cause of an up or down event.

func (MouseEvent) SecondaryButton

func (event MouseEvent) SecondaryButton() bool

SecondaryButton checks wether the secondary button (usually right) was the cause of an up or down event.

type MouseEventTarget

type MouseEventTarget interface {
	HandleMouseEvent(event MouseEvent) *Transition
}

MouseEventTarget can be implemented by States to receive mouse events.

type MouseEventType

type MouseEventType string
const (
	MouseUp   MouseEventType = "up"
	MouseDown MouseEventType = "down"
	MouseMove MouseEventType = "move"
)

type Object

type Object struct {
	Key string

	X float64
	Y float64

	Z int

	// Animation is the progress of animation. 0 is the start, 1 is the end. Still
	// works if above or below this interval.
	Animation float64

	// SmoothPosition is a flag to let objects break out from the fixed pixel grid.
	SmoothPosition bool

	Scale int
}

type State

type State interface {
	// Init will be called every time this state is transitioned to.
	Init()

	// Tick invokes a game tick, given a duration in milliseconds.
	Tick(ms int) *Transition

	Objects() map[string][]Object
}

type Transition

type Transition struct {
	NextStateKey string
}

func NewTransition

func NewTransition(nextStateKey string) *Transition

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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