@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.
| Name | Kind |
|---|---|
ChaseConfig | type |
ChaseResult | type |
ChaseSelf | type |
ChaseTarget | type |
GroundAhead | type |
chaseTarget | function |
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 }:
distancePxis centre to centre (target minus self); measuring from left edges makes the distance a box of different width notices at differ by half the width difference.dirfollows the sign of the distance, and keepsself.dirwhen the centres coincide — a pursuer standing exactly on its target should not jitter.noticedincludes both ends:|distancePx| <= sightPx.groundAheadis called with thedirthis call returns, so the ground it checks is the ground it will walk; a hole (±Infinity,NaN) is never walkable, andwalkableimpliesnoticed.stepTolerancePxis one number for both directions:-32is as walkable as32.
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.