@fogrexon/glyph-arena-chase

Whether a pursuer should be walking toward something, and which way — one pure call per frame. See also package README.

Exports

Generated from the package's source when the docs are built — do not edit this table by hand.

NameKind
ChaseConfigtype
ChaseResulttype
ChaseSelftype
ChaseTargettype
GroundAheadtype
chaseTargetfunction

chaseTarget(self, target, config, groundAhead)

self is { x, w, dir } (left edge, width, current facing), target is { x, w }, config is { sightPx, stepTolerancePx } — both required, no defaults — and groundAhead(dir) answers how far the ground one pixel ahead of the feet steps, in dir: 0 flat, +32 a one-tile lip, -32 a drop, Infinity or NaN a hole.

const chase = chaseTarget(
  { x: enemy.x, w: enemy.w, dir: enemy.dir },
  { x: player.x, w: player.w },
  { sightPx: 224, stepTolerancePx: 0 },
  (dir) => stepAhead(enemy, dir),
);

if (chase.walkable) enemy.x += chase.dir * speed * dt;

It returns { noticed, dir, distancePx, walkable }:

Nothing else is in the package: no state (patrol, how long sight has been lost, attack modes are the caller's memory), no speed and no dt (one game moves a plain x, the other feeds a body), and no attack verbs.