Temporary abilities, buffs, upgrades and pickups. Timed buffs with stacking rules (refresh, extend, stack, replace), stat modifiers (add and multiply), flags like shield, invincibility and magnet, charge-based power-ups, expiry warnings, pause-safe timers, HUD icons, spawning by need, and permanent upgrades between runs. Includes tested powerups.js. Use for "add power-ups / buffs / pickups / up...
Download skill (.zip) Files on GitHubPower-up system
Drop-in: assets/powerups.js (tests: multiply and add modifiers, stacking to a max, charges, expiry warning, extend, expiry,
need-weighted spawning).
import { PowerUps, pickPowerUp } from "./core/powerups.js";
player.pu = new PowerUps(player);
player.pu.add({ id: "speed", icon: "boot", duration: 6, mods: { speed: { mul: 1.5 } } }); // refresh on re-pickup
player.pu.add({ id: "rage", duration: 5, stack: "stack", maxStacks: 3, mods: { damage: { add: 2 } } });
player.pu.add({ id: "shield", charges: 1, flags: ["shield"] }); // when hit: if (pu.consumeCharge("shield")) return;
// each step: player.pu.update(dt); speed = player.pu.stat("speed", cfg.speed); if (player.pu.has("magnet")) pullCoins();
// HUD: player.pu.hud() → icons with time left; blink the ones in pu.expiringSoon(1.5)
const next = pickPowerUp([{ id: "heart", weight: (c) => (c.hp < 0.3 ? 8 : 1) }, { id: "bomb", weight: 1 }], { hp: player.hp / player.maxHp }, rng.next, last);
Stacking rules (choose per power-up)
| Rule | Picking up again… | Good for |
|---|---|---|
refresh |
Resets the timer | Speed, magnet |
extend |
Adds time | Invincibility star, slow-mo |
stack |
+1 stack (up to max), resets the timer | Damage, fire rate |
replace |
Old one ends, new one starts | Weapon types |
Design rules
- Readable: distinct shape, color and sound per power-up; an icon with a timer ring in the HUD; blink the last 1.5 s.
- Short and strong beats long and weak (5–10 s). Big ones are rare.
- Spawn by need: more health when low, never the same twice in a row, cooldown between drops.
- Timers advance with
dtfrom the game loop, so pausing freezes them. - Effects end cleanly:
onEndrestores visuals;pu.clear()on death and level change. - Permanent upgrades (meta progression) are separate: store them in the save, apply them as base stats (level-progression).