collision

package
v0.0.0-...-79996cc Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

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

func GetBoundingRect(a Actor) render.Rect

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

func GetBoundingRectHitbox(a Actor, hitbox render.Rect) render.Rect

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.

func SizePlusHitbox

func SizePlusHitbox(size render.Rect, hitbox render.Rect) render.Rect

SizePlusHitbox adjusts an actor's canvas Size() to better fit the declared Hitbox by the actor's script.

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

func CollidesWithGrid(d Actor, grid *level.Chunker, target render.Point) (*Collide, bool)

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

func (c *Collide) IsColliding() bool

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

func (c *Collide) ScanBoundingBox(box render.Rect, grid *level.Chunker) bool

ScanBoundingBox scans all of the pixels in a bounding box on the grid and returns if any of them intersect with level geometry.

func (*Collide) ScanGridLine

func (c *Collide) ScanGridLine(p1, p2 render.Point, grid *level.Chunker, side Side)

ScanGridLine scans all of the pixels between p1 and p2 on the grid and tests for any pixels to be set, implying a collision between level geometry and the bounding boxes of the doodad.

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.

type IndexTuple

type IndexTuple [2]int

IndexTuple holds two integers used as array indexes.

type Side

type Side uint8

Side of the collision box (top, bottom, left, right)

const (
	Top Side = iota
	Bottom
	Left
	Right
)

Options for the Side type.

Jump to

Keyboard shortcuts

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