Documentation ¶
Index ¶
- Constants
- func GenerateFromPNGFile(inputFile string, outputFile string, packageName string, ...)
- type BeforePaint
- type Collision
- type CollisionHandler
- type DynamicData
- type EventHandler
- type FramePainter
- type Game
- type GameObject
- func (gameObject *GameObject) ClearDynamicData(key string)
- func (gameObject *GameObject) CurrentSprite() SpriteInterface
- func (gameObject *GameObject) GetCollisionEdge(collidingObject *GameObject) string
- func (gameObject *GameObject) GetDynamicData(key string, fallback interface{}) interface{}
- func (gameObject *GameObject) HasDynamicData(key string) bool
- func (gameObject *GameObject) Height() int
- func (gameObject *GameObject) IsResting() bool
- func (gameObject *GameObject) RecalculatePosition(gravity float64)
- func (gameObject *GameObject) SetDynamicData(key string, value interface{})
- func (gameObject *GameObject) Width() int
- type GameObjectStates
- type KeyListener
- type Level
- type Palette
- type Sprite
- type SpriteGroup
- type SpriteInterface
- type SpriteSeries
- type Vector
Constants ¶
const ( // The values are determined via a catersian plane DirLeft = -1 // x-axis DirRight = 1 // x-axis DirStationary = 0 // x-axis )
Direction constants
const ( EventFloorCollision = 0 EventDropOffLevel = 1 EventFreeFall = 2 )
Event constants
const ( EdgeTop = "top" EdgeTopLeft = "top_left" EdgeTopRight = "top_right" EdgeBottom = "bottom" EdgeBottomLeft = "bottom_left" EdgeBottomRight = "bottom_right" EdgeLeft = "left" EdgeRight = "right" EdgeNone = "none" )
Collision Edges
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BeforePaint ¶
type BeforePaint func(level *Level)
BeforePaint is the signature for functions that are called on levels prior to them being repainted
type Collision ¶
type Collision struct { GameObject *GameObject Edge string }
Collision is a struct that represents a collision with another game object
type CollisionHandler ¶
type CollisionHandler func(gameObject *GameObject, collision Collision)
CollisionHandler is a signature for functions that handle collision events
type DynamicData ¶
type DynamicData map[string]interface{}
DynamicData is a type that defines a repository of arbitrary game object data
type EventHandler ¶
type EventHandler func(eventCode int, gameObject *GameObject)
EventHandler is the signature for functions that handle game events
type FramePainter ¶
FramePainter is the signature for functions that handle frame painting
type Game ¶
type Game struct { Title string Width int Height int ScaleFactor int TargetFrameRate int FramePainter FramePainter KeyListener KeyListener Levels []*Level CurrentLevelID int CurrentFrame int }
Game is a struct that defines a game and the window that contains it
func CreateGame ¶
func CreateGame(title string, width int, height int, scaleFactor int, targetFrameRate int, framePainter FramePainter, keyListener KeyListener, levels []*Level) *Game
CreateGame sets up a game and its window
func (*Game) BroadcastInput ¶
BroadCastInput sends the game input to the current level's object if they are controllable
func (*Game) CurrentLevel ¶
CurrentLevel gets the current level object
type GameObject ¶
type GameObject struct { CurrentState string States GameObjectStates Position Vector Mass float64 Velocity Vector Direction int IsFlipped bool IsControllable bool IsFloor bool IsInteractive bool IsHidden bool Level *Level DynamicData DynamicData FloorY float64 EventHandler EventHandler CollisionHandler CollisionHandler }
GameObject represented a sprite and its properties
func (*GameObject) ClearDynamicData ¶
func (gameObject *GameObject) ClearDynamicData(key string)
ClearDynamicData clears a piece of specific dynamic game object data
func (*GameObject) CurrentSprite ¶
func (gameObject *GameObject) CurrentSprite() SpriteInterface
CurrentSprite gets the current sprite for the object's state
func (*GameObject) GetCollisionEdge ¶
func (gameObject *GameObject) GetCollisionEdge(collidingObject *GameObject) string
GetCollisionEdge infers edge on which an intersecting object collided with the game object
func (*GameObject) GetDynamicData ¶
func (gameObject *GameObject) GetDynamicData(key string, fallback interface{}) interface{}
GetDynamicData gets a piece of dynamic game object data, falling back to a define value if the data does not exist
func (*GameObject) HasDynamicData ¶
func (gameObject *GameObject) HasDynamicData(key string) bool
HasDynamicData checks whether a piece of dynamic data game object data exists
func (*GameObject) Height ¶
func (gameObject *GameObject) Height() int
Height gets height of the game object
func (*GameObject) IsResting ¶
func (gameObject *GameObject) IsResting() bool
IsResting determined whether the game object is currently atop another game object
func (*GameObject) RecalculatePosition ¶
func (gameObject *GameObject) RecalculatePosition(gravity float64)
RecalculatePosition recalculates the latest X and Y position of the game
object from its properties
func (*GameObject) SetDynamicData ¶
func (gameObject *GameObject) SetDynamicData(key string, value interface{})
SetDynamicData sets a piece of dynamic game object data
func (*GameObject) Width ¶
func (gameObject *GameObject) Width() int
Width gets width of the game object
type GameObjectStates ¶
type GameObjectStates map[string]SpriteSeries
GameObjectStates is a type that defines the various states (and accompanying sprites) of game objects
type KeyListener ¶
type KeyListener func(event key.Event, gameObject *GameObject)
KeyListener is the signature for functions that handle key events for controllable game objects
type Level ¶
type Level struct { BackgroundColour color.RGBA Gravity float64 GameObjects []*GameObject Game *Game PaintOffset Vector BeforePaint BeforePaint }
Level is a struct that defines a single level of a game
func (*Level) AssignFloors ¶
func (level *Level) AssignFloors()
AssignFloors iterates through all objects in the level and defines which object beneath them (if any) should be considered their 'floor' object, setting its top edge as the lowest point that the object can fall
func (*Level) CalculateCollisions ¶
func (level *Level) CalculateCollisions()
CalculateCollisions iterates via all objects in the level and defines which objects (if any) intersect them
type Sprite ¶
Sprite defines structure of single sprite
func CreateSprite ¶
CreateSprite object based on a set of hex-encoded scanlines
func (*Sprite) AddToCanvas ¶
AddToCanvas draws sprite to an existing image canvas
type SpriteGroup ¶
SpriteGroup is a struct that represents a group of sprites that form a larger individual sprite
func CreateSpriteGroup ¶
func CreateSpriteGroup(width int, height int, sprites *[]*Sprite) (*SpriteGroup, error)
CreateSpriteGroup creates a sprite group based on a grid size and collection of sprites
func (*SpriteGroup) AddToCanvas ¶
func (spriteGroup *SpriteGroup) AddToCanvas(canvas *image.RGBA, targetX int, targetY int, mirrorImage bool)
AddToCanvas draws the sprite group on an existing image canvas
func (*SpriteGroup) Height ¶
func (spriteGroup *SpriteGroup) Height() int
Height gets the pixel height of the sprite group
func (*SpriteGroup) Width ¶
func (spriteGroup *SpriteGroup) Width() int
Width gets the pixel width of the sprite group
type SpriteInterface ¶
type SpriteInterface interface { AddToCanvas(canvas *image.RGBA, targetX int, targetY int, mirrorImage bool) Width() int Height() int }
SpriteInterface is an interface that defines objects that can be treated as a single sprites
type SpriteSeries ¶
type SpriteSeries struct { Sprites []SpriteInterface CyclesPerSecond int }
SpriteSeries is a type that defines a series of sprites that form an animation for a game object state