bound

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorVersionNotSupported   = "Version \"%s\" not supported"
	ErrorShapeTypeNotSupported = "Shape type \"%s\" is not supported"
	ErrorShapeDataNotValid     = "Shape data of shape type \"%s\" is not valid"
)

Returned errors

View Source
const (
	AxisNone = iota
	AxisX    = 1
	AxisY    = 2
	AxisBoth = 3
)

Possible collision axis values

Variables

This section is empty.

Functions

func Deserialize

func Deserialize(r io.Reader) (map[string][]Shaper, error)

Types

type BoundFile

type BoundFile struct {
	Version string
	Bounds  map[string]struct {
		Shapes []struct {
			Type   string
			Values json.RawMessage
		}
	}
}

BoundFile is the struct of the JSON file used to store an animated sprite with attached bounding boxes

type Box

type Box struct {
	pixel.Rect
}

Box is a Rect with methods to resolve collisions

func NewBox

func NewBox(min pixel.Vec, max pixel.Vec) *Box

NewBox returns a new Box instance.

func (*Box) Align

func (bb *Box) Align(pos pixel.Vec)

func (*Box) Collides

func (bb *Box) Collides(other Shaper) bool

Collides returns true if the bounding box collides with the passed shape

func (*Box) Draw

func (bb *Box) Draw(color *color.RGBA, imd *imdraw.IMDraw, target pixel.Target)

Draw draws the bounding box surface on the passed target with the specified color for debugging purposes

func (*Box) Resolve

func (bb *Box) Resolve(delta pixel.Vec, others ...Shaper) Solution

Resolve checks if the bounding box will collide with another bounding box if it moves a certain delta

func (*Box) Shape

func (bb *Box) Shape() Shape

Shape returns the Box instance

type Circle

type Circle struct {
	pixel.Circle
}

func NewCircle

func NewCircle(x, y, r float64) *Circle

func (*Circle) Align

func (bb *Circle) Align(pos pixel.Vec)

TODO

func (*Circle) Collides

func (bc *Circle) Collides(other Shaper) bool

func (*Circle) Draw

func (bc *Circle) Draw(color *color.RGBA, imd *imdraw.IMDraw, target pixel.Target)

func (*Circle) Resolve

func (bc *Circle) Resolve(delta pixel.Vec, others ...Shaper) Solution

TODO

func (*Circle) Shape

func (bc *Circle) Shape() Shape

type Shape

type Shape interface {
	Collides(Shaper) bool
	Resolve(pixel.Vec, ...Shaper) Solution
	Draw(color *color.RGBA, imd *imdraw.IMDraw, target pixel.Target)
	Align(pos pixel.Vec)
}

Shape is an interface that defines the minimum contract required for shapes that can be checked for collisions

type Shaper

type Shaper interface {
	Shape() Shape
}

type Solution

type Solution struct {
	CollisionAxis int
	Object        Shaper
	Distance      pixel.Vec
}

Solution holds information about a collision if it happened, in which axis did and what's the maximum distance an object can move without colliding with the target object

Jump to

Keyboard shortcuts

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