Documentation
¶
Overview ¶
Package grid is a 2D tile map for walkability and world↔cell conversion.
The grid is shared map state — not ECS entities. Pathing and movement sample it; towers mark cells blocked when placed or sold.
Index ¶
- type Grid
- func (g *Grid) CellCenter(cx, cy int, tileSize float64) (wx, wy float64)
- func (g *Grid) EachCell(r Rect, fn func(x, y int))
- func (g *Grid) FillWalkable(walkable bool)
- func (g *Grid) InBounds(x, y int) bool
- func (g *Grid) Index(x, y int) int
- func (g *Grid) Neighbors4(x, y int, dst [][2]int) [][2]int
- func (g *Grid) RectClear(r Rect) bool
- func (g *Grid) RectInBounds(r Rect) bool
- func (g *Grid) SetBlocked(x, y int, blocked bool)
- func (g *Grid) SetRectBlocked(r Rect, blocked bool)
- func (g *Grid) SetWalkable(x, y int, walkable bool)
- func (g *Grid) Walkable(x, y int) bool
- func (g *Grid) WorldToCell(wx, wy, tileSize float64) (cx, cy int)
- type Rect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Grid ¶
Grid is a rectangular tile map. Cells are indexed row-major: y*Width + x.
func (*Grid) CellCenter ¶
CellCenter returns the world-space center of cell (cx, cy).
func (*Grid) FillWalkable ¶
FillWalkable sets every cell to the same walkability.
func (*Grid) Neighbors4 ¶
Neighbors4 appends the four cardinal neighbors of (x, y) that are in bounds. Order: N, E, S, W.
func (*Grid) RectClear ¶
RectClear reports whether every cell of r is currently walkable. Out-of-bounds rects are not clear.
func (*Grid) RectInBounds ¶
RectInBounds reports whether every cell of r lies on the grid.
func (*Grid) SetBlocked ¶
SetBlocked marks (x, y) non-walkable when blocked is true.
func (*Grid) SetRectBlocked ¶
SetRectBlocked marks every cell in r blocked or clear. Out-of-bounds cells are skipped.
func (*Grid) SetWalkable ¶
SetWalkable sets whether (x, y) may be entered. Out-of-bounds is a no-op.
func (*Grid) Walkable ¶
Walkable reports whether units may enter (x, y). Out-of-bounds cells are never walkable.
func (*Grid) WorldToCell ¶
WorldToCell converts a world position to a cell using floor division.