Documentation ¶
Index ¶
- func BetweenBoxes(boxes []render.Rect) chan BoxCollision
- func GetBoundingRect(a Actor) render.Rect
- func GetBoundingRectHitbox(a Actor, hitbox render.Rect) render.Rect
- func SizePlusHitbox(size render.Rect, hitbox render.Rect) render.Rect
- type Actor
- type BoxCollision
- type Collide
- type CollisionBox
- type IndexTuple
- type Side
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BetweenBoxes ¶
func BetweenBoxes(boxes []render.Rect) chan BoxCollision
BetweenBoxes checks if there is a collision between any two bounding rectangles.
This returns a generator that spits out indexes of the intersecting boxes.
func GetBoundingRect ¶
GetBoundingRect computes the full pairs of points for the bounding box of the actor.
The X,Y coordinates are the position in the level of the actor, The W,H are the size of the actor's drawn box.
func GetBoundingRectHitbox ¶
GetBoundingRectHitbox returns the bounding rect of the Actor taking into account their self-declared collision hitbox.
The rect returned has the X,Y coordinate set to the actor's position, plus the X,Y of their hitbox, if any.
The W,H of the rect is the W,H of their declared hitbox.
If the actor has NOT declared its hitbox, this function returns exactly the same way as GetBoundingRect() does.
Types ¶
type Actor ¶
type Actor interface { Position() render.Point Size() render.Rect Grounded() bool SetGrounded(bool) Hitbox() render.Rect }
Actor is a subset of the uix.Actor interface with just the methods needed for collision checking purposes.
type BoxCollision ¶
type BoxCollision struct { // A and B are the indexes of the boxes sent to BetweenBoxes. A int B int // Overlap is the rect of how the boxes overlap. Overlap render.Rect }
BoxCollision holds the result of a collision BetweenBoxes.
func CompareBoxes ¶
func CompareBoxes(box, other render.Rect) (BoxCollision, error)
CompareBoxes checks if two boxes overlaps and returns information about the overlap. The boxes are bounding rectangles like those given to BetweenBoxes().
type Collide ¶
type Collide struct { Top bool TopPoint render.Point TopPixel *level.Swatch Left bool LeftPoint render.Point LeftPixel *level.Swatch Right bool RightPoint render.Point RightPixel *level.Swatch Bottom bool BottomPoint render.Point BottomPixel *level.Swatch MoveTo render.Point // Swatch attributes affecting the collision at this time. InFire string // the name of the swatch, Fire = general ouchy color. InWater bool IsSlippery bool }
Collide describes how a collision occurred.
func CollidesWithGrid ¶
CollidesWithGrid checks if a Doodad collides with level geometry.
The `target` is the point the actor wants to move to on this tick.
func (*Collide) IsColliding ¶
IsColliding returns whether any sort of collision has occurred.
func (*Collide) Reset ¶
func (c *Collide) Reset()
Reset a Collide struct flipping all the bools off, but keeping MoveTo.
func (*Collide) ScanBoundingBox ¶
ScanBoundingBox scans all of the pixels in a bounding box on the grid and returns if any of them intersect with level geometry.
type CollisionBox ¶
type CollisionBox struct { Top [2]render.Point Bottom [2]render.Point Left [2]render.Point Right [2]render.Point }
CollisionBox holds all of the coordinate pairs to draw the collision box around a doodad.
func GetCollisionBox ¶
func GetCollisionBox(box render.Rect) CollisionBox
GetCollisionBox returns a CollisionBox with the four coordinates.
func NewBox ¶
func NewBox(topLeft, bottomRight render.Point) CollisionBox
NewBox creates a collision box from the Top Left and Bottom Right points.
func Overlap ¶
func Overlap(a, b render.Rect) CollisionBox
Overlap returns the overlap rectangle between two boxes.
The two rects given have an X,Y coordinate and their W,H are their width and heights.
The returned CollisionBox uses absolute coordinates in the same space as the passed-in rects.
func OverlapRelative ¶
func OverlapRelative(source, other render.Rect) CollisionBox
OverlapRelative returns the Overlap box using coordinates relative to the source rect instead of absolute coordinates.
func (CollisionBox) BottomRight ¶
func (c CollisionBox) BottomRight() render.Point
BottomRight returns the point at the bottom right.
func (CollisionBox) String ¶
func (c CollisionBox) String() string
String prints the bounds of the collision box in absolute terms.
func (CollisionBox) TopLeft ¶
func (c CollisionBox) TopLeft() render.Point
TopLeft returns the point at the top left.