Documentation ¶
Index ¶
- func Init(spaceWidth, spaceHeight, cellWidth, cellHeight int)
- type Cell
- type Circle
- func (circle *Circle) Bounds() (vector2.Vector, vector2.Vector)
- func (circle *Circle) Clone() IShape
- func (circle *Circle) Intersection(dx, dy float64, other IShape) *ContactSet
- func (c *Circle) IntersectionForEach(dx, dy float64, f func(c *ContactSet) bool, others ...IShape)
- func (circle *Circle) IntersectionPointsCircle(other *Circle) []vector2.Vector
- func (circle *Circle) Move(x, y float64)
- func (circle *Circle) MoveVec(vec vector2.Vector)
- func (circle *Circle) PointInside(point vector2.Vector) bool
- func (circle *Circle) Position() vector2.Vector
- func (circle *Circle) Radius() float64
- func (circle *Circle) Rotate(radians float64)
- func (circle *Circle) Rotation() float64
- func (circle *Circle) Scale() vector2.Vector
- func (circle *Circle) SetPosition(x, y float64)
- func (circle *Circle) SetPositionVec(vec vector2.Vector)
- func (circle *Circle) SetRadius(radius float64)
- func (circle *Circle) SetRotation(rotation float64)
- func (circle *Circle) SetScale(w, h float64)
- func (circle *Circle) SetScaleVec(scale vector2.Vector)
- type Collider
- func (col *Collider) AddTags(tags ...string)
- func (col *Collider) AddToIgnoreList(ignoreObj *Collider)
- func (col *Collider) Bottom() float64
- func (col *Collider) BoundsToSpace(dx, dy float64) (int, int, int, int)
- func (col *Collider) CellPosition() (int, int)
- func (col *Collider) Center() vector2.Vector
- func (col *Collider) Check(dx, dy float64, tags ...string) *Inspector
- func (col *Collider) Clone() *Collider
- func (col *Collider) Destruction()
- func (col *Collider) HasTags(tags ...string) bool
- func (col *Collider) Move(move vector2.Vector)
- func (col *Collider) Overlaps(other *Collider) bool
- func (col *Collider) RemoveFromIgnoreList(ignoreObj *Collider)
- func (col *Collider) RemoveTags(tags ...string)
- func (col *Collider) Right() float64
- func (col *Collider) SetBottom(y float64)
- func (col *Collider) SetBounds(topLeft, bottomRight vector2.Vector)
- func (col *Collider) SetCenter(x, y float64)
- func (col *Collider) SetCenterVec(pos vector2.Vector)
- func (col *Collider) SetRight(x float64)
- func (col *Collider) SetShape(shape IShape)
- func (col *Collider) SharesCells(other *Collider) bool
- func (col *Collider) SharesCellsTags(tags ...string) bool
- func (col *Collider) Tags() []string
- func (col *Collider) Update()
- type ContactSet
- type ConvexPolygon
- func (cp *ConvexPolygon) AddPoints(vertexPositions ...float64)
- func (cp *ConvexPolygon) AddPointsVec(points ...vector2.Vector)
- func (cp *ConvexPolygon) Bounds() (vector2.Vector, vector2.Vector)
- func (cp *ConvexPolygon) Center() vector2.Vector
- func (cp *ConvexPolygon) Clone() IShape
- func (cp *ConvexPolygon) ContainedBy(otherShape IShape) bool
- func (cp *ConvexPolygon) FlipH()
- func (cp *ConvexPolygon) FlipV()
- func (cp *ConvexPolygon) Intersection(dx, dy float64, other IShape) *ContactSet
- func (p *ConvexPolygon) IntersectionForEach(dx, dy float64, f func(c *ContactSet) bool, others ...IShape)
- func (cp *ConvexPolygon) Lines() []*collidingLine
- func (cp *ConvexPolygon) Move(x, y float64)
- func (cp *ConvexPolygon) MoveVec(vec vector2.Vector)
- func (polygon *ConvexPolygon) PointInside(point vector2.Vector) bool
- func (cp *ConvexPolygon) Position() vector2.Vector
- func (cp *ConvexPolygon) Project(axis vector2.Vector) Projection
- func (cp *ConvexPolygon) RecenterPoints()
- func (cp *ConvexPolygon) ReverseVertexOrder()
- func (polygon *ConvexPolygon) Rotate(radians float64)
- func (polygon *ConvexPolygon) Rotation() float64
- func (cp *ConvexPolygon) SATAxes() []vector2.Vector
- func (polygon *ConvexPolygon) Scale() vector2.Vector
- func (cp *ConvexPolygon) SetPosition(x, y float64)
- func (cp *ConvexPolygon) SetPositionVec(vec vector2.Vector)
- func (polygon *ConvexPolygon) SetRotation(radians float64)
- func (polygon *ConvexPolygon) SetScale(x, y float64)
- func (polygon *ConvexPolygon) SetScaleVec(vec vector2.Vector)
- func (cp *ConvexPolygon) Transformed() []vector2.Vector
- type IShape
- type Inspector
- func (cc *Inspector) CollidersByTags(tags ...string) []*Collider
- func (cc *Inspector) ContactWithCell(cell *Cell) vector2.Vector
- func (cc *Inspector) ContactWithCollider(collider *Collider) vector2.Vector
- func (cc *Inspector) HasTags(tags ...string) bool
- func (cc *Inspector) SlideAgainstCell(cell *Cell, avoidTags ...string) (vector2.Vector, bool)
- type Projection
- type Space
- func (sp *Space) Add(colliders ...*Collider)
- func (sp *Space) Cell(x, y int) *Cell
- func (sp *Space) CellsInLine(startX, startY, endX, endY int) []*Cell
- func (sp *Space) CheckCells(x, y, w, h int, tags ...string) []*Collider
- func (sp *Space) CheckWorld(x, y, w, h float64, tags ...string) []*Collider
- func (sp *Space) CheckWorldVec(pos, size vector2.Vector, tags ...string) []*Collider
- func (sp *Space) Colliders() []*Collider
- func (sp *Space) Height() int
- func (sp *Space) Remove(colliders ...*Collider)
- func (sp *Space) Resize(width, height int)
- func (sp *Space) SpaceToWorld(x, y int) (float64, float64)
- func (sp *Space) SpaceToWorldVec(x, y int) vector2.Vector
- func (sp *Space) UnregisterAllColliders()
- func (sp *Space) Width() int
- func (sp *Space) WorldToSpace(x, y float64) (int, int)
- func (sp *Space) WorldToSpaceVec(position vector2.Vector) (int, int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(spaceWidth, spaceHeight, cellWidth, cellHeight int)
spaceWidth and spaceHeight is the width and height of the Space (usually in pixels), which is then populated with cells of size cellWidth by cellHeight. Generally, you want cells to be the size of the smallest collide-able colliders in your game, and you want to move Colliders at a maximum speed of one cell size per inspector check to avoid missing any possible inspectors.
Types ¶
type Cell ¶
type Cell struct {
X, Y int // The X and Y position of the cell in the Space - note that this is in Grid position, not World position.
Colliders []*Collider // The Colliders that a Cell contains.
}
Cell is used to contain and organize Collider information.
func (*Cell) Contains ¶
Contains returns whether a Cell contains the specified Collider at its position.
func (*Cell) ContainsTags ¶
ContainsTags returns whether a Cell contains an Collider that has the specified tag at its position.
type Circle ¶
type Circle struct {
// contains filtered or unexported fields
}
func NewCircle ¶
NewCircle returns a new Circle, with its center at the X and Y position given, and with the defined radius.
func (*Circle) Intersection ¶
func (circle *Circle) Intersection(dx, dy float64, other IShape) *ContactSet
Intersection tests to see if a Circle intersects with the other given Shape. dx and dy are delta movement variables indicating movement to be applied before the intersection check (thereby allowing you to see if a Shape would collide with another if it were in a different relative location). If an Intersection is found, a ContactSet will be returned, giving information regarding the intersection.
func (*Circle) IntersectionForEach ¶
func (c *Circle) IntersectionForEach(dx, dy float64, f func(c *ContactSet) bool, others ...IShape)
IntersectionForEach runs a specified function for each contact set caused by contact with any of the shapes passed. If the custom function returns false, then the intersection testing stops iterating through further colliders.
func (*Circle) IntersectionPointsCircle ¶
IntersectionPointsCircle returns the intersection points of the two circles provided.
func (*Circle) PointInside ¶
PointInside returns if the given vector2.Vector is inside of the circle.
func (*Circle) Rotate ¶
Circles can't rotate, of course. This function is just a stub to make them acceptable as IShapes.
func (*Circle) Rotation ¶
Circles can't rotate, of course. This function is just a stub to make them acceptable as IShapes.
func (*Circle) Scale ¶
Scale returns the scale multiplier of the Circle, twice; this is to have it adhere to the Shape interface.
func (*Circle) SetPosition ¶
SetPosition sets the center position of the Circle using the X and Y values given.
func (*Circle) SetPositionVec ¶
SetPosition sets the center position of the Circle using the vector2.Vector given.
func (*Circle) SetRadius ¶
SetRadius sets the radius of the Circle, updating the scale multiplier to reflect this change.
func (*Circle) SetRotation ¶
Circles can't rotate, of course. This function is just a stub to make them acceptable as IShapes.
func (*Circle) SetScale ¶
SetScale sets the scale multiplier of the Circle (this is W and H to have it adhere to IShape as a contract; in truth, the Circle's radius will be set to 0.5 * the maximum out of the width and height height values given).
func (*Circle) SetScaleVec ¶
SetScaleVec sets the scale multiplier of the Circle (this is W and H to have it adhere to IShape as a contract; in truth, the Circle's radius will be set to 0.5 * the maximum out of the width and height height values given).
type Collider ¶
type Collider struct { Shape IShape // A shape for more specific inspector-checking. Space *Space // Reference to the Space the Collider exists within Position vector2.Vector // The position of the Collider in the Space Size vector2.Vector // The size of the Collider in the Space TouchingCells []*Cell // An array of Cells the Collider is touching Data interface{} // A pointer to a user-definable collider // contains filtered or unexported fields }
Collider represents an collider that can be spread across one or more Cells in a Space. An Collider is essentially an AABB (Axis-Aligned Bounding Box) Rectangle.
func NewCollider ¶
NewCollider returns a new Collider of the specified position and size.
func RandNewCollider ¶
RandNewCollider returns a new Collider of the
func (*Collider) AddToIgnoreList ¶
AddToIgnoreList adds the specified Collider to the Collider's internal inspector ignoral list. Cells that contain the specified Collider will not be counted when calling Check().
func (*Collider) Bottom ¶
Bottom returns the bottom Y coordinate of the Collider (i.e. col.Y + col.H).
func (*Collider) BoundsToSpace ¶
BoundsToSpace returns the Space coordinates of the shape (x, y, w, and h), given its world position and size, and a supposed movement of dx and dy.
func (*Collider) CellPosition ¶
CellPosition returns the cellular position of the Collider's center in the Space.
func (*Collider) Check ¶
Check checks the space around the collider using the designated delta movement (dx and dy). This is done by querying the containing Space's Cells so that it can see if moving it would coincide with a cell that houses another Collider (filtered using the given selection of tag strings). If so, Check returns a Inspector. If no colliders are found or the Collider does not exist within a Space, this function returns nil.
func (*Collider) Clone ¶
Clone clones the Collider with its properties into another Collider. It also clones the Collider's Shape (if it has one).
func (*Collider) RemoveFromIgnoreList ¶
RemoveFromIgnoreList removes the specified Collider from the Collider's internal inspector ignoral list. Colliders removed from this list will once again be counted for Check().
func (*Collider) RemoveTags ¶
RemoveTags removes tags from the Collider.
func (*Collider) SetBottom ¶
SetBottom sets the Y position of the Collider so that the bottom edge is at the Y position given.
func (*Collider) SetCenter ¶
SetCenter sets the Collider such that its center is at the X and Y position given.
func (*Collider) SetCenterVec ¶
SetCenterVec sets the Collider such that its center is at the X and Y position given.
func (*Collider) SetRight ¶
SetRight sets the X position of the Collider so the right edge is at the X position given.
func (*Collider) SetShape ¶
SetShape sets the Shape on the Collider, in case you need to use precise per-Shape intersection detection. SetShape calls Collider.Update() as well, so that it's able to update the Shape's position to match its Collider as necessary. (If you don't use this, the Shape's position might not match the Collider's, depending on if you set the Shape after you added the Collider to a Space and if you don't call Collider.Update() yourself afterwards.)
func (*Collider) SharesCells ¶
SharesCells returns whether the Collider occupies a cell shared by the specified other Collider.
func (*Collider) SharesCellsTags ¶
SharesCellsTags returns if the Cells the Collider occupies have an collider with the specified tags.
type ContactSet ¶
type ContactSet struct { Points []vector2.Vector // Slice of points indicating contact between the two Shapes. MTV vector2.Vector // Minimum Translation vector2.Vector; this is the vector to move a Shape on to move it outside of its contacting Shape. Center vector2.Vector // Center of the Contact set; this is the average of all Points contained within the Contact Set. }
func NewContactSet ¶
func NewContactSet() *ContactSet
func (*ContactSet) BottommostPoint ¶
func (cs *ContactSet) BottommostPoint() vector2.Vector
BottommostPoint returns the bottom-most point out of the ContactSet's Points slice. If the Points slice is empty somehow, this returns nil.
func (*ContactSet) LeftmostPoint ¶
func (cs *ContactSet) LeftmostPoint() vector2.Vector
LeftmostPoint returns the left-most point out of the ContactSet's Points slice. If the Points slice is empty somehow, this returns nil.
func (*ContactSet) RightmostPoint ¶
func (cs *ContactSet) RightmostPoint() vector2.Vector
RightmostPoint returns the right-most point out of the ContactSet's Points slice. If the Points slice is empty somehow, this returns nil.
func (*ContactSet) TopmostPoint ¶
func (cs *ContactSet) TopmostPoint() vector2.Vector
TopmostPoint returns the top-most point out of the ContactSet's Points slice. If the Points slice is empty somehow, this returns nil.
type ConvexPolygon ¶
type ConvexPolygon struct { Points []vector2.Vector // Points represents the points constructing the ConvexPolygon. // X, Y float64 // X and Y are the position of the ConvexPolygon. // ScaleW, ScaleH float64 // The width and height for scaling Closed bool // Closed is whether the ConvexPolygon is closed or not; only takes effect if there are more than 2 points. // contains filtered or unexported fields }
ConvexPolygon represents a series of points, connected by lines, constructing a convex shape. The polygon has a position, a scale, a rotation, and may or may not be closed.
func NewConvexPolygon ¶
func NewConvexPolygon(x, y float64, points ...float64) *ConvexPolygon
NewConvexPolygon creates a new convex polygon at the position given, from the provided set of X and Y positions of 2D points (or vertices). You don't need to pass any points at this stage, but if you do, you should pass whole pairs. The points should generally be ordered clockwise, from X and Y of the first, to X and Y of the last. For example: NewConvexPolygon(30, 20, 0, 0, 10, 0, 10, 10, 0, 10) would create a 10x10 convex polygon square, with the vertices at {0,0}, {10,0}, {10, 10}, and {0, 10}, with the polygon itself occupying a position of 30, 20. You can also pass the points using vectors with ConvexPolygon.AddPointsVec().
func NewConvexPolygonVec ¶
func NewConvexPolygonVec(position vector2.Vector, points ...vector2.Vector) *ConvexPolygon
func NewLine ¶
func NewLine(x1, y1, x2, y2 float64) *ConvexPolygon
NewLine is a helper function that returns a ConvexPolygon composed of a single line. The Polygon has a position of x1, y1, and the line stretches to x2-x1 and y2-y1.
func NewRectangle ¶
func NewRectangle(x, y, w, h float64) *ConvexPolygon
NewRectangle returns a rectangular ConvexPolygon at the {x, y} position given with the vertices ordered in clockwise order, positioned at {0, 0}, {w, 0}, {w, h}, {0, h}. TODO: In actuality, an AABBRectangle should be its own "thing" with its own optimized Intersection code check.
func (*ConvexPolygon) AddPoints ¶
func (cp *ConvexPolygon) AddPoints(vertexPositions ...float64)
AddPoints allows you to add points to the ConvexPolygon with a slice or selection of float64s, with each pair indicating an X or Y value for a point / vertex (i.e. AddPoints(0, 1, 2, 3) would add two points - one at {0, 1}, and another at {2, 3}).
func (*ConvexPolygon) AddPointsVec ¶
func (cp *ConvexPolygon) AddPointsVec(points ...vector2.Vector)
AddPointsVec allows you to add points to the ConvexPolygon with a slice of Vectors, each indicating a point / vertex.
func (*ConvexPolygon) Bounds ¶
func (cp *ConvexPolygon) Bounds() (vector2.Vector, vector2.Vector)
Bounds returns two Vectors, comprising the top-left and bottom-right positions of the bounds of the ConvexPolygon, post-transformation.
func (*ConvexPolygon) Center ¶
func (cp *ConvexPolygon) Center() vector2.Vector
Center returns the transformed Center of the ConvexPolygon.
func (*ConvexPolygon) Clone ¶
func (cp *ConvexPolygon) Clone() IShape
Clone returns a clone of the ConvexPolygon as an IShape.
func (*ConvexPolygon) ContainedBy ¶
func (cp *ConvexPolygon) ContainedBy(otherShape IShape) bool
ContainedBy returns if the ConvexPolygon is wholly contained by the other shape provided.
func (*ConvexPolygon) FlipH ¶
func (cp *ConvexPolygon) FlipH()
FlipH flips the ConvexPolygon's vertices horizontally, across the polygon's width, according to their initial offset when adding the points.
func (*ConvexPolygon) FlipV ¶
func (cp *ConvexPolygon) FlipV()
FlipV flips the ConvexPolygon's vertices vertically according to their initial offset when adding the points.
func (*ConvexPolygon) Intersection ¶
func (cp *ConvexPolygon) Intersection(dx, dy float64, other IShape) *ContactSet
Intersection tests to see if a ConvexPolygon intersects with the other given Shape. dx and dy are the delta movement to be applied before the intersection check (thereby allowing you to see if a Shape would collide with another if it were in a different relative location). If an Intersection is found, a ContactSet will be returned, giving information regarding the intersection.
func (*ConvexPolygon) IntersectionForEach ¶
func (p *ConvexPolygon) IntersectionForEach(dx, dy float64, f func(c *ContactSet) bool, others ...IShape)
IntersectionForEach runs a specified function for each contact set caused by contact with any of the shapes passed. If the custom function returns false, then the intersection testing stops iterating through further colliders.
func (*ConvexPolygon) Lines ¶
func (cp *ConvexPolygon) Lines() []*collidingLine
Lines returns a slice of transformed internalLines composing the ConvexPolygon.
func (*ConvexPolygon) Move ¶
func (cp *ConvexPolygon) Move(x, y float64)
Move translates the ConvexPolygon by the designated X and Y values.
func (*ConvexPolygon) MoveVec ¶
func (cp *ConvexPolygon) MoveVec(vec vector2.Vector)
MoveVec translates the ConvexPolygon by the designated vector2.Vector.
func (*ConvexPolygon) PointInside ¶
func (polygon *ConvexPolygon) PointInside(point vector2.Vector) bool
PointInside returns if a Point (a vector2.Vector) is inside the ConvexPolygon.
func (*ConvexPolygon) Position ¶
func (cp *ConvexPolygon) Position() vector2.Vector
Position returns the position of the ConvexPolygon.
func (*ConvexPolygon) Project ¶
func (cp *ConvexPolygon) Project(axis vector2.Vector) Projection
Project projects (i.e. flattens) the ConvexPolygon onto the provided axis.
func (*ConvexPolygon) RecenterPoints ¶
func (cp *ConvexPolygon) RecenterPoints()
RecenterPoints recenters the vertices in the polygon, such that they are all equidistant from the center. For example, say you had a polygon with the following three points: {0, 0}, {10, 0}, {0, 16}. After calling cp.RecenterPoints(), the polygon's points would be at {-5, -8}, {5, -8}, {-5, 8}.
func (*ConvexPolygon) ReverseVertexOrder ¶
func (cp *ConvexPolygon) ReverseVertexOrder()
ReverseVertexOrder reverses the vertex ordering of the ConvexPolygon.
func (*ConvexPolygon) Rotate ¶
func (polygon *ConvexPolygon) Rotate(radians float64)
Rotate is a helper function to rotate a ConvexPolygon by the radians given.
func (*ConvexPolygon) Rotation ¶
func (polygon *ConvexPolygon) Rotation() float64
Rotation returns the rotation (in radians) of the ConvexPolygon.
func (*ConvexPolygon) SATAxes ¶
func (cp *ConvexPolygon) SATAxes() []vector2.Vector
SATAxes returns the axes of the ConvexPolygon for SAT intersection testing.
func (*ConvexPolygon) Scale ¶
func (polygon *ConvexPolygon) Scale() vector2.Vector
Scale returns the scale multipliers of the ConvexPolygon.
func (*ConvexPolygon) SetPosition ¶
func (cp *ConvexPolygon) SetPosition(x, y float64)
SetPosition sets the position of the ConvexPolygon. The offset of the vertices compared to the X and Y position is relative to however you initially defined the polygon and added the vertices.
func (*ConvexPolygon) SetPositionVec ¶
func (cp *ConvexPolygon) SetPositionVec(vec vector2.Vector)
SetPositionVec allows you to set the position of the ConvexPolygon using a vector2.Vector. The offset of the vertices compared to the X and Y position is relative to however you initially defined the polygon and added the vertices.
func (*ConvexPolygon) SetRotation ¶
func (polygon *ConvexPolygon) SetRotation(radians float64)
SetRotation sets the rotation for the ConvexPolygon; note that the rotation goes counter-clockwise from 0 to pi, and then from -pi at 180 down, back to 0. This rotation scheme follows the way math.Atan2() works.
func (*ConvexPolygon) SetScale ¶
func (polygon *ConvexPolygon) SetScale(x, y float64)
SetScale sets the scale multipliers of the ConvexPolygon.
func (*ConvexPolygon) SetScaleVec ¶
func (polygon *ConvexPolygon) SetScaleVec(vec vector2.Vector)
SetScaleVec sets the scale multipliers of the ConvexPolygon using the provided vector2.Vector.
func (*ConvexPolygon) Transformed ¶
func (cp *ConvexPolygon) Transformed() []vector2.Vector
Transformed returns the ConvexPolygon's points / vertices, transformed according to the ConvexPolygon's position.
type IShape ¶
type IShape interface { // Intersection tests to see if a Shape intersects with the other given Shape. dx and dy are delta movement variables indicating // movement to be applied before the intersection check (thereby allowing you to see if a Shape would collide with another if it // were in a different relative location). If an Intersection is found, a ContactSet will be returned, giving information regarding // the intersection. Intersection(dx, dy float64, other IShape) *ContactSet // IntersectionForEach runs a specified function for each contact set caused by contact with any of // the shapes passed. If the custom function returns false, then the intersection testing stops // iterating through further colliders. IntersectionForEach(dx, dy float64, f func(c *ContactSet) bool, others ...IShape) // Bounds returns the top-left and bottom-right points of the Shape. Bounds() (vector2.Vector, vector2.Vector) // Position returns the X and Y position of the Shape. Position() vector2.Vector // SetPosition allows you to place a Shape at another location. SetPosition(x, y float64) // SetPositionVec allows you to place a Shape at another location using a vector2.Vector. SetPositionVec(position vector2.Vector) // Rotation returns the current rotation value for the Shape. Rotation() float64 // SetRotation sets the rotation value for the Shape. // Note that the rotation goes counter-clockwise from 0 at right to pi/2 in the upwards direction, // pi or -pi at left, -pi/2 in the downwards direction, and finally back to 0. // This can be visualized as follows: // // U // L R // D // // R: 0 // U: pi/2 // L: pi / -pi // D: -pi/2 SetRotation(radians float64) // Rotate rotates the IShape by the radians provided. // Note that the rotation goes counter-clockwise from 0 at right to pi/2 in the upwards direction, // pi or -pi at left, -pi/2 in the downwards direction, and finally back to 0. // This can be visualized as follows: // // U // L R // D // // R: 0 // U: pi/2 // L: pi / -pi // D: -pi/2 Rotate(radians float64) Scale() vector2.Vector // Returns the scale of the IShape (the radius for Circles). // Sets the overall scale of the IShape; 1.0 is 100% scale, 2.0 is 200%, and so on. // The greater of these values is used for the radius for Circles. SetScale(w, h float64) // Sets the overall scale of the IShape using the provided vector2.Vector; 1.0 is 100% scale, 2.0 is 200%, and so on. // The greater of these values is used for the radius for Circles. SetScaleVec(vec vector2.Vector) // Move moves the IShape by the x and y values provided. Move(x, y float64) // MoveVec moves the IShape by the movement values given in the vector provided. MoveVec(vec vector2.Vector) // Clone duplicates the IShape. Clone() IShape }
type Inspector ¶
type Inspector struct { Colliders []*Collider // Slice of colliders that were collided with; sorted according to distance to calling Collider. Cells []*Cell // Slice of cells that were collided with; sorted according to distance to calling Collider. // contains filtered or unexported fields }
Inspector contains the results of an Collider.Check() call, and represents a inspector between an Collider and cells that contain other Colliders. The Colliders array indicate the Colliders collided with.
func (*Inspector) CollidersByTags ¶
CollidersByTags returns a slice of Colliders from the cells reported by a Inspector collider by searching for Colliders with a specific set of tags. This slice does not contain the Collider that called Check().
func (*Inspector) ContactWithCell ¶
ContactWithCell returns the delta to move to have the checking collider come into contact with the specified Cell.
func (*Inspector) ContactWithCollider ¶
ContactWithCollider returns the delta to move to have the checking collider come into contact with the specified Collider.
func (*Inspector) HasTags ¶
HasTags returns whether any colliders within the Inspector have all of the specified tags. This slice does not contain the Collider that called Check().
func (*Inspector) SlideAgainstCell ¶
SlideAgainstCell returns how much distance the calling Collider can slide to avoid a inspector with the targetCollider, and a boolean indicating if such a slide was possible. This only works on vertical and horizontal axes (x and y directly), primarily for platformers / top-down games. avoidTags is a sequence of tags (as strings) to indicate when sliding is valid (i.e. if a Cell contains an Collider that has the tag given in the avoidTags slice, then sliding CANNOT happen).
type Projection ¶
type Projection struct {
Min, Max float64
}
}
func (Projection) IsInside ¶
func (projection Projection) IsInside(other Projection) bool
IsInside returns whether the Projection is wholly inside of the other, provided Projection.
func (Projection) Overlap ¶
func (projection Projection) Overlap(other Projection) float64
Overlap returns the amount that a Projection is overlapping with the other, provided Projection. Credit to https://dyn4j.org/2010/01/sat/#sat-nointer
func (Projection) Overlapping ¶
func (projection Projection) Overlapping(other Projection) bool
Overlapping returns whether a Projection is overlapping with the other, provided Projection. Credit to https://www.sevenson.com.au/programming/sat/
type Space ¶
type Space struct { Cells [][]*Cell CellWidth, CellHeight int // Width and Height of each Cell in "world-space" / pixels / whatever }
Space represents a inspector space. Internally, each Space contains a 2D array of Cells, with each Cell being the same size. Cells contain information on which Colliders occupy those spaces.
func (*Space) Add ¶
Add adds the specified Colliders to the Space, updating the Space's cells to refer to the Collider.
func (*Space) Cell ¶
Cell returns the Cell at the given cellular / spatial (not world) X and Y position in the Space. If the X and Y position are out of bounds, Cell() will return nil.
func (*Space) CellsInLine ¶
func (*Space) CheckCells ¶
CheckCells checks a set of cells (from x,y to x + w, y + h in cellular coordinates) and returns a slice of the colliders found within those Cells. The colliders must have any of the tags provided (if any are provided).
func (*Space) CheckWorld ¶
CheckWorld checks the cells of the Grid with the given world coordinates. Internally, this is just syntactic sugar for calling Space.WorldToSpace() on the position and size given.
func (*Space) CheckWorldVec ¶
CheckWorldVec checks the cells of the Grid with the given world coordinates. This function takes vectors for the position and size of the checked area. Internally, this is just syntactic sugar for calling Space.WorldToSpace() on the position and size given.
func (*Space) Colliders ¶
Colliders loops through all Cells in the Space (from top to bottom, and from left to right) to return all Colliders that exist in the Space. Of course, each Collider is counted only once.
func (*Space) Height ¶
Height returns the height of the Space grid in Cells (so a 320x240 Space with 16x16 cells would have a height of 15).
func (*Space) Remove ¶
Remove removes the specified Colliders from being associated with the Space. This should be done whenever an Collider is removed from the game.
func (*Space) SpaceToWorld ¶
SpaceToWorld converts from a position in the Space (on a grid) to a world-based position, given the size of the Space when first created.
func (*Space) UnregisterAllColliders ¶
func (sp *Space) UnregisterAllColliders()
UnregisterAllColliders unregisters all Colliders registered to Cells in the Space.
func (*Space) Width ¶
Width returns the width of the Space grid in Cells (so a 320x240 Space with 16x16 cells would have a width of 20).
func (*Space) WorldToSpace ¶
WorldToSpace converts from a world position (x, y) to a position in the Space (a grid-based position).