entities

package
v2.3.3-beta Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: Apache-2.0 Imports: 5 Imported by: 5

Documentation

Overview

Package entities stores useful object and entity types, such as positions and renderables, collision spaces and renderables, and delta / speed vectors built into the above types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doodad

type Doodad struct {
	Point
	event.CID
	R render.Renderable
}

A Doodad is an entity composed of a position, a renderable, and a CallerID.

func NewDoodad

func NewDoodad(x, y float64, r render.Renderable, cid event.CID) *Doodad

NewDoodad returns a new doodad that is not drawn but is initialized. Passing a CID of 0 will initialize the entity as a Doodad. Passing any other CID will assume that the struct containing this doodad has already been initialized to the passed in CID. This applies to ALL NewX functions in entities which take in a CID.

func (*Doodad) Destroy

func (d *Doodad) Destroy()

Destroy cleans up the events, renderable and entity mapping for this Doodad

func (*Doodad) GetID

func (d *Doodad) GetID() event.CID

GetID returns this Doodad's CID Consider: are these getters needed?

func (*Doodad) GetRenderable

func (d *Doodad) GetRenderable() render.Renderable

GetRenderable returns this Doodad's Renderable

func (*Doodad) Init

func (d *Doodad) Init() event.CID

Init satisfies event.Entity

func (*Doodad) SetPos

func (d *Doodad) SetPos(x, y float64)

SetPos both Sets logical position and renderable position The need for this sort of function is lessened with the introduction of vector attachement.

func (*Doodad) SetRenderable

func (d *Doodad) SetRenderable(r render.Renderable)

SetRenderable sets this Doodad's renderable, drawing it. Todo:this automatic drawing doesn't really work with our two tiers of draw layers

func (*Doodad) String

func (d *Doodad) String() string

type Interactive

type Interactive struct {
	Reactive
	// contains filtered or unexported fields
}

Interactive parallels Moving, but for Reactive instead of Solid

func NewInteractive

func NewInteractive(x, y, w, h float64, r render.Renderable, tree *collision.Tree,
	cid event.CID, friction float64) *Interactive

NewInteractive returns a new Interactive

func (*Interactive) ApplyFriction

func (v *Interactive) ApplyFriction(outsideFriction float64)

ApplyFriction modifies a moving's delta by combining environmental friction with the moving's base friction and scaling down the delta by the combined result.

func (Interactive) GetDelta

func (v Interactive) GetDelta() physics.Vector

GetDelta returns this moving's delta

func (Interactive) GetSpeed

func (v Interactive) GetSpeed() physics.Vector

GetSpeed returns this moving's speed

func (*Interactive) Init

func (iv *Interactive) Init() event.CID

Init satisfies event.Entity

type Moving

type Moving struct {
	Solid
	// contains filtered or unexported fields
}

A Moving is a Solid that also keeps track of a speed and a delta vector

func NewMoving

func NewMoving(x, y, w, h float64, r render.Renderable, tree *collision.Tree, cid event.CID, friction float64) *Moving

NewMoving returns a new Moving

func (*Moving) ApplyFriction

func (v *Moving) ApplyFriction(outsideFriction float64)

ApplyFriction modifies a moving's delta by combining environmental friction with the moving's base friction and scaling down the delta by the combined result.

func (Moving) GetDelta

func (v Moving) GetDelta() physics.Vector

GetDelta returns this moving's delta

func (Moving) GetSpeed

func (v Moving) GetSpeed() physics.Vector

GetSpeed returns this moving's speed

func (*Moving) Init

func (m *Moving) Init() event.CID

Init satisfies event.Entity

func (*Moving) ShiftVector

func (m *Moving) ShiftVector(v physics.Vector)

ShiftVector probably shouldn't be on moving but it lets you ShiftPos by a given vector

type Point

type Point struct {
	physics.Vector
}

A Point is a wrapper around a physics vector.

func NewPoint

func NewPoint(x, y float64) *Point

NewPoint returns a new point

func (*Point) DistanceTo

func (p *Point) DistanceTo(x, y float64) float64

DistanceTo returns the euclidean distance to (x,y)

func (*Point) DistanceToPoint

func (p *Point) DistanceToPoint(p2 Point) float64

DistanceToPoint returns the euclidean distance to p2.GetLogicPos()

func (*Point) GetLogicPos

func (p *Point) GetLogicPos() (float64, float64)

GetLogicPos returns the logical position of an entity. See SetLogicPos.

func (*Point) SetLogicPos

func (p *Point) SetLogicPos(x, y float64)

SetLogicPos is an explicit declaration for setting just the logical position of an entity. On a Point there is no distinction as there is nothing but the logical position but this is important for other entity types

func (*Point) ShiftLogicPos

func (p *Point) ShiftLogicPos(x, y float64)

ShiftLogicPos shifts a point's underlying position by both x and y

func (*Point) String

