Documentation
¶
Overview ¶
Package arena is the shared playfield for maze-style tower defense.
It owns the grid, flow field, spawn/exit cells, and build↔wave phase. Building *types*, combat, and economy stay in game code; this package only manages footprints on walkability and when pathing is rebuilt.
Typical loop (Matrix Defense / Desktop TD style):
a.BeginBuild() a.Place(footprint) // or Unplace after a sell — marks dirty a.BeginWave() // rebuilds field if needed; requires open path move.FollowFlow(...) // during wave a.BeginBuild() // after wave cleared
Index ¶
- Variables
- func DefaultTopBottom(width, height int) (spawns, exits []pathing.Cell, err error)
- func VerticalPlayfield(width, height, spawnRows int) (spawns, exits []pathing.Cell, err error)
- type Arena
- func (a *Arena) BeginBuild()
- func (a *Arena) BeginWave() error
- func (a *Arena) CanPlace(fp grid.Rect) error
- func (a *Arena) Dirty() bool
- func (a *Arena) MarkDirty()
- func (a *Arena) Place(fp grid.Rect) error
- func (a *Arena) SpawnsReachable() bool
- func (a *Arena) SyncPathing() error
- func (a *Arena) TileSize() float64
- func (a *Arena) Unplace(fp grid.Rect) error
- type Config
- type Phase
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotBuildPhase is returned when Place/Unplace runs outside build. ErrNotBuildPhase = errors.New("arena: not in build phase") // ErrNotWavePhase is returned when wave-only ops run outside a wave. ErrNotWavePhase = errors.New("arena: not in wave phase") // ErrFootprintBlocked is returned when a footprint overlaps occupied cells. ErrFootprintBlocked = errors.New("arena: footprint not clear") // ErrFootprintOOB is returned when a footprint leaves the playable grid. ErrFootprintOOB = errors.New("arena: footprint out of bounds") // ErrPathBlocked is returned when a place/start would seal spawn→exit. ErrPathBlocked = errors.New("arena: placement blocks all paths to exit") // ErrNoSpawns is returned when the arena has no spawn cells. ErrNoSpawns = errors.New("arena: no spawn cells") )
Functions ¶
func DefaultTopBottom ¶
DefaultTopBottom returns spawns along the full top row and exits along the full bottom row — the classic “enter top, escape bottom” layout.
func VerticalPlayfield ¶ added in v0.0.2
VerticalPlayfield is the Matrix Defense–style map: a vertical rectangle, a horizontal spawn strip of spawnRows at the top, and a full-width exit strip on the bottom row.
Players typically build horizontal walls left→right then right→left, leaving a one-cell gap on alternating ends so creeps snake downward.
Types ¶
type Arena ¶
type Arena struct {
Grid *grid.Grid
Field *pathing.Field
Phase Phase
Config Config
// contains filtered or unexported fields
}
Arena is the maze rectangle + phase machine.
func (*Arena) BeginBuild ¶
func (a *Arena) BeginBuild()
BeginBuild enters (or returns to) build phase. Safe to call at wave end.
func (*Arena) BeginWave ¶
BeginWave locks footprint edits, rebuilds pathing if dirty, and starts the wave. Fails if RequirePath and any spawn cannot reach an exit.
func (*Arena) MarkDirty ¶
func (a *Arena) MarkDirty()
MarkDirty notes that walkability changed outside Place/Pickup.
func (*Arena) SpawnsReachable ¶
SpawnsReachable reports whether every configured spawn can reach an exit on the *current* grid (cheap BFS; does not require a fresh Field).
func (*Arena) SyncPathing ¶
SyncPathing rebuilds the flow field when dirty.
type Config ¶
type Config struct {
Width, Height int
TileSize float64
// Spawns are entry cells (typically a full top strip).
Spawns []pathing.Cell
// Exits are creep goals (typically the full bottom row).
Exits []pathing.Cell
// RequirePath rejects placements (and BeginWave) that seal every
// spawn from every exit — Desktop TD / fair-maze style.
// If false, players may wall off; creeps on sealed tiles simply stall.
RequirePath bool
// LivePathing rebuilds the flow field after every Place/Unplace in
// build phase so UI can preview the maze path. If false, pathing
// rebuilds on BeginWave (and SyncPathing) only.
LivePathing bool
}
Config seeds a new Arena.