Cauldron2D.Grid.Coarse (Cauldron2D v0.1.3)

Copy Markdown View Source

A tile grid in blocks, for finding a way when the tiles are many: a block is passable when every tile in it is open, and a path is a run of block centres.

coarse = Cauldron2D.Grid.Coarse.new(grid, {width, height}, block: 2, wrap?: true)
{:ok, path} = Cauldron2D.Grid.Coarse.find(coarse, me.pos, enemy.pos)
goal = Cauldron2D.Grid.Coarse.waypoint(grid, me.pos, path)

grid is the function Cauldron2D.Collision takes, a tile coordinate to :open, :solid or a half tile. A point in a block that is not passable — on a base, in a pocket — starts from, or is sought at, the nearest passable block within two of it.

Summary

Functions

The block the tile at point is in.

The tile position at the centre of a block.

The path from from to to as block centres, or :none when there is none within limit blocks.

The coarse map of grid, size tiles across and down; options :block, tiles to a block (default 2), and :wrap? (default false).

Whether the block holding the tile at point is passable.

The point of path to make for from from: the furthest in a clear straight line on grid, else the first.

Types

t()

@type t() :: %Cauldron2D.Grid.Coarse{
  block: pos_integer(),
  height: pos_integer(),
  passable: MapSet.t({integer(), integer()}),
  width: pos_integer(),
  wrap?: boolean()
}

Functions

block_of(coarse, arg)

@spec block_of(t(), {number(), number()}) :: {integer(), integer()}

The block the tile at point is in.

centre(coarse, arg)

@spec centre(t(), {integer(), integer()}) :: {float(), float()}

The tile position at the centre of a block.

find(coarse, from, to, limit \\ 400)

@spec find(t(), {number(), number()}, {number(), number()}, pos_integer()) ::
  {:ok, [{float(), float()}]} | :none

The path from from to to as block centres, or :none when there is none within limit blocks.

new(grid, arg, opts \\ [])

The coarse map of grid, size tiles across and down; options :block, tiles to a block (default 2), and :wrap? (default false).

passable?(coarse, point)

@spec passable?(t(), {number(), number()}) :: boolean()

Whether the block holding the tile at point is passable.

waypoint(grid, from, path)

@spec waypoint(Cauldron2D.Collision.grid(), {number(), number()}, [{float(), float()}]) ::
  {float(), float()}

The point of path to make for from from: the furthest in a clear straight line on grid, else the first.