coord

package
v0.0.0-...-73b4bbd Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: MIT Imports: 5 Imported by: 6

README

GoDoc

Documentation

Overview

Package coord implements math primitives that are used in a 2d cell/tile based game.

Index

Constants

View Source
const TurnActionDelay = 10

Currenting in Frames, optimized for 40fps TODO Conditionalize this with the fps

Variables

View Source
var ErrBoundsAreInverted = errors.New("bounds are inverted")
View Source
var ErrBoundsAreTooSmall = errors.New("bounds are too small to split")
View Source
var ErrInvalidDirection = errors.New("invalid direction")

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	TopL Cell `json:"tl"`
	BotR Cell `json:"br"`
}

func JoinBounds

func JoinBounds(bounds ...Bounds) Bounds

func (Bounds) Area

func (b Bounds) Area() int

func (Bounds) BotL

func (b Bounds) BotL() Cell

func (Bounds) Contains

func (b Bounds) Contains(c Cell) bool

func (Bounds) DiffFrom

func (a Bounds) DiffFrom(b Bounds) []Bounds

Diffs 2 overlapping bounds and returns a slice of rectangles that are contained within b and not contained within other. The slice of rectangles will either have 1,2,3,5,8 rectangles.

1 rect - Iff w && h are the same and it shares 2 parallel edges
         aka, its been translated in 1 of the 4 directions
2 rect - TODO Iff w || h are different but it shares 2 perpendicular edges
3 rect - TODO If w && h are different and it shares 2 perpendicular edges
3 rect - *TODO If w && h are the same, but it's been translated by 2 directions
5 rect - TODO Iff w && h are different and other shares 1 edge with b
8 rect - TODO Iff b contains other and shares no edges

func (Bounds) Expand

func (b Bounds) Expand(mag int) Bounds

func (Bounds) HasOnEdge

func (b Bounds) HasOnEdge(c Cell) (onEdge bool)

func (Bounds) Height

func (b Bounds) Height() int

func (Bounds) Intersection

func (b Bounds) Intersection(other Bounds) (Bounds, error)

func (Bounds) Invert

func (b Bounds) Invert() Bounds

Flip TopL and BotR

func (Bounds) IsInverted

func (b Bounds) IsInverted() bool

Is BotR actually TopL?

func (Bounds) Join

func (b Bounds) Join(with Bounds) Bounds

func (Bounds) JoinAll

func (b Bounds) JoinAll(bounds ...Bounds) Bounds

func (Bounds) Overlaps

func (b Bounds) Overlaps(other Bounds) bool

func (Bounds) Quads

func (b Bounds) Quads() ([4]Bounds, error)

func (Bounds) TopR

func (b Bounds) TopR() Cell

func (Bounds) Width

func (b Bounds) Width() int

type Cell

type Cell struct {
	X int `json:"x"`
	Y int `json:"y"`
}

func (Cell) Add

func (c Cell) Add(x, y int) Cell

func (Cell) DirectionTo

func (c Cell) DirectionTo(other Cell) Direction

func (Cell) Neighbor

func (c Cell) Neighbor(d Direction) Cell

type CellCollision

type CellCollision struct {
	CollisionType
	stime.Span
	Cell Cell
	Path PathAction
}

func NewCellCollision

func NewCellCollision(p PathAction, c Cell) (cc CellCollision)

func (CellCollision) End

func (c CellCollision) End() stime.Time

func (CellCollision) OverlapAt

func (c CellCollision) OverlapAt(t stime.Time) (overlap float64)

func (CellCollision) Start

func (c CellCollision) Start() stime.Time

func (CellCollision) Type

func (c CellCollision) Type() CollisionType

type Collision

type Collision interface {
	Type() CollisionType
	Start() stime.Time
	End() stime.Time
	OverlapAt(stime.Time) float64
}

type CollisionType

