pather

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KindPlain (.) is a plain tile with a movement cost of 1.
	KindPlain uint8 = iota
	// KindBlocker (X) is a tile which blocks movement.
	KindBlocker
	// KindFrom (F) is a tile which marks where the path should be calculated
	// from.
	KindFrom
	// KindTo (T) is a tile which marks the goal of the path.
	KindTo
	// KindSoftBlocker (S) is a tile to fake some blocking areas with increased cost of moving, like Arcane Sanctuary platforms
	KindSoftBlocker
)

Kind* constants refer to tile kinds for input and output.

Variables

View Source
var KindCosts = map[uint8]float64{
	KindPlain:       1.0,
	KindFrom:        1.0,
	KindTo:          1.0,
	KindSoftBlocker: 3.0,
}

KindCosts map tile kinds to movement costs.

Functions

func DistanceFromMe

func DistanceFromMe(d data.Data, p data.Position) int

func DistanceFromPoint

func DistanceFromPoint(from data.Position, to data.Position) int

func GameCoordsToScreenCords

func GameCoordsToScreenCords(playerX, playerY, destinationX, destinationY int) (int, int)

func MoveThroughPath

func MoveThroughPath(p *Pather, distance int, teleport bool)

func RandomMovement

func RandomMovement()

Types

type AstarPather

type AstarPather []astar.Pather

type Pather

type Pather struct {
	AstarPather
	Destination data.Position
}

func GetClosestWalkablePath

func GetClosestWalkablePath(d data.Data, dest data.Position, blacklistedCoords ...[2]int) (path *Pather, distance float64, found bool)

func GetPath

func GetPath(d data.Data, to data.Position, blacklistedCoords ...[2]int) (path *Pather, distance float64, found bool)

func (*Pather) Distance

func (p *Pather) Distance() int

type Tile

type Tile struct {
	// Kind is the kind of tile, potentially affecting movement.
	Kind uint8
	// X and Y are the coordinates of the tile.
	X, Y int
	// W is a reference to the World that the tile is a part of.
	W World
}

A Tile is a tile in a grid which implements Pather.

func (*Tile) PathEstimatedCost

func (t *Tile) PathEstimatedCost(to astar.Pather) float64

PathEstimatedCost uses Manhattan distance to estimate orthogonal distance between non-adjacent nodes.

func (*Tile) PathNeighborCost

func (t *Tile) PathNeighborCost(to astar.Pather) float64

PathNeighborCost returns the movement cost of the directly neighboring tile.

func (*Tile) PathNeighbors

func (t *Tile) PathNeighbors() []astar.Pather

PathNeighbors returns the neighbors of the tile, excluding blockers and tiles off the edge of the board.

type World

type World [][]*Tile

func (World) FirstOfKind

func (w World) FirstOfKind(kind uint8) *Tile

FirstOfKind gets the first tile on the board of a kind, used to get the from and to tiles as there should only be one of each.

func (World) From

func (w World) From() *Tile

From gets the from tile from the world.

func (World) NewTile

func (w World) NewTile(kind uint8, x, y int) *Tile

func (World) SetTile

func (w World) SetTile(t *Tile)

SetTile sets a tile at the given coordinates in the world.

func (World) Tile

func (w World) Tile(x, y int) *Tile

Tile gets the tile at the given coordinates in the world.

func (World) To

func (w World) To() *Tile

To gets the to tile from the world.

Jump to

Keyboard shortcuts

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