func (p *Point) String() string

type Reactive

type Reactive struct {
	Doodad
	W, H   float64
	RSpace *collision.ReactiveSpace
	Tree   *collision.Tree
}

Reactive is parallel to Solid, but has a Reactive collision space instead of a regular collision space

func NewReactive

func NewReactive(x, y, w, h float64, r render.Renderable, tree *collision.Tree, cid event.CID) *Reactive

NewReactive returns a new Reactive struct. The added space will be added to the input tree, or DefTree if none is given.

func (*Reactive) Destroy

func (r *Reactive) Destroy()

Destroy destroys this reactive's doodad component and removes its space from it's collision tree

func (*Reactive) GetLogicDim

func (r *Reactive) GetLogicDim() (float64, float64)

GetLogicDim returns this Reactive's width and height todo: move wh into their own struct to compose into solid and reactive

func (*Reactive) GetReactiveSpace

func (r *Reactive) GetReactiveSpace() *collision.ReactiveSpace

GetReactiveSpace returns this reactive's RSpace

func (*Reactive) GetSpace

func (r *Reactive) GetSpace() *collision.Space

GetSpace returns this reactive's space underlying its RSpace

func (*Reactive) Init

func (r *Reactive) Init() event.CID

Init satisfies event.Entity

func (*Reactive) SetDim

func (r *Reactive) SetDim(w, h float64)

SetDim sets the dimensions of this reactive's space and it's logical dimensions

func (*Reactive) SetLogicDim

func (r *Reactive) SetLogicDim(w, h float64)

SetLogicDim sets the logical width and height of this reactive without changing the real dimensions of its collision space

func (*Reactive) SetPos

func (r *Reactive) SetPos(x, y float64)

SetPos sets this reactive's logical, renderable, and collision position to be x,y

func (*Reactive) SetSpace

func (r *Reactive) SetSpace(sp *collision.ReactiveSpace)

SetSpace sets this reactive's collision space to the given reactive space, updating it's collision tree to include it.

func (*Reactive) ShiftPos

func (r *Reactive) ShiftPos(x, y float64)

ShiftPos acts like SetPos if given r.X()+x, r.Y()+y

func (*Reactive) String

func (r *Reactive) String() string

type Solid

type Solid struct {
	Doodad
	W, H  float64
	Space *collision.Space
	Tree  *collision.Tree
}

A Solid is a Doodad with a width, height, and collision space.

func NewSolid

func NewSolid(x, y, w, h float64, r render.Renderable, tree *collision.Tree, cid event.CID) *Solid

NewSolid returns an initialized Solid that is not drawn and whose space belongs to the given collision tree. If nil is given as the tree, it will belong to collision.DefTree

func (*Solid) Destroy

func (s *Solid) Destroy()

Destroy removes this solid's collision space from it's Tree and destroys the doodad portion of the solid.

func (*Solid) GetLogicDim

func (s *Solid) GetLogicDim() (float64, float64)

GetLogicDim will return the width and height of the Solid

func (*Solid) GetSpace

func (s *Solid) GetSpace() *collision.Space

GetSpace returns a solid's collision space

func (*Solid) HitLabel

func (s *Solid) HitLabel(classtype collision.Label) *collision.Space

HitLabel will return the first space that this solid collides with matching the given label that it finds, or nil if it finds nothing.

func (*Solid) Init

func (s *Solid) Init() event.CID

Init satisfies event.Entity

func (*Solid) SetDim

func (s *Solid) SetDim(w, h float64)

SetDim sets the logical dimensions of the solid and the real dimensions on the solid's space

func (*Solid) SetLogicDim

func (s *Solid) SetLogicDim(w, h float64)

SetLogicDim sets the width and height of the solid

func (*Solid) SetPos

func (s *Solid) SetPos(x float64, y float64)

SetPos sets the position of the collision space, the logical position, and the renderable position of the solid.

func (*Solid) SetSpace

func (s *Solid) SetSpace(sp *collision.Space)

SetSpace assigns a solid a collision space and puts it in this Solid's Tree

func (*Solid) ShiftPos

func (s *Solid) ShiftPos(x, y float64)

ShiftPos moves a solid by (x,y)

func (*Solid) ShiftSpace

func (s *Solid) ShiftSpace(x, y float64)

ShiftSpace will shift this solid's collision space by (x,y)

func (*Solid) ShiftX

func (s *Solid) ShiftX(x float64)

ShiftX moves a solid by x along the x axis

func (*Solid) ShiftY

func (s *Solid) ShiftY(y float64)

ShiftY moves a solid by y along the y axis

func (*Solid) String

func (s *Solid) String() string

func (*Solid) UpdateLabel

func (s *Solid) UpdateLabel(classtype collision.Label)

UpdateLabel will update it's label in this solid's collision tree.

Directories

Path Synopsis
x
btn

Jump to

Keyboard shortcuts

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