type CollisionType int
const (
	CT_NONE CollisionType = iota
	CT_HEAD_TO_HEAD
	CT_FROM_SIDE
	CT_A_INTO_B
	CT_A_INTO_B_FROM_SIDE
	CT_SWAP
	CT_SAME_ORIG
	CT_SAME_ORIG_PERP
	CT_SAME_ORIG_DEST
	CT_CELL_DEST
	CT_CELL_ORIG
)

TODO Implement this as bitflags

func (CollisionType) String

func (i CollisionType) String() string

type Direction

type Direction byte
const (
	North, N Direction = iota, iota
	East, E
	South, S
	West, W
)

func NewDirectionWithString

func NewDirectionWithString(s string) (Direction, error)

Create a new direction from a string value. Returns ErrInvalidDirection if the string doesn't represent a valid direction.

func (Direction) IsParallelTo

func (d Direction) IsParallelTo(p Direction) bool

func (Direction) Reverse

func (d Direction) Reverse() Direction

func (Direction) String

func (i Direction) String() string

type MoveAction

type MoveAction interface {
	Start() stime.Time
	End() stime.Time
	CanHappenAfter(action MoveAction) bool
}

type PartialCell

type PartialCell struct {
	Cell
	Percentage float64
}

func (PartialCell) String

func (p PartialCell) String() string

type PathAction

type PathAction struct {
	stime.Span
	Orig, Dest Cell
}

func (PathAction) Bounds

func (pa PathAction) Bounds() Bounds

func (*PathAction) CanHappenAfter

func (pa *PathAction) CanHappenAfter(anAction MoveAction) bool

func (PathAction) CollidesWith

func (A PathAction) CollidesWith(B interface{}) (c Collision)

func (PathAction) Crosses

func (pa PathAction) Crosses(path PathAction) bool

func (PathAction) DestPartial

func (pa PathAction) DestPartial(now stime.Time) (pc PartialCell)

func (PathAction) Direction

func (pa PathAction) Direction() Direction

func (*PathAction) End

func (pa *PathAction) End() stime.Time

func (PathAction) IsParallelTo

func (pa PathAction) IsParallelTo(pa2 PathAction) bool

func (PathAction) OrigPartial

func (pa PathAction) OrigPartial(now stime.Time) (pc PartialCell)

func (*PathAction) Start

func (pa *PathAction) Start() stime.Time

func (PathAction) String

func (pa PathAction) String() string

func (PathAction) ToState

func (pa PathAction) ToState() PathActionState

func (PathAction) Traverses

func (pa PathAction) Traverses(c Cell) bool

func (PathAction) TraversesAt

func (pa PathAction) TraversesAt(c Cell, t stime.Time) (pc PartialCell, err error)

type PathActionState

type PathActionState struct {
	Start stime.Time `json:"start"`
	End   stime.Time `json:"end"`
	Orig  Cell       `json:"orig"`
	Dest  Cell       `json:"dest"`
}

type PathCollision

type PathCollision struct {
	CollisionType
	stime.Span
	A, B PathAction
}

func NewPathCollision

func NewPathCollision(a, b PathAction) (c PathCollision)

func (PathCollision) End

func (c PathCollision) End() stime.Time

func (PathCollision) OverlapAt

func (c PathCollision) OverlapAt(t stime.Time) (overlap float64)

func (PathCollision) Start

func (c PathCollision) Start() stime.Time

func (PathCollision) Type

func (c PathCollision) Type() CollisionType

type Quad

type Quad int
const (
	NW Quad = iota
	NE
	SE
	SW
)

func (Quad) String

func (i Quad) String() string

type TurnAction

type TurnAction struct {
	From, To Direction
	Time     stime.Time
}

func (TurnAction) CanHappenAfter

func (a TurnAction) CanHappenAfter(anAction MoveAction) bool

func (TurnAction) End

func (a TurnAction) End() stime.Time

func (TurnAction) Start

func (a TurnAction) Start() stime.Time

Jump to

Keyboard shortcuts

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