Documentation ¶
Index ¶
- func AreColliding(h1, h2 Hitbox) bool
- func Run(name string, w, h int, level LevelIface)
- type Game
- type Hitbox
- type Kinematics
- type Level
- type LevelIface
- type Object
- func (o *Object) Accelerate(v Vec)
- func (o *Object) AddChildren(children ...ObjectIface)
- func (rdr *Object) CopyTo(wrtr *Object)
- func (o *Object) Draw(drawContext *gg.Context)
- func (o *Object) GenID() error
- func (o *Object) GetAcc() Vec
- func (o *Object) GetChildren() []ObjectIface
- func (o *Object) GetID() ObjectID
- func (o *Object) GetKinematics() Kinematics
- func (o *Object) GetName() string
- func (o *Object) GetPos() Vec
- func (o1 *Object) GetPosOffset(o2 ObjectIface) Vec
- func (o *Object) GetVel() Vec
- func (o *Object) Init()
- func (o *Object) Move(v Vec)
- func (o *Object) ObjAddChildren(children ...ObjectIface)
- func (o *Object) ObjDrawPos(dc *gg.Context, at Vec)
- func (o *Object) ObjGenID() error
- func (o *Object) ObjGetAcc() Vec
- func (o *Object) ObjGetChildren() []ObjectIface
- func (o *Object) ObjGetID() ObjectID
- func (o *Object) ObjGetKinematics() Kinematics
- func (o *Object) ObjGetName() string
- func (o *Object) ObjGetPos() Vec
- func (o *Object) ObjGetVel() Vec
- func (o *Object) ObjInit()
- func (o *Object) ObjRemoveChildren(children ...ObjectIface)
- func (o *Object) ObjSetAcc(acc Vec)
- func (o *Object) ObjSetChildren(children []ObjectIface)
- func (o *Object) ObjSetKinematics(lk Kinematics)
- func (o *Object) ObjSetPos(pos Vec)
- func (o *Object) ObjSetVel(vel Vec)
- func (o *Object) ObjUpdate() error
- func (o *Object) RemoveChildren(children ...ObjectIface)
- func (o *Object) SetAcc(acc Vec)
- func (o *Object) SetChildren(children []ObjectIface)
- func (o *Object) SetKinematics(lk Kinematics)
- func (o *Object) SetPos(pos Vec)
- func (o *Object) SetVel(vel Vec)
- func (o *Object) Update() error
- func (o *Object) UpdateKinematics()
- func (o *Object) UpdatePos()
- func (o *Object) UpdateVel()
- type ObjectID
- type ObjectIface
- type Vec
- func (v1 Vec) Add(v2 Vec) Vec
- func (v Vec) RotateXY180() Vec
- func (v Vec) RotateXY180Around(r Vec) Vec
- func (v Vec) RotateXY270() Vec
- func (v Vec) RotateXY270Around(r Vec) Vec
- func (v Vec) RotateXY90() Vec
- func (v Vec) RotateXY90Around(r Vec) Vec
- func (v Vec) Scale(a float64) Vec
- func (v1 Vec) Subtract(v2 Vec) Vec
- func (v Vec) Thousandths() Vec
- func (v Vec) ToInt() (int, int, int)
- func (v Vec) ToInt64() (int64, int64, int64)
- func (v Vec) ToString() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AreColliding ¶
Return true if two hitboxes are currently colliding where colliding means either they overlap or their surfaces are touching
func Run ¶
func Run(name string, w, h int, level LevelIface)
Types ¶
type Kinematics ¶
type Level ¶
type Level struct {
Object
}
func (*Level) ChildrenByZ ¶
func (l *Level) ChildrenByZ() []ObjectIface
type LevelIface ¶
type LevelIface interface { ChildrenByZ() []ObjectIface Draw(drawContext *gg.Context) Update() error }
type Object ¶
type Object struct { Name string ID ObjectID LK Kinematics // Structure for linear kinematics (angular kinematics may be added later) HB Hitbox UpdateFunc func() error Children map[ObjectID]ObjectIface // If this object contains any children, they go in this map }
***************************************
- Functions implementing the interface * **************************************
Generic object implementing the ObjectIface interface
func NewObjAtPos ¶
func (*Object) Accelerate ¶
Adjust the object's velocity according to the given vector v
func (*Object) AddChildren ¶
func (o *Object) AddChildren(children ...ObjectIface)
func (*Object) GetChildren ¶
func (o *Object) GetChildren() []ObjectIface
func (*Object) GetKinematics ¶
func (o *Object) GetKinematics() Kinematics
func (*Object) GetPosOffset ¶
func (o1 *Object) GetPosOffset(o2 ObjectIface) Vec
Get the offset position vector of o1 as compared to o2
func (*Object) ObjAddChildren ¶
func (o *Object) ObjAddChildren(children ...ObjectIface)
func (*Object) ObjGetKinematics ¶
func (o *Object) ObjGetKinematics() Kinematics
func (*Object) ObjGetName ¶
func (*Object) ObjRemoveChildren ¶
func (o *Object) ObjRemoveChildren(children ...ObjectIface)
func (*Object) ObjSetChildren ¶
func (o *Object) ObjSetChildren(children []ObjectIface)
func (*Object) ObjSetKinematics ¶
func (o *Object) ObjSetKinematics(lk Kinematics)
func (*Object) ObjSetPos ¶
Set the position of the object and the relative position of all child objects
func (*Object) RemoveChildren ¶
func (o *Object) RemoveChildren(children ...ObjectIface)
func (*Object) SetChildren ¶
func (o *Object) SetChildren(children []ObjectIface)
func (*Object) SetKinematics ¶
func (o *Object) SetKinematics(lk Kinematics)
func (*Object) UpdateKinematics ¶
func (o *Object) UpdateKinematics()
Convenience function update velocity from acceleration and position from velocity
type ObjectIface ¶
type ObjectIface interface { // Accounting functions Init() GetName() string GetID() ObjectID GenID() error // Movement Functions (position, velocity, acceleration) GetPos() Vec SetPos(Vec) Move(Vec) GetPosOffset(ObjectIface) Vec GetVel() Vec SetVel(Vec) GetAcc() Vec SetAcc(Vec) GetKinematics() Kinematics SetKinematics(Kinematics) // Child functions GetChildren() []ObjectIface SetChildren([]ObjectIface) AddChildren(...ObjectIface) RemoveChildren(...ObjectIface) // Game loop functions Update() error Draw(drawContext *gg.Context) }
type Vec ¶
type Vec struct {
X, Y, Z float64
}
These coordinates are restricted based on a 2D representation. The reference coordinate 0, 0, 0 is at the top left corner of the screen. X has positive going to the right. Y has positive going down. Z functions as depth, and has positive going out of the screen toward the player
func (Vec) RotateXY180 ¶
Uses a vector rotate trick to rotate the 2D vector of just X and Y around 0, 0.
func (Vec) RotateXY180Around ¶
func (Vec) RotateXY270 ¶
Uses a vector rotate trick to rotate the 2D vector of just X and Y around 0, 0.
func (Vec) RotateXY270Around ¶
func (Vec) RotateXY90 ¶
Uses a vector rotate trick to rotate the 2D vector of just X and Y around 0, 0.
func (Vec) RotateXY90Around ¶
func (Vec) Thousandths ¶
Round each dimension to the nearest 1000th to avoid arithmetic errors with floating points from propagating