A dash mechanic with an afterimage trail: press dash and the player bursts in the current movement direction, leaving a chain of fading ghost images. The trail sells the speed; the short input lock after the dash gives it weight.
Reuse
The mechanic lives in src/dash-trail.js as a framework-free ES module:
createDasher(opts)— returns a state object; callupdate(dt, input)each frame.opts:speed,dashSpeed,dashDuration,dashCooldown,trailLength,trailFade.- Rendering is yours: the state exposes
pos,trail(array of{x, y, age}), anddashing. Draw the trail however fits the project — the demo uses canvas rects with alpha keyed toage.
Port notes for DragonRuby: the update logic is ~60 lines of pure state math with no
DOM dependencies — translate update() directly into a tick method; trail maps to
args.outputs.sprites with alpha from age.
Gotchas
- Trail sampling is time-based, not frame-based; don’t sample per-frame or the trail bunches up at high refresh rates.
- The demo in
demo/bundles its own copy of the module (self-contained by contract). If you touchsrc/, re-copy it intodemo/.