Documentation
¶
Index ¶
- Constants
- func NewTimer(seconds float64, trigger TimerTrigger) *timer
- func SetDefaultFont(font string, fontSize float64, textColor string)
- type AspectRatio
- type AspectRatioControlAxis
- type Dimensions
- type Engine
- type Entity
- type EntityGroup
- func (this *EntityGroup) AddEntity(layer int, ent interface{}) string
- func (this *EntityGroup) AddNamedEntity(name string, layer int, ent interface{})
- func (this *EntityGroup) ClearEntities()
- func (this *EntityGroup) GetEntity(layer int, name string) interface{}
- func (this *EntityGroup) GetEntityGroupEntity() *Entity
- func (this *EntityGroup) IterateEntities(cb func(interface{}))
- func (this *EntityGroup) RemoveEntity(layer int, name string)
- func (this *EntityGroup) Render(engine *Engine)
- func (this *EntityGroup) Update(engine *Engine)
- type IEntity
- type IEntityCollider
- type IEntityCollisionDetection
- type IEntityConstrainedHandler
- type IEntityConstraint
- type IEntityRenderer
- type IEntityUpdater
- type IFPSUpdateHandler
- type IKeyChar
- type IKeyDown
- type IKeyUp
- type IMouseDown
- type IMouseMove
- type IMouseUp
- type ISceneInitializer
- type IScenePreRenderer
- type ISceneRenderer
- type ISceneUpdater
- type ITPSUpdateHandler
- type ITexture
- type ImageEntity
- type LineCapStyle
- type LineEntity
- type Rect
- type RectSide
- type Scene
- func (this *Scene) AddTimer(name string, t *timer)
- func (this *Scene) ClearResources()
- func (this *Scene) GetResource(name string) interface{}
- func (this *Scene) RemoveTimer(name string)
- func (this *Scene) RenderStats(font string, size float64, color string)
- func (this *Scene) SetResource(name string, res interface{})
- func (this *Scene) StopRenderingStats()
- type SpriteSheet
- type TextCentering
- type TextEntity
- func (this *TextEntity) GetEntity() *Entity
- func (this *TextEntity) Measure(e *Engine)
- func (this *TextEntity) Render(e *Engine)
- func (this *TextEntity) SetCenteredIn(r Rect)
- func (this *TextEntity) SetCentering(c TextCentering)
- func (this *TextEntity) SetFont(font string)
- func (this *TextEntity) SetFontSize(fontSize float64)
- func (this *TextEntity) SetText(text string)
- func (this *TextEntity) SetTextColor(color string)
- func (this *TextEntity) Update(e *Engine)
- type TimerTrigger
- type Vector
- func (this *Vector) AngleTo(other Vector) float64
- func (this *Vector) ConstrainTo(r Rect)
- func (this Vector) Constrained(r Rect) Vector
- func (this *Vector) Copy() Vector
- func (this *Vector) DirectionTo(other Vector) Vector
- func (this *Vector) DistanceTo(other Vector) float64
- func (this Vector) Equals(other Vector) bool
- func (this Vector) Inverted() Vector
- func (this Vector) InvertedX() Vector
- func (this Vector) InvertedY() Vector
- func (this Vector) IsAbove(v Vector) bool
- func (this Vector) IsBelow(v Vector) bool
- func (this Vector) IsInsideOf(r Rect) bool
- func (this Vector) IsLeftOf(v Vector) bool
- func (this Vector) IsRightOf(v Vector) bool
- func (this Vector) IsZero() bool
- type VelocityVector
Constants ¶
const ( AspectRatioControlAxisWidth = iota AspectRatioControlAxisHeight )
const ( MOUSE_BUTTON_LEFT = 1 MOUSE_BUTTON_MIDDLE = 2 MOUSE_BUTTON_RIGHT = 3 MOUSE_BUTTON_X1 = 4 MOUSE_BUTTON_X2 = 5 )
const ( LINECAP_MITER = iota LINECAP_BEVEL LINECAP_ROUND LINECAP_SQUARE LINECAP_BUTT )
const ( TEXT_CENTERING_NONE = iota TEXT_CENTERING_VERTICAL TEXT_CENTERING_HORIZONTAL )
const ( RectSideLeft = iota RectSideRight RectSideTop RectSideBottom )
const TICK_DURATION = time.Duration(0)
TICK_DURATION is intended to be used as the duration for a VelocityVector that should move the given amount in one tick.
Variables ¶
This section is empty.
Functions ¶
func NewTimer ¶
func NewTimer(seconds float64, trigger TimerTrigger) *timer
NewTimer creates a new timer that will trigger the given TimerTrigger every given seconds.
func SetDefaultFont ¶
SetDefaultFont sets the default font, font size, and text color for all text entities created with NewTextEntitySimple.
Types ¶
type AspectRatio ¶
type AspectRatio struct { Dimensions ControlAxis AspectRatioControlAxis }
AspectRatio is a simple aspect ratio implementation.
func NewAspectRatio ¶
func NewAspectRatio(w float64, h float64, c AspectRatioControlAxis) *AspectRatio
NewAspectRatio creates a new aspect ratio with the given width, height, and control axis.
func (*AspectRatio) NewDimensions ¶
func (this *AspectRatio) NewDimensions(v float64) Dimensions
NewDimensions returns a new Dimensions struct that is the result of applying this aspect ratio to the given value on the control axis.
type AspectRatioControlAxis ¶
type AspectRatioControlAxis int
AspectRatioControlAxis is an enum that defines which axis of an aspect ratio should be in control when calculating new dimensions.
type Dimensions ¶
Dimensions is a simple struct that represents the width and height of an object.
func NewSquareDimensions ¶
func NewSquareDimensions(size float64) Dimensions
NewSquareDimensions creates a new Dimensions struct with equal width and height.
func NewZeroDimensions ¶
func NewZeroDimensions() Dimensions
NewZeroDimensions creates a new Dimensions struct with zero width and height.
func (*Dimensions) Plus ¶
func (this *Dimensions) Plus(other Dimensions) Dimensions
Plus returns a new Dimensions struct that is the sum of this Dimensions struct and the given Dimensions struct.
func (*Dimensions) PlusHeight ¶
func (this *Dimensions) PlusHeight(height float64) Dimensions
PlusHeight returns a new Dimensions struct that is the sum of this Dimensions struct and the given height.
func (*Dimensions) PlusWidth ¶
func (this *Dimensions) PlusWidth(width float64) Dimensions
PlusWidth returns a new Dimensions struct that is the sum of this Dimensions struct and the given width.
type Engine ¶
type Engine struct { // Name is the name of the game window. Name string // Dimensions is the dimensions of the game window. Dimensions Dimensions // FPSUpdateHandler is the handler for when the FPS is updated. FPSUpdateHandler IFPSUpdateHandler // TPSUpdateHandler is the handler for when the TPS is updated. TPSUpdateHandler ITPSUpdateHandler // Canvas is the canvas that is used to render the game. Canvas *canvas.Canvas // HideCursor is a flag that determines if the cursor should be hidden. HideCursor bool // MaxTPS is the maximum TPS that the game should run at. MaxTPS int // contains filtered or unexported fields }
Engine is the main engine that handles the game loop and rendering.
func GetActiveEngines ¶
func GetActiveEngines() []*Engine
GetActiveEngines returns all active engines.
func NewEngine ¶
func NewEngine(name string, dimensions Dimensions) *Engine
NewEngine creates a new engine with the given name and dimensions.
type Entity ¶
type Entity struct { // Visible is a flag that can be used to hide the entity. Visible bool // Bounds is the rectangle that defines the entity's position and size. Bounds Rect // Velocity is the entity's velocity. Velocity VelocityVector }
Entity is a basic entity that can be used to create more complex entities.
func (*Entity) CollidesWith ¶
CollidesWith returns true if the entity collides with the other entity. This is not using IEntityCollider and IEntityCollisionDetection, but rather directly checks the entity's bounds.
type EntityGroup ¶
type EntityGroup struct { Entity // contains filtered or unexported fields }
EntityGroup is an entity that represents a group of entities that can be rendered in layers.
func (*EntityGroup) AddEntity ¶
func (this *EntityGroup) AddEntity(layer int, ent interface{}) string
AddEntity adds an entity to the group.
func (*EntityGroup) AddNamedEntity ¶
func (this *EntityGroup) AddNamedEntity(name string, layer int, ent interface{})
AddNamedEntity adds an entity to the group with the given name.
func (*EntityGroup) ClearEntities ¶
func (this *EntityGroup) ClearEntities()
ClearEntities clears all entities from the group.
func (*EntityGroup) GetEntity ¶
func (this *EntityGroup) GetEntity(layer int, name string) interface{}
GetEntity gets an entity from the group.
func (*EntityGroup) GetEntityGroupEntity ¶
func (this *EntityGroup) GetEntityGroupEntity() *Entity
GetEntityGroupEntity returns the entity group entity.
func (*EntityGroup) IterateEntities ¶
func (this *EntityGroup) IterateEntities(cb func(interface{}))
IterateEntities iterates over all entities in the group.
func (*EntityGroup) RemoveEntity ¶
func (this *EntityGroup) RemoveEntity(layer int, name string)
RemoveEntity removes an entity from the group.
func (*EntityGroup) Render ¶
func (this *EntityGroup) Render(engine *Engine)
Render renders the entity group.
func (*EntityGroup) Update ¶
func (this *EntityGroup) Update(engine *Engine)
Update updates the entity group.
type IEntityCollider ¶
type IEntityCollider interface {
GetCollider() Rect
}
IEntityCollider is an interface that can be implemented by entities that want to be recognized by other entities with that implement IEntityCollisionDetection.
type IEntityCollisionDetection ¶
type IEntityCollisionDetection interface {
CollidedWith(other interface{})
}
IEntityCollisionDetection is an interface that can be implemented by entities that want to be notified when they collide with other entities that implement IEntityCollider.
type IEntityConstrainedHandler ¶
type IEntityConstrainedHandler interface {
OnConstrained(s RectSide)
}
IEntityConstrainedHandler is an interface that can be implemented by entities that want to be notified when they are constrained.
type IEntityConstraint ¶
IEntityConstraint is an interface that can be implemented by entities that want to constrain themselves.
type IEntityRenderer ¶
type IEntityRenderer interface {
Render(c *Engine)
}
IEntityRenderer is an interface that can be implemented by entities that want to render themselves.
type IEntityUpdater ¶
type IEntityUpdater interface {
Update(e *Engine)
}
IEntityUpdater is an interface that can be implemented by entities that want to update themselves.
type IFPSUpdateHandler ¶
type IMouseDown ¶
type IMouseMove ¶
type IMouseMove interface {
MouseMove(pos Vector)
}
type ISceneInitializer ¶
type IScenePreRenderer ¶
type ISceneRenderer ¶
type ISceneUpdater ¶
type ITPSUpdateHandler ¶
type ImageEntity ¶
type ImageEntity struct { Entity // contains filtered or unexported fields }
ImageEntity is a simple image entity that can be used to draw images on the screen.
func LoadImageEntity ¶
func LoadImageEntity(path string) (*ImageEntity, error)
LoadImageEntity loads an image entity from the given path.
func NewCircleImageEntity ¶
func NewCircleImageEntity(color string, radius int) *ImageEntity
NewCircleImageEntity creates a new image entity depicting a circle with the given color and radius.
func NewImageEntity ¶
func NewImageEntity(img image.Image) *ImageEntity
NewImageEntity creates a new image entity from the given image.
func NewRectImageEntity ¶
func NewRectImageEntity(color string, dimensions Dimensions) *ImageEntity
NewRectImageEntity creates a new image entity with the given color and dimensions.
func (*ImageEntity) GetEntity ¶
func (this *ImageEntity) GetEntity() *Entity
GetEntity returns the entity of the image entity.
func (*ImageEntity) GetImage ¶
func (this *ImageEntity) GetImage() image.Image
GetImage returns the image of the image entity.
func (*ImageEntity) Render ¶
func (this *ImageEntity) Render(e *Engine)
Render renders the image entity.
func (*ImageEntity) Update ¶
func (this *ImageEntity) Update(e *Engine)
Update updates the image entity.
type LineCapStyle ¶
type LineCapStyle uint8
LienCapStyle is a type that represents the different line cap styles
type LineEntity ¶
type LineEntity struct { Entity // contains filtered or unexported fields }
LineEntity is a simple line entity that can be used to draw lines on the screen.
func NewLineEntity ¶
func NewLineEntity(from Vector, direction Vector, length float64, thickness int, color string) *LineEntity
NewLineEntity creates a new line entity with the given from vector, direction vector, length, thickness, and color.
func NewLineEntitySimple ¶
func NewLineEntitySimple(from Vector, to Vector, thickness int, color string) *LineEntity
NewLineEntitySimple creates a new line entity with the given from and to vectors, thickness, and color.
func (*LineEntity) GetEntity ¶
func (this *LineEntity) GetEntity() *Entity
GetEntity returns the entity of the line entity.
func (*LineEntity) Render ¶
func (this *LineEntity) Render(e *Engine)
Render renders the line entity.
func (*LineEntity) SetCapStyle ¶
func (this *LineEntity) SetCapStyle(capStyle LineCapStyle)
SetCapStyle sets the cap style of the line.
func (*LineEntity) Update ¶
func (this *LineEntity) Update(e *Engine)
Update updates the line entity.
type Rect ¶
type Rect struct { Vector Dimensions }
Rect is a simple rectangle implementation.
func NewRect ¶
NewRect creates a new rectangle with the given width and height at the given position.
func NewZeroRect ¶
NewZeroRect creates a new rectangle with the given width and height at the origin.
func (*Rect) Constrain ¶
Constrain constrains this rectangle to the given rectangle. If this rectangle is outside of the given rectangle, it will be moved to the closest point on the rectangle. The return value is a slice of the sides that were constrained.
func (Rect) Contains ¶
Contains returns true if the given vector is contained within this rectangle.
func (Rect) IntersectsWith ¶
IntersectsWith returns true if this rectangle intersects with the given rectangle.
type Scene ¶
type Scene struct { *EntityGroup // Name is the name of the scene. Name string // Initializer is the initializer that will be called when the scene is initialized. Initializer ISceneInitializer // PreRenderer is the pre-renderer that will be called before the scene is rendered. PreRenderer IScenePreRenderer // Renderer is the renderer that will be called when the scene is rendered. Renderer ISceneRenderer // Updater is the updater that will be called when the scene is updated. Updater ISceneUpdater // contains filtered or unexported fields }
Scene is a simple scene implementation.
func GetActiveScene ¶
func GetActiveScene() *Scene
GetActiveScene returns the active scene. If no scene is active, nil is returned. If you are using multiple scenes, you should use GetActiveScenes() otherwise you will get a panic.
func (*Scene) ClearResources ¶
func (this *Scene) ClearResources()
ClearResources clears all resources.
func (*Scene) GetResource ¶
GetResource returns a resource by name.
func (*Scene) RemoveTimer ¶
RemoveTimer removes a timer from the scene.
func (*Scene) RenderStats ¶
RenderStats will enable rendering of the FPS and TPS in the top left corner of the screen. The font, size and color can be specified. The stats will be rendered on top of everything else.
func (*Scene) SetResource ¶
SetResource sets a resource by name.
func (*Scene) StopRenderingStats ¶
func (this *Scene) StopRenderingStats()
StopRenderingStats will stop rendering the FPS and TPS.
type SpriteSheet ¶
type SpriteSheet struct { // RowSize is the size of each row in the sprite sheet. RowSize int // ColumnSize is the size of each column in the sprite sheet. ColumnSize int // contains filtered or unexported fields }
SpriteSheet is a simple sprite sheet implementation.
func NewSpriteSheet ¶
func NewSpriteSheet(path string, columnSize int, rowSize int) (*SpriteSheet, error)
NewSpriteSheet creates a new sprite sheet from the given image path with the given column and row size.
type TextCentering ¶
type TextCentering int
TextCentering is a type that represents the different ways text can be centered.
type TextEntity ¶
type TextEntity struct { Entity // contains filtered or unexported fields }
TextEntity is a simple text entity that can be used to display text on the screen.
func NewTextEntity ¶
func NewTextEntity(text string, font string, fontSize float64, textColor string) *TextEntity
NewTextEntity creates a new text entity with the given text, font, font size, and text color.
func NewTextEntitySimple ¶
func NewTextEntitySimple(text string) *TextEntity
NewTextEntitySimple creates a new text entity with the given text, using the default font, font size, and text color.
func (*TextEntity) GetEntity ¶
func (this *TextEntity) GetEntity() *Entity
GetEntity returns the base entity of this text entity.
func (*TextEntity) Measure ¶
func (this *TextEntity) Measure(e *Engine)
Measure updates the bounds of this text entity based on the text, font, and font size also taking into account the centering of the text.
func (*TextEntity) Render ¶
func (this *TextEntity) Render(e *Engine)
Render renders this text entity to the given engine.
func (*TextEntity) SetCenteredIn ¶
func (this *TextEntity) SetCenteredIn(r Rect)
SetCenteredIn sets the rectangle that this text entity should be centered in.
func (*TextEntity) SetCentering ¶
func (this *TextEntity) SetCentering(c TextCentering)
SetCentering sets the centering of this text entity.
func (*TextEntity) SetFont ¶
func (this *TextEntity) SetFont(font string)
SetFont sets the font of this text entity.
func (*TextEntity) SetFontSize ¶
func (this *TextEntity) SetFontSize(fontSize float64)
SetFontSize sets the font size of this text entity.
func (*TextEntity) SetText ¶
func (this *TextEntity) SetText(text string)
SetText sets the text of this text entity.
func (*TextEntity) SetTextColor ¶
func (this *TextEntity) SetTextColor(color string)
SetTextColor sets the text color of this text entity.
func (*TextEntity) Update ¶
func (this *TextEntity) Update(e *Engine)
Update updates this text entity.
type TimerTrigger ¶
type TimerTrigger interface {
OnTriggered(owner interface{})
}
type Vector ¶
Vector is a 2D vector with an X and Y component.
func DirectionDown ¶
func DirectionDown() Vector
DirectionDown returns a Vector with a y component of 1.
func DirectionLeft ¶
func DirectionLeft() Vector
DirectionLeft returns a Vector with an x component of -1.
func DirectionRight ¶
func DirectionRight() Vector
DirectionRight returns a Vector with an x component of 1.
func NewRandomVector ¶
NewRandomVector creates a new Vector with random x and y components within the given maximum.
func NewRandomVectorWithin ¶
NewRandomVectorWithin creates a new Vector with random x and y components within the given rectangle.
func NewZeroVector ¶
func NewZeroVector() Vector
NewZeroVector creates a new Vector with x and y components of 0.
func (*Vector) ConstrainTo ¶
ConstrainTo constrains this vector to the given rectangle. If the vector is outside of the rectangle, it will be moved to the closest point on the rectangle.
func (Vector) Constrained ¶
Constrained returns a copy of this vector constrained to the given rectangle. If the vector is outside of the rectangle, it will be moved to the closest point on the rectangle.
func (*Vector) DirectionTo ¶
DirectionTo returns a Vector that points from this vector to the given vector.
func (*Vector) DistanceTo ¶
DistanceTo returns the distance between this vector and the given vector.
func (Vector) Inverted ¶
Inverted returns a copy of this vector with its x and y components inverted.
func (Vector) IsInsideOf ¶
IsInsideOf returns true if this vector is inside of the given rectangle.
type VelocityVector ¶
VelocityVector is a vector that has a duration. The duration is the amount of time it should take for the vector to move from one point to another. If the duration is 0, then the vector will move the given amount in one tick.
func NewVelocityVector ¶
func NewVelocityVector(x, y float64, d time.Duration) VelocityVector
NewVelocityVector creates a new VelocityVector with the given x and y components and duration. The duration is the amount of time it should take for the vector to move from one point to another. If the duration is 0, then the vector will move the given amount in one tick.
func (VelocityVector) GetNextMovement ¶
func (this VelocityVector) GetNextMovement() Vector
GetNextMovement returns the next movement that should be applied to the vector. This is used to calculate the next movement of the vector based on the duration. If the duration is 0, then the vector will move the given amount in one tick.