Skip to content

244 pixel art effects, every one a small piece of code. Plus a Claude Code skill to make your own.

Rebuild pilot at Sprite Fusion's quality bar

rehan-remade62c190305b15
diff --git a/docs/CATALOG.md b/docs/CATALOG.md
index 77c0386..ad7e73c 100644
--- a/docs/CATALOG.md
+++ b/docs/CATALOG.md
@@ -47,7 +47,7 @@ blasts, smoke, fireworks, mushroom clouds.
| Mine blast | `explosions/mine-blast` | one-shot 1.9s | 88×124 | A buried mine blinks red twice and arms, then fires a narrow jet of fire and dirt straight up; clods rain back down and a crater smokes in the floor. |
| Nuke | `explosions/nuke` | one-shot 4.4s | 176×172 | A blinding white flash, then a fireball lifts off on a rising stem and rolls into a mushroom cloud, cooling to smoke as a ring of dust surges out along the ground. |
| Plasma explosion | `explosions/plasma-explosion` | one-shot 0.95s | 104×104 | A blue-white energy blast: a white core flash, a crackling plasma sphere that swells and hollows out, three shock rings, arcs of lightning, plasma motes. |
-| Small explosion | `explosions/small-explosion` | one-shot 1.2s | 84×88 | A quick blast: a white flash frame, a lumpy fireball that cools from the edges into rising smoke, a shockwave, sparks and debris. |
+| Explosion | `explosions/small-explosion` | one-shot 5.4s | 300×240 | A ground blast: a white flash and shock rings, fire that cools into a rolling smoke column, sparks, burning brands that land and keep burning, tumbling rocks and a glowing scorch. |
| Smoke puff | `explosions/smoke-puff` | one-shot 0.75s | 60×52 | A cartoon poof: round outlined puffs pop out with a bounce, drift apart and blink away one by one, with speed lines and a couple of twinkles. |
## water
@@ -82,7 +82,7 @@ spikes, novas, freezing, shattering.
| Cold mist | `ice/cold-mist` | loop 4s | 128×32 | Low freezing fog rolls along the floor in two layers drifting right at different speeds, thick at the ground, wispy on top, with ice glints winking in it. |
| Freeze | `ice/freeze` | one-shot 2.4s | 64×52 | Frost creeps up the character from the feet, an ice block snaps shut around them, glints, cracks, then bursts apart into shards. |
| Frost breath | `ice/frost-breath` | loop 1s | 104×44 | An icy gust blows right in a widening cone: frost puffs swell and tear apart, streaks of wind race past and ice crystals tumble and twinkle. |
-| Frost nova | `ice/frost-nova` | one-shot 1.3s | 128×64 | A white flash at the feet, then a ring of ice crystals bursts outward across a frosting floor, slows, shatters into spinning shards and melts away. |
+| Frost nova | `ice/frost-nova` | one-shot 3.4s | 288×192 | Frost spirals into a spinning snowflake, then a wave blooms three rings of ice crystals round the caster; snow drifts, frost creeps, and the ice melts back into the floor. |
| Frozen ground | `ice/frozen-ground` | one-shot 2.6s | 128×32 | Frost creeps out across the floor in feathery fingers, little crystals sprout as it passes and glint; then it all goes glassy, wet and melts away. |
| Hail impact | `ice/hail-impact` | loop 1.2s | 80×48 | Hailstones pelt the ground at a slant: each hits with a white crack and a puff of powder, bounces, hops, and melts away; some burst into chips. |
| Ice crystal | `ice/ice-crystal` | loop 2.4s | 48×64 | A floating six-sided ice crystal turns slowly and bobs: its facets catch the light in turn, a shine sweeps across, a star winks at its tip, motes circle. |
@@ -153,7 +153,7 @@ slashes, smears, cleaves, combos.
| Scythe reap | `melee/scythe-reap` | one-shot 0.9s | 72×68 | A slow, huge reap: a dark crescent with a pale ghostly edge hangs in the air a beat, then tears away and leaves its ghost to rise, waver and fade. |
| Spear sweep | `melee/spear-sweep` | one-shot 0.7s | 92×40 | A long polearm swept low around the front: a wide flat arc skims the floor from behind to the far side, kicking up a wake of dust. |
| Spin slash | `melee/spin-slash` | one-shot 0.45s | 76×48 | A full-circle spin attack: the blade sweeps a ring around the fighter's waist, front then back, and the ring flares out and dissolves. |
-| Sword slash | `melee/sword-slash` | one-shot 0.4s | 72×68 | A fast crescent smear: the white edge whips through in four frames, the tail catches up and dissolves, glints fly off. |
+| Sword slash | `melee/sword-slash` | one-shot 0.75s | 136×104 | A tilted crescent whips round in two frames, cools from white to deep blue as it trails off, glints at the tip and throws sparks. |
| Thrust | `melee/thrust` | one-shot 0.4s | 76×40 | A piercing stab: a narrow lance of streaks shoots out in two frames, a sharp star flashes at the tip, speed lines and sparks run on past it. |
| Uppercut | `melee/uppercut` | one-shot 0.45s | 56×62 | A rising punch: a swoosh hooks up from the hip past the face, and a fat comic star bursts where the fist lands up high. |
| Whip crack | `melee/whip-crack` | one-shot 0.55s | 92×54 | A whip lashes out to the right: a loop rolls down its length, the tip snaps straight with a white crack and sparks, then the lash sags and fades. |
diff --git a/src/core/actor.js b/src/core/actor.js
index 38ce7ba..fd4b400 100644
--- a/src/core/actor.js
+++ b/src/core/actor.js
@@ -27,26 +27,29 @@ const HERO_PAL = {
t: "#5f6f94", T: "#46536f", b: "#8a5a32", p: "#38334a", o: "#6a4030",
};
-function maskOf(rows) {
- const h = rows.length, w = rows[0].length, data = new Uint8Array(w * h);
- rows.forEach((r, y) => [...r].forEach((ch, x) => (data[y * w + x] = ch === "." ? 0 : 1)));
+function maskOf(rows, k = 1) {
+ const h = rows.length * k, w = rows[0].length * k, data = new Uint8Array(w * h);
+ rows.forEach((r, y) => [...r].forEach((ch, x) => {
+ if (ch === ".") return;
+ for (let j = 0; j < k * k; j++) data[(y * k + ((j / k) | 0)) * w + x * k + (j % k)] = 1;
+ }));
return { w, h, data };
}
-const MASK = maskOf(HERO);
+const MASKS = { 1: maskOf(HERO, 1), 2: maskOf(HERO, 2) };
/**
- * The stock actor, in local space with its feet at (0, 0):
- * { mask, x, y (top-left of the mask), w, h, head: [x, y] (top of the head), chest: [x, y] }.
+ * The stock actor at scale k (1: 12 x 19 px, 2: 24 x 38 px), in local space with its feet at (0, 0):
+ * { mask, x, y (top-left of the mask), w, h, k, head: [x, y] (top of the head), chest: [x, y] }.
*/
-export function stockActor() {
- const x = -Math.floor(MASK.w / 2), y = -MASK.h;
- return { mask: MASK, x, y, w: MASK.w, h: MASK.h, head: [0, y], chest: [0, y + 11] };
+export function stockActor(k = 1) {
+ const m = MASKS[k] ?? (MASKS[k] = maskOf(HERO, k)), x = -Math.floor(m.w / 2), y = -m.h;
+ return { mask: m, x, y, w: m.w, h: m.h, k, head: [0, y], chest: [0, y + 11 * k] };
}
/** Draw the stock actor with its feet at the painter's origin, at alpha a (dithered). */
export function drawActor(p, actor = stockActor(), a = 1) {
- if (a > 0) p.sprite(HERO, HERO_PAL, actor.x, actor.y, { a });
+ if (a > 0) p.sprite(HERO, HERO_PAL, actor.x, actor.y, { a, scale: actor.k ?? 1 });
}
/** How visible an effect wants the stand-in character at time t (effects may export actorAlpha). */
export const actorAlphaOf = (mod, t, o) => (typeof mod.actorAlpha === "function" ? mod.actorAlpha(t, o) : 1);
diff --git a/src/core/fx.js b/src/core/fx.js
index 41baa6f..1acacba 100644
--- a/src/core/fx.js
+++ b/src/core/fx.js
@@ -39,7 +39,7 @@ export function resolveOptions(meta, o = {}) {
const opts = { ...(meta.options ?? {}), ...o };
for (const [k, def] of Object.entries(meta.options ?? {}))
if (isRamp(def) && isRamp(o[k]) && o[k].length !== def.length) opts[k] = fit(o[k], def.length).map(toHex);
- if (meta.actor && !opts.actor) opts.actor = stockActor();
+ if (meta.actor && !opts.actor) opts.actor = stockActor(meta.actor === 2 ? 2 : 1);
return opts;
}
@@ -62,7 +62,10 @@ export function createFx(mod, o = {}) {
},
update(dt) {
t += dt;
- impl.update?.(dt, opts);
+ if (!impl.update) return;
+ // simulations step at 120 Hz or finer whatever the caller's frame rate, so they look the same everywhere
+ const n = Math.max(1, Math.ceil(dt * 120 - 1e-9));
+ for (let i = 0; i < n; i++) impl.update(dt / n, opts);
},
draw(frame, layer) {
const p = painterFor(frame);
@@ -99,22 +102,24 @@ export function composite(f, out, bg = null, lightK = 1) {
for (let i = 0; i < n; i++) {
const c = C[i], l = L[i] & 0xffffff;
let r, g, b, a;
- if (c >>> 24) {
+ const ca = c >>> 24;
+ if (ca === 255) {
r = c & 255; g = (c >>> 8) & 255; b = (c >>> 16) & 255; a = 255;
} else if (bg === null) {
- r = g = b = a = 0;
+ // translucent color over nothing keeps its alpha
+ r = c & 255; g = (c >>> 8) & 255; b = (c >>> 16) & 255; a = ca;
} else {
- const k = flat ? bg : bg[i];
- r = k & 255; g = (k >>> 8) & 255; b = (k >>> 16) & 255; a = 255;
+ const k = flat ? bg : bg[i], f = ca / 255;
+ r = (c & 255) * f + (k & 255) * (1 - f); g = ((c >>> 8) & 255) * f + ((k >>> 8) & 255) * (1 - f);
+ b = ((c >>> 16) & 255) * f + ((k >>> 16) & 255) * (1 - f); a = 255;
}
if (l) {
const lr = (l & 255) * lightK, lg = ((l >>> 8) & 255) * lightK, lb = ((l >>> 16) & 255) * lightK;
- if (a === 0) {
- const m = Math.min(255, Math.max(lr, lg, lb));
- if (m >= 1) {
- const s = 255 / Math.max(lr, lg, lb);
- r = lr * s; g = lg * s; b = lb * s; a = m;
- }
+ if (a < 255) {
+ // over transparency: premultiply what's there, add the light, divide by the new alpha
+ const pa = a / 255, pr = r * pa + lr, pg = g * pa + lg, pb = b * pa + lb;
+ const na = Math.min(1, Math.max(pa, Math.max(lr, lg, lb) / 255));
+ if (na > 0) { r = Math.min(255, pr / na); g = Math.min(255, pg / na); b = Math.min(255, pb / na); a = na * 255; }
} else {
r = Math.min(255, r + lr); g = Math.min(255, g + lg); b = Math.min(255, b + lb);
}
diff --git a/src/core/index.js b/src/core/index.js
index 8e564cc..38e65aa 100644
--- a/src/core/index.js
+++ b/src/core/index.js
@@ -4,6 +4,7 @@ export * from "./math.js";
export * from "./color.js";
export * from "./particles.js";
export * from "./shapes.js";
+export { Particles, Bits, Lights, Blazes, P, PF, B, GRAVITY, FIRE_RAMP, SMOKE_RAMP, sparkle, flare, band, crystal } from "./sim.js";
export { Painter } from "./painter.js";
export { FONTS, textWidth } from "./font.js";
export { createFrame, clearFrame, createFx, composite, painterFor, resolveOptions } from "./fx.js";
diff --git a/src/core/painter.js b/src/core/painter.js
index f90ef4b..4f397db 100644
--- a/src/core/painter.js
+++ b/src/core/painter.js
@@ -62,6 +62,31 @@ export class Painter {
const b = Math.min(255, ((d >>> 16) & 255) + ((c >>> 16) & 255) * k) | 0;
this.L[i] = (255 << 24) | (b << 16) | (g << 8) | r;
}
+ /**
+ * Blend a color over what's there at alpha a (0..1), keeping the result's own alpha: soft smoke, vapour and
+ * mist. Use dithered dot() for hard pixel fades and blend() for translucent volumes.
+ */
+ blendPx(sx, sy, c, a) {
+ a *= this.fade;
+ if (!c || a <= 0.004) return;
+ const x = sx - this.ox, y = sy - this.oy;
+ if (x < 0 || y < 0 || x >= this.w || y >= this.h) return;
+ const i = y * this.w + x, d = this.C[i], da = (d >>> 24) / 255, oa = a + da * (1 - a), k = a / oa;
+ const ch = (s) => ((((c >>> s) & 255) * k + ((d >>> s) & 255) * (1 - k)) & 255);
+ this.C[i] = (((oa * 255) & 255) << 24) | (ch(16) << 16) | (ch(8) << 8) | ch(0);
+ }
+ /** Translucent pixel at a local point. */
+ blend(x, y, c, a) { this.blendPx(this.cellX(x, y), this.cellY(x, y), c, a); }
+ /** A translucent disc: puffs of smoke, vapour, dust. c and a may be functions of (d: 0 center..1 rim, angle). */
+ disc(cx, cy, r, c, a) {
+ if (r < 0.5) return this.blend(cx, cy, call(c, 0, 0), call(a, 0, 0));
+ this.each(cx - r, cy - r, cx + r, cy + r, (x, y, sx, sy) => {
+ const dx = x - cx, dy = y - cy, d2 = dx * dx + dy * dy;
+ if (d2 > r * r) return;
+ const d = Math.sqrt(d2) / r, ang = Math.atan2(dy, dx);
+ this.blendPx(sx, sy, call(c, d, ang), call(a, d, ang));
+ });
+ }
/** Read back the color under a local point (0 if empty). */
get(x, y) {
const sx = this.cellX(x, y) - this.ox, sy = this.cellY(x, y) - this.oy;
diff --git a/src/core/sim.js b/src/core/sim.js
new file mode 100644
index 0000000..68f1a70
--- /dev/null
+++ b/src/core/sim.js
@@ -0,0 +1,442 @@
+// Simulated particles, debris and lights, for effects that want real physics: sparks that streak and bounce
+// off the floor, shards that tumble and settle, vapour and smoke that swell and thin, lights that flare and die.
+// Adapted from Sprite Fusion's open-source pixel art VFX (https://www.spritefusion.com/pixel-art-vfx),
+// MIT License, Copyright (c) 2026 Hugo Duprez. Units here are art pixels and seconds; draw through a Painter,
+// so effects stay in local space and mirror or rotate like any other.
+
+import { Rng, clamp, TAU } from "./math.js";
+import { hex, scale, mix, rgb, WHITE } from "./color.js";
+
+export const GRAVITY = 950; // px/s²
+const CROSS = [[1, 0], [-1, 0], [0, 1], [0, -1]];
+const DIAG = [[1, 1], [1, -1], [-1, 1], [-1, -1]];
+const HOT = ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"].map(hex);
+/** Fire from white-hot to smouldering, and smoke from fresh to thin: the ramps FIRE puffs and SMOKE walk down. */
+export const FIRE_RAMP = ["#ffffff", "#fff3a6", "#ffe26b", "#ffc23d", "#ff8a2a", "#f2561d", "#c9281f", "#8a1f17", "#4a1712"].map(hex);
+export const SMOKE_RAMP = ["#7b6f72", "#5d5660", "#433d48", "#2b2630", "#1a171e"].map(hex);
+const rampAt = (r, t) => r[Math.min(r.length - 1, Math.max(0, Math.floor(t * r.length)))];
+
+/** Particle kinds. */
+export const P = { SPARK: 0, MOTE: 1, STREAK: 2, FLAKE: 3, VAPOUR: 4, DUST: 5, STAR: 6, EMBER: 7, SMOKE: 8, FIRE: 9, BRAND: 10, GRIT: 11 };
+/** Particle flags: SMOKES (a FIRE puff leaves smoke when it dies), BIG (bigger, slower smoke), BACK (draw behind). */
+export const PF = { SMOKES: 1, BIG: 2, BACK: 4 };
+const SOFT = new Set([P.VAPOUR, P.DUST, P.SMOKE]);
+
+/**
+ * A particle system. opts: { seed, ground: (x) => floor y (local px; sparks bounce on it), sparks: [head..tail]
+ * colors for SPARK, haze: color vapour glows with }.
+ * spawn(kind, x, y, vx, vy, life, color, size); update(dt); draw(p, layer): "back" draws the soft kinds
+ * (vapour, dust, smoke), "front" the rest, nothing for both.
+ */
+export class Particles {
+ constructor(opts = {}) {
+ this.R = opts.rng ?? new Rng(opts.seed ?? 1);
+ this.list = [];
+ this.t = 0;
+ this.ground = opts.ground ?? (() => Infinity);
+ this.sparks = (opts.sparks ?? HOT).map(hex);
+ this.haze = opts.haze === undefined ? null : hex(opts.haze);
+ this.onLand = opts.onLand ?? null; // (x, y) when a BRAND hits the floor
+ }
+ /** delay: seconds before it appears; flag: PF bits. col 0 lets FIRE and SMOKE use their own ramps. */
+ spawn(k, x, y, vx, vy, life, col = WHITE, size = 1, delay = 0, flag = 0) {
+ this.list.push({ k, x, y, vx, vy, life, max: life, col: col ? hex(col) : 0, size, seed: this.R.next() * 100, delay, flag });
+ }
+ get count() {
+ return this.list.length;
+ }
+ update(dt) {
+ this.t += dt;
+ const R = this.R, t = this.t;
+ for (let i = this.list.length - 1; i >= 0; i--) {
+ const p = this.list[i];
+ if (p.delay > 0) {
+ p.delay -= dt;
+ continue;
+ }
+ if ((p.life -= dt) <= 0) {
+ if (p.k === P.FIRE && p.flag & PF.SMOKES) {
+ const big = p.flag & PF.BIG;
+ this.spawn(P.SMOKE, p.x, p.y, p.vx * 0.6, p.vy * 0.6 - 6, big ? R.range(1.3, 2.3) : R.range(0.8, 1.4), 0, p.size * (big ? 0.85 : 0.7), 0, big ? PF.BIG : 0);
+ }
+ this.list.splice(i, 1);
+ continue;
+ }
+ switch (p.k) {
+ case P.FIRE:
+ p.vy -= 95 * dt;
+ p.vx += Math.sin(t * 17 + p.seed) * 30 * dt;
+ p.vx -= p.vx * 5 * dt;
+ p.vy -= p.vy * 3.2 * dt;
+ break;
+ case P.GRIT: {
+ p.vy += GRAVITY * dt;
+ p.vx -= p.vx * 0.8 * dt;
+ const g = this.ground(p.x), ny = p.y + p.vy * dt;
+ p.x += p.vx * dt;
+ if (p.vy > 0 && p.y <= g && ny >= g) {
+ p.y = g - 0.25;
+ if (p.vy > 130 && R.chance(0.4)) (p.vy = -p.vy * 0.25), (p.vx = p.vx * 0.5 + R.range(-10, 10));
+ else (p.vx = p.vy = 0), (p.life = Math.min(p.life, 0.5));
+ } else p.y = ny;
+ continue;
+ }
+ case P.BRAND: {
+ // a burning chunk: arcs, trails flame, and starts a little fire where it lands
+ p.vy += GRAVITY * 0.8 * dt;
+ p.vx -= p.vx * 0.9 * dt;
+ if (R.chance(0.9 * Math.min(1, dt * 60))) this.spawn(P.FIRE, p.x, p.y, p.vx * 0.1 + R.range(-7, 7), p.vy * 0.1 - 10, R.range(0.16, 0.32), 0, R.range(0.9, 1.7) * (0.5 + (p.life / p.max) * 0.6), 0, R.chance(0.4) ? PF.SMOKES : 0);
+ const g = this.ground(p.x), ny = p.y + p.vy * dt;
+ p.x += p.vx * dt;
+ if (p.vy > 0 && p.y <= g && ny >= g) {
+ this.onLand?.(p.x, g);
+ this.list.splice(i, 1);
+ } else p.y = ny;
+ continue;
+ }
+ case P.SPARK: {
+ p.vy += GRAVITY * 0.45 * dt;
+ p.vx -= p.vx * 2.2 * dt;
+ p.vy -= p.vy * 2.2 * dt;
+ const g = this.ground(p.x), ny = p.y + p.vy * dt;
+ p.x += p.vx * dt;
+ if (p.vy > 0 && p.y <= g && ny >= g) (p.vy = -p.vy * 0.45), (p.vx *= 0.7), (p.y = g - 0.25);
+ else p.y = ny;
+ continue;
+ }
+ case P.STREAK: (p.vx += p.vx * 3 * dt), (p.vy += p.vy * 3 * dt); break;
+ case P.FLAKE:
+ p.vx -= p.vx * 2.2 * dt;
+ p.vy -= p.vy * 2.2 * dt - 35 * dt;
+ p.x += Math.sin(this.t * 2.5 + p.seed) * 7 * dt;
+ break;
+ case P.EMBER:
+ p.vy += (-30 + Math.sin(t * 3 + p.seed) * 20) * dt;
+ p.vx += Math.cos(t * 2.3 + p.seed) * 45 * dt;
+ p.vx -= p.vx * 1.6 * dt;
+ p.vy -= p.vy * 1.6 * dt;
+ break;
+ case P.SMOKE: {
+ const big = p.flag & PF.BIG;
+ p.vy -= (big ? 23 : 16) * dt;
+ p.vx += Math.sin(t * 1.3 + p.seed) * 8 * dt;
+ p.vx -= p.vx * 1.6 * dt;
+ p.vy -= p.vy * 1.2 * dt;
+ break;
+ }
+ case P.MOTE: p.vx -= p.vx * 0.6 * dt; p.vy -= p.vy * 0.6 * dt; break;
+ default: {
+ const drag = SOFT.has(p.k) ? 4 : 1.6;
+ p.vx -= p.vx * drag * dt;
+ p.vy -= p.vy * drag * dt + 5 * dt;
+ }
+ }
+ p.x += p.vx * dt;
+ p.y += p.vy * dt;
+ }
+ }
+ draw(p, layer) {
+ for (const q of this.list) {
+ if (q.delay > 0) continue;
+ if (layer && (SOFT.has(q.k) || q.flag & PF.BACK ? "back" : "front") !== layer) continue;
+ const k = q.life / q.max, x = q.x, y = q.y, sp = Math.hypot(q.vx, q.vy) || 1, ux = q.vx / sp, uy = q.vy / sp;
+ switch (q.k) {
+ case P.SPARK: {
+ const S = this.sparks, head = k > 0.6 ? S[0] : k > 0.3 ? S[1] : S[2], len = Math.min(9, 1 + sp * 0.022);
+ p.line(x - ux * len, y - uy * len, x - ux * len * 0.4, y - uy * len * 0.4, k > 0.5 ? head : S[S.length - 1]);
+ p.line(x - ux * len * 0.45, y - uy * len * 0.45, x, y, head);
+ p.glow(x, y, 3, head, 0.45 * k);
+ break;
+ }
+ case P.MOTE: {
+ const len = Math.min(16, 0.5 + sp * 0.026) * q.size, a = k < 0.35 ? k / 0.35 : 1;
+ p.line(x - ux * len, y - uy * len, x - ux * len * 0.35, y - uy * len * 0.35, scale(q.col, 0.55), a);
+ p.line(x - ux * len * 0.4, y - uy * len * 0.4, x, y, q.col, a);
+ p.glow(x, y, 2.5 + q.size, q.col, 0.4 * k);
+ break;
+ }
+ case P.STREAK: {
+ const L = clamp(sp / 30, 1, 7);
+ for (let d = L; d >= 0; d -= 0.5) p.dot(x - ux * d, y - uy * d, d < 1 ? WHITE : d < L * 0.5 ? q.col : scale(q.col, 0.6), d < L * 0.5 ? 1 : 1.2 - d / L);
+ p.glow(x, y, 4, q.col, 0.4);
+ break;
+ }
+ case P.FLAKE: {
+ const a = Math.min(1, k * 3);
+ p.dot(x, y, q.col, a);
+ if (q.size > 1.3) for (const [dx, dy] of CROSS) p.dot(x + dx, y + dy, scale(q.col, 0.8), a * 0.8);
+ break;
+ }
+ case P.VAPOUR: {
+ const r = q.size * (0.6 + (1 - k) * 0.9);
+ p.disc(x, y, r, q.col, Math.pow(k, 1.3) * 0.45);
+ if (this.haze) p.glow(x, y, r * 1.8, this.haze, 0.16 * k);
+ break;
+ }
+ case P.DUST: p.disc(x, y, q.size * (0.6 + (1 - k) * 0.9), q.col, Math.pow(k, 1.3) * 0.7); break;
+ case P.SMOKE: {
+ // three soft discs: a body, a denser core sitting low, a lit cap while it's young
+ const age = 1 - k, big = q.flag & PF.BIG;
+ const r = q.size * (0.65 + Math.min(1, age * 2.5) * 0.45 + age * (big ? 0.5 : 0.4));
+ const a = Math.min(1, age * 12) * Math.min(1, k * 2.4) * (big ? 0.7 : 0.58);
+ const c = q.col ? mix(q.col, rampAt(SMOKE_RAMP, age), age) : rampAt(SMOKE_RAMP, age * 1.05);
+ p.disc(x, y, r, c, a * 0.45);
+ p.disc(x + r * 0.05, y + r * 0.06, r * 0.74, c, a * 0.62);
+ if (age < 0.5) p.disc(x - r * 0.22, y - r * 0.3, r * 0.5, mix(c, WHITE, 0.12), a * 0.4 * (1 - age * 2));
+ break;
+ }
+ case P.FIRE: {
+ // a ball of flame that cools down the ramp as it rises: a darker rim, a lit core, a tongue on top
+ const age = 1 - k, heat = Math.min(0.999, Math.pow(age, 0.62) + (q.seed % 1) * 0.1), F = FIRE_RAMP, n = F.length;
+ const idx = Math.min(n - 2, Math.floor(heat * (n - 1)));
+ const r = q.size * (0.55 + 0.45 * Math.min(1, age * 7)) * (1 - age * 0.55), c = F[idx];
+ if (idx >= n - 2) p.disc(x, y, r, c, Math.min(1, k * 3) * 0.85);
+ else {
+ p.circle(x, y, r, F[Math.min(n - 1, idx + 2)]);
+ p.circle(x - r * 0.16, y - r * 0.22, r * 0.78, c);
+ if (r > 1.6) p.circle(x, y - r * 0.9, r * 0.42, c);
+ if (idx <= 3 && r > 1.8) p.circle(x - r * 0.28, y - r * 0.34, r * 0.36, F[Math.max(0, idx - 1)]);
+ if (idx < 6) p.glow(x, y, r * 2.4 + 2, c, 0.18 * k);
+ }
+ break;
+ }
+ case P.BRAND:
+ p.circle(x, y, 1.6, HOT[3]);
+ p.px(x, y, Math.sin(this.t * 40 + q.seed) > 0 ? HOT[0] : HOT[1]);
+ p.px(x + 1, y, HOT[1]);
+ p.glow(x, y, 7, HOT[2], 0.45);
+ break;
+ case P.GRIT:
+ if (k > 0.25 || k * 4 > 0.5) {
+ p.px(x, y, q.col);
+ if (q.size >= 2) p.px(x + 1, y, q.col), p.px(x, y + 1, scale(q.col, 0.8)), p.px(x + 1, y + 1, scale(q.col, 0.7));
+ }
+ break;
+ case P.EMBER: {
+ const c = k > 0.6 ? this.sparks[0] : k > 0.3 ? this.sparks[1] : this.sparks[2];
+ if (k < 0.25 && Math.sin(this.t * 40 + q.seed) < 0) break;
+ p.px(x, y, c);
+ if (q.size > 1.5) p.px(x, y + 1, this.sparks[this.sparks.length - 1]);
+ p.glow(x, y, 3 + q.size, c, 0.35 * k);
+ break;
+ }
+ default: {
+ // STAR: a twinkling cross, arms set by size
+ const tw = 0.6 + 0.4 * Math.sin(this.t * (8 + (q.seed % 5)) + q.seed);
+ if (q.size < 1) {
+ if (tw * k > 0.25) p.px(x, y, tw > 0.8 ? WHITE : q.col);
+ p.glow(x, y, 3, q.col, 0.4 * k * tw);
+ break;
+ }
+ sparkle(p, x, y, q.size * tw * Math.min(1, k * 3), q.col, scale(q.col, 0.75), 0.5 * k * tw);
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Little fires burning where something landed: add(x, y, life, power) feeds FIRE puffs (and the odd ember)
+ * into a particle system, fading over its life. update(dt); drawBack(p) adds a hot pixel and a glow at its foot.
+ */
+export class Blazes {
+ constructor(ps) {
+ this.ps = ps;
+ this.list = [];
+ }
+ add(x, y, life, power) {
+ this.list.push({ x, y, life, max: life, acc: this.ps.R.next(), power });
+ }
+ get count() {
+ return this.list.length;
+ }
+ update(dt) {
+ const ps = this.ps, R = ps.R;
+ for (let i = this.list.length - 1; i >= 0; i--) {
+ const b = this.list[i];
+ if ((b.life -= dt) <= 0) {
+ this.list.splice(i, 1);
+ continue;
+ }
+ const k = b.life / b.max, intensity = b.power * (k > 0.7 ? 1 : 0.35 + (k / 0.7) * 0.65);
+ for (b.acc += dt * (6 + 16 * intensity); b.acc > 1; b.acc--) {
+ const s = R.range(1.2, 2.8) * intensity;
+ ps.spawn(P.FIRE, b.x + R.range(-1.5, 1.5), b.y - s * 0.6, R.range(-6, 6), R.range(-30, -12), R.range(0.28, 0.6), 0, s, 0, PF.BACK | (R.chance(0.3) ? PF.SMOKES : 0));
+ if (R.chance(0.06)) ps.spawn(P.EMBER, b.x, b.y - 1.5, R.range(-15, 15), R.range(-45, -15), R.range(0.6, 1.4), HOT[2], 1, 0, PF.BACK);
+ }
+ }
+ }
+ drawBack(p) {
+ for (const b of this.list) {
+ const k = b.life / b.max;
+ p.px(b.x, b.y, k > 0.4 ? (Math.sin(b.life * 31 + b.x) > 0 ? HOT[1] : HOT[2]) : HOT[3]);
+ p.glow(b.x, b.y, 6 + 5 * k * b.power, HOT[2], 0.3 * k * b.power);
+ }
+ }
+}
+
+/** Debris kinds. */
+export const B = { SHARD: 0, CHUNK: 1, DRIP: 2 };
+
+/**
+ * Rigid debris that tumbles, bounces and settles. add({ kind, x, y, vx, vy, a, va, s (size), c (color), ramp
+ * (chunk shading, dark to bright), g (gravity scale), drag, bounce, life }); update(dt); draw(p).
+ */
+export class Bits {
+ constructor(opts = {}) {
+ this.list = [];
+ this.ground = opts.ground ?? (() => Infinity);
+ }
+ add(b) {
+ const life = b.life ?? 1;
+ this.list.push({ kind: B.SHARD, vx: 0, vy: 0, a: 0, va: 0, s: 1, c: WHITE, g: 1, drag: 0, bounce: 0, rest: false, ...b, life, max: life });
+ }
+ get count() {
+ return this.list.length;
+ }
+ update(dt) {
+ for (let i = this.list.length - 1; i >= 0; i--) {
+ const b = this.list[i];
+ if ((b.life -= dt) <= 0) {
+ this.list.splice(i, 1);
+ continue;
+ }
+ if (b.rest) continue;
+ b.vy += GRAVITY * b.g * dt;
+ b.vx -= b.vx * b.drag * dt;
+ b.vy -= b.vy * b.drag * dt;
+ b.x += b.vx * dt;
+ b.y += b.vy * dt;
+ b.a += b.va * dt;
+ const floor = this.ground(b.x), sp = b.vy;
+ if (b.g <= 0 || b.y < floor || sp <= 0) continue;
+ b.y = floor - 0.01;
+ if (b.kind === B.DRIP) b.life = 0;
+ else if (b.bounce > 0 && sp > 70) (b.vy = -sp * b.bounce), (b.vx *= 0.7), (b.va *= 0.6);
+ else (b.rest = true), (b.vx = b.vy = 0);
+ }
+ }
+ draw(p) {
+ for (const b of this.list) {
+ const a = Math.min(1, b.life / 0.4), ca = Math.cos(b.a), sa = Math.sin(b.a);
+ if (b.kind === B.SHARD) {
+ for (let d = -b.s / 2; d <= b.s / 2; d += 0.5) p.dot(b.x + ca * d, b.y + sa * d, d > b.s / 2 - 0.6 ? WHITE : hex(b.c), a);
+ } else if (b.kind === B.DRIP) {
+ p.dot(b.x, b.y, hex(b.c), a);
+ p.dot(b.x, b.y - 1, hex(b.c), a * 0.5);
+ } else {
+ // a shaded chunk: lit top-left, dark bottom-right, a dark rim
+ const R = (b.ramp ?? ["#1c2030", "#3a4a66", "#6e86a8", "#a8c0dc", "#e8f2ff"]).map(hex), n = R.length;
+ const x = Math.round(b.x), y = Math.round(b.y), r = Math.ceil(b.s) + 1;
+ for (let py = -r; py <= r; py++)
+ for (let px = -r; px <= r; px++) {
+ const u = (px + 0.5) * ca + (py + 0.5) * sa, v = -(px + 0.5) * sa + (py + 0.5) * ca;
+ const d = Math.abs(u) / b.s + Math.abs(v) / (b.s * 0.62);
+ if (d > 1.3) continue;
+ p.dot(x + px, y + py, d > 1 ? R[0] : v < 0 ? (u < 0 ? R[n - 1] : R[n - 2]) : u < 0 ? R[n - 3] : R[Math.max(1, n - 4)], a);
+ }
+ }
+ }
+ }
+}
+
+/** Lights that flare and die: add(x, y, r, color, k, life); update(dt); draw(p). */
+export class Lights {
+ constructor() {
+ this.list = [];
+ }
+ add(x, y, r, color, k, life) {
+ this.list.push({ x, y, r, color: hex(color), k, life, max: life });
+ }
+ update(dt) {
+ for (let i = this.list.length - 1; i >= 0; i--) if ((this.list[i].life -= dt) <= 0) this.list.splice(i, 1);
+ }
+ draw(p) {
+ for (const l of this.list) {
+ const k = l.life / l.max;
+ p.glow(l.x, l.y, l.r * (0.55 + 0.45 * k), l.color, l.k * k * k);
+ }
+ }
+}
+
+/** A star glint: arms of length arm in color c with tips in tip, a white heart, light. */
+export function sparkle(p, x, y, arm, c, tip = c, k = 0.6) {
+ const n = Math.round(arm);
+ if (n < 1) return;
+ const X = Math.floor(x), Y = Math.floor(y);
+ for (let d = 1; d <= n; d++) {
+ const cc = d > n * 0.6 ? tip : c;
+ for (const [dx, dy] of CROSS) p.px(X + dx * d, Y + dy * d, cc);
+ }
+ if (n >= 3) for (const [dx, dy] of DIAG) p.px(X + dx, Y + dy, c);
+ if (n >= 6) for (const [dx, dy] of DIAG) p.px(X + dx * 2, Y + dy * 2, tip);
+ p.px(X, Y, WHITE);
+ p.glow(x, y, 4 + n * 2, c, k);
+}
+
+/** An 8-ray flare: long rays on the axes, shorter between, fading out along their length. ramp dark to bright. */
+export function flare(p, x, y, L, k, ramp) {
+ if (L < 1) return;
+ const R = ramp.map(hex), n = R.length;
+ for (let i = 0; i < 8; i++) {
+ const an = (i * Math.PI) / 4, len = i % 4 === 0 ? L : i % 2 === 0 ? L * 0.6 : L * 0.3, ca = Math.cos(an), sa = Math.sin(an);
+ for (let d = 0; d <= len; d += 0.5) {
+ const u = d / len;
+ p.dot(x + ca * d, y + sa * d, u < 0.35 ? WHITE : u < 0.7 ? R[n - 2] : R[n - 3], u < 0.6 ? 1 : k * 1.5 * (1 - u) + 0.2);
+ }
+ }
+}
+
+/**
+ * A ring on a tilted plane (sy squashes it: 0.16 lies on the floor, 1 stands up), thickness th inward, alpha k,
+ * colored by depth through the band with ramp (dark to bright). keep(angle) picks which part to draw, so the
+ * far half can go behind things and the near half in front: (g) => Math.sin(g) < 0 is the far half.
+ */
+export function band(p, cx, cy, r, sy, th, k, ramp, keep = () => true, hot = false) {
+ if (r <= 0 || k <= 0) return;
+ const R = ramp.map(hex), n = R.length;
+ for (let j = 0, m = Math.ceil(r * TAU * 1.2); j < m; j++) {
+ const ang = (j / m) * TAU, ca = Math.cos(ang), sa = Math.sin(ang);
+ if (!keep(ang)) continue;
+ for (let o = th; o >= 0; o -= 0.5) {
+ const u = o / th, c = u < 0.15 ? (hot ? WHITE : R[n - 1]) : u < 0.4 ? R[n - 2] : u < 0.7 ? R[n - 3] : R[n - 4];
+ p.dot(cx + ca * (r - o), cy + sa * (r - o) * sy, c, k * (u < 0.4 ? 1.2 : 1.15 - u));
+ }
+ }
+}
+
+/**
+ * A faceted crystal spike standing on (x, base), height h, base width w, leaning lean px at the tip, shaded in
+ * ramp (dark to bright, 6+ steps): a lit ridge, a bright left face, a darker right face, a dark rim.
+ * opts: { a (alpha), white (flash it white), glint (0..1 height of a sweeping highlight, or -1) }.
+ */
+export function crystal(p, x, base, h, w, lean, ramp, opts = {}) {
+ if (h < 1.5) return;
+ const R = ramp.map(hex), n = R.length, C = (i) => R[Math.max(0, n - 1 - i)];
+ const a = opts.a ?? 1, top = base - h, ridge0 = x - w * 0.14, glint = opts.glint ?? -1;
+ const inside = (px, py) => {
+ const u = (base - (py + 0.5)) / h;
+ return u >= 0 && u <= 1 && Math.abs(px + 0.5 - (x + lean * u)) <= (w / 2) * (1 - u) + 0.35;
+ };
+ for (let py = Math.floor(top) - 1; py < Math.ceil(base); py++)
+ for (let px = Math.floor(x - w / 2 - Math.abs(lean) - 2); px <= Math.ceil(x + w / 2 + Math.abs(lean) + 2); px++) {
+ if (!inside(px, py)) {
+ if (inside(px - 1, py) || inside(px + 1, py) || inside(px, py + 1) || (inside(px, py - 1) && py < base - 1)) p.dot(px, py, R[0], a);
+ continue;
+ }
+ if (opts.white) {
+ p.dot(px, py, WHITE, a);
+ continue;
+ }
+ const u = (base - (py + 0.5)) / h, rx = ridge0 + (x + lean - ridge0) * u, c = x + lean * u, hw = (w / 2) * (1 - u) + 0.35, fx = px + 0.5;
+ let col = u > 0.9 ? WHITE : Math.abs(fx - rx) < 0.55 ? C(1)
+ : fx < rx ? (fx - (c - hw) < 1 ? C(1) : (fx - (c - hw)) / Math.max(1, rx - (c - hw)) > 0.55 ? C(2) : C(3))
+ : c + hw - fx < 1.2 ? C(Math.min(n - 2, 6)) : (fx - rx) / Math.max(1, c + hw - rx) > 0.5 ? C(5) : C(4);
+ if (glint >= 0 && fx <= rx + 0.6) {
+ const g = Math.abs(u - glint);
+ if (g < 0.05) col = WHITE;
+ else if (g < 0.1) col = C(1);
+ }
+ p.dot(px, py, col, a);
+ }
+}
diff --git a/src/fx/explosions/small-explosion.js b/src/fx/explosions/small-explosion.js
index 79a4fa2..64b98a2 100644
--- a/src/fx/explosions/small-explosion.js
+++ b/src/fx/explosions/small-explosion.js
@@ -1,91 +1,150 @@
-import { PAL, RAMP, fit, at, burst, fly, flyV, seg, ease, clamp, noise2, TAU, WHITE } from "../../core/index.js";
+// The particle recipe (fire puffs that cool into smoke, sparks, embers, burning brands, grit, rocks, scorch) is
+// adapted from Sprite Fusion's open-source explosion (https://www.spritefusion.com/pixel-art-vfx/explosion),
+// MIT License, Copyright (c) 2026 Hugo Duprez.
+import { Particles, Bits, Lights, Blazes, P, PF, B, Rng, fit, band, clamp, smooth, ease, rand, TAU, WHITE, hex, mix, scale, rgb } from "../../core/index.js";
export const meta = {
- name: "Small explosion",
- desc: "A quick blast: a white flash frame, a lumpy fireball that cools from the edges into rising smoke, a shockwave, sparks and debris.",
- tags: ["explosion", "fire", "smoke", "impact", "one-shot"],
- size: [84, 88],
- origin: [42, 48],
- duration: 1.2,
+ name: "Explosion",
+ desc: "A ground blast: a white flash and shock rings, fire that cools into a rolling smoke column, sparks, burning brands that land and keep burning, tumbling rocks and a glowing scorch.",
+ tags: ["explosion", "fire", "smoke", "debris", "impact", "one-shot"],
+ size: [300, 240],
+ origin: [150, 196],
+ duration: 5.4,
loop: false,
fps: 30,
- bg: "dark",
- options: { palette: PAL.fire, size: 1, seed: 3 },
+ bg: "ground",
+ options: { palette: ["#4a1712", "#c9281f", "#f2561d", "#ff8a2a", "#ffc23d", "#ffe26b", "#fff3a6", "#ffffff"], stone: "#4a3f69", size: 1, seed: 7 },
};
-export function draw(p, t, o) {
- const F = fit(o.palette, 8), SM = RAMP.smoke, S = o.seed, k = o.size;
- const FIRE = [F[2], F[3], F[4], F[5], F[6], F[7], WHITE]; // cool edge .. white-hot core
+const SOOT = hex("#0d0a12"), SOOT2 = hex("#17121d"), OUTLINE = hex("#1a1422"), WARM = rgb(255, 176, 96);
- // puffs: pushed out fast then drifting up; each is both a ball of heat and, later, a ball of smoke
- const puffs = [];
- burst(12, S, (r, i) => {
- const ang = (i / 12) * TAU + r.range(-0.35, 0.35), reach = (i < 2 ? r.range(0, 3) : r.range(5, 13)) * k;
- const age = t - (i < 2 ? 0 : r.range(0.01, 0.07)), life = r.range(0.75, 1.05);
- if (age < 0 || age > life) return;
- const q = age / life, e = ease.outCubic(seg(age, 0, 0.28));
- const x = Math.cos(ang) * reach * e, y = Math.sin(ang) * reach * e * 0.7 - age * age * 26 * k;
- const r0 = r.range(5, 8) * k * (0.5 + 0.7 * e);
- puffs.push({
- x, y,
- fr: r0 * (1 - 0.45 * seg(q, 0.15, 0.6)), heat: 1 - seg(q, 0.05, 0.62),
- sx: x, sy: y - q * q * 16 * k, sr: r0 * (1.05 + 0.8 * q), smoke: seg(q, 0.12, 0.4) * (1 - seg(q, 0.62, 1)),
- });
- });
- // the field: the strongest puff at each pixel decides, with light from the top-left
- const field = (x, y, rk, vk, xk, yk) => {
- let best = 0, lit = 0;
- for (const f of puffs) {
- const dx = x - f[xk], dy = y - f[yk], d = Math.sqrt(dx * dx + dy * dy) / f[rk];
- if (d >= 1) continue;
- const v = (1 - d * d) * f[vk];
- if (v > best) (best = v), (lit = (-dx - dy * 1.4) / f[rk]);
+function stone(c) {
+ c = hex(c);
+ return { light: mix(scale(c, 1.35), WHITE, 0.08), body: c, shade: scale(c, 0.64), dust: mix(scale(c, 1.2), rgb(150, 140, 150), 0.3) };
+}
+
+// the floor under the blast: white-hot, cooling through the fire ramp to soot
+function scorch(p, F, t, rx0, cool, fade) {
+ if (fade <= 0) return;
+ const rx = rx0 * Math.min(1, t / 0.08), ry = 4, heat = [...F].reverse();
+ for (let y = 0; y <= 2; y++)
+ for (let x = Math.floor(-rx); x <= Math.ceil(rx); x++) {
+ const dx = (x + 0.5) / rx, dy = (y + 0.5) / ry, d = Math.sqrt(dx * dx + dy * dy);
+ if (d > 1) continue;
+ const k = rand(x * 31 + y, 3), T = Math.pow(clamp(1 - t / cool), 1.4) * (1.25 - d) - k * 0.35;
+ if (T > 0.06) {
+ const c = heat[Math.min(heat.length - 1, Math.floor((1 - Math.min(1, T)) * (heat.length - 1)))];
+ p.dot(x, y, c, fade);
+ if ((x & 3) === 0) p.glow(x + 0.5, y, 6, c, 0.18 * T * fade);
+ } else p.dot(x, y, d < 0.5 ? SOOT : SOOT2, (d < 0.95 - k * 0.3 ? 1 : 1 - d) * fade);
}
- return [best, lit];
- };
- // debris: dark chunks tossed up and falling (behind the fire, so they show once they're clear of it)
- burst(6, S + 2, (r) => {
- const a = -Math.PI / 2 + r.range(-1.2, 1.2), sp = r.range(50, 95) * k, life = r.range(0.4, 0.55);
- if (t > life) return;
- const [x, y] = fly(0, 0, Math.cos(a) * sp, Math.sin(a) * sp, t, 260, 0.5), s = r.next() < 0.5 ? 2 : 1;
- p.rect(x, y, s, s, SM[1], 1 - seg(t, life * 0.7, life));
- });
- // smoke behind
- p.shade(-36, -42, 36, 30, (x, y, out) => {
- const [v, lit] = field(x, y, "sr", "smoke", "sx", "sy");
- if (v < 0.06) return;
- out.c = at(SM.slice(1, 6), 0.25 + lit * 0.3 + v * 0.35 + noise2(x * 0.4, y * 0.4, S) * 0.12);
- out.a = clamp(v * 4);
- });
- // fire in front
- p.shade(-36, -42, 36, 30, (x, y, out) => {
- const [v, lit] = field(x, y, "fr", "heat", "x", "y");
- if (v < 0.08) return;
- out.c = at(FIRE, v * 0.95 + lit * 0.12 + noise2(x * 0.5, y * 0.5, S + 1) * 0.1);
- out.k = v * 0.25;
+}
+
+// a rock: a lit side, a shaded side, an outline, spinning
+function rock(p, b, st) {
+ const r = 0.6 + b.s * 0.75, fade = Math.min(1, b.life / 0.5), lx = Math.cos(b.a) * r * 0.4, ly = Math.sin(b.a) * r * 0.4;
+ p.shade(b.x - r - 1, b.y - r - 1, b.x + r + 1, b.y + r + 1, (x, y, out) => {
+ const dx = x - b.x, dy = y - b.y, d = Math.hypot(dx * 1.15, dy);
+ if (d > r + 0.9) return;
+ const lit = dx * lx + dy * ly;
+ out.c = d > r ? OUTLINE : lit < -0.4 ? st.light : lit > 0.6 ? st.shade : st.body;
+ out.a = fade;
});
- // flash: one or two frames of solid white, the frame that sells the hit
- if (t < 0.07) {
- p.circle(0, 0, (6 + 40 * t) * k, WHITE);
- p.glow(0, 0, 48 * k, F[6], 0.9);
+}
+
+export function create(o) {
+ const F = fit(o.palette, 8), S = o.size, RAD = 18 * S, POWER = 0.9 * Math.pow(S, 0.8), EARTH = 1.6, st = stone(o.stone);
+ const R = new Rng(o.seed), floor = () => 0;
+ let blazes;
+ const ps = new Particles({ rng: R, ground: floor, sparks: [F[6], F[5], F[3], F[2]], onLand: (x, y) => blazes.add(x, y - 0.25, R.range(0.9, 1.5), R.range(0.55, 0.85)) });
+ blazes = new Blazes(ps);
+ const rocks = new Bits({ ground: floor }), lights = new Lights(), flashes = [], rings = [];
+ const Y = -RAD * 0.3;
+ let t = 0;
+
+ // the fireball
+ flashes.push({ r: RAD * 1.05, life: 0.06, max: 0.06 });
+ rings.push({ r0: RAD * 0.45, r1: RAD * 2.7, life: 0.34, max: 0.34, thick: 3, c: F[5] }, { r0: RAD * 0.3, r1: RAD * 1.6, life: 0.22, max: 0.22, thick: 1.8, c: F[3] });
+ lights.add(0, Y, RAD * 3.4, WARM, 0.6 * POWER, 0.7);
+ lights.add(0, Y, RAD * 1.6, WHITE, 0.6, 0.08);
+ for (let i = 0; i < 5; i++) ps.spawn(P.FIRE, R.range(-2.5, 2.5), Y + R.range(-2.5, 2.5), R.range(-20, 20), R.range(-40, -10), R.range(0.18, 0.3), 0, R.range(RAD * 0.4, RAD * 0.55));
+ for (let i = 0; i < Math.round(28 * POWER); i++) {
+ const a = R.range(0, TAU), d = R.range(0, RAD * 0.55), sp = R.range(40, 210) * POWER;
+ ps.spawn(P.FIRE, Math.cos(a) * d, Y + Math.sin(a) * d, Math.cos(a) * sp, Math.sin(a) * sp * 0.8 - 40, R.range(0.55, 1.15), 0, R.range(RAD * 0.22, RAD * 0.46), 0, R.chance(0.45) ? PF.SMOKES | PF.BIG : 0);
}
- // shockwave: a thin ring racing out, dithering away
- const sw = seg(t, 0.02, 0.24);
- if (sw > 0 && sw < 1) {
- const r = (8 + 22 * ease.outCubic(sw)) * k;
- p.ring(0, 0, r, 1, F[7], 1 - sw * 0.9);
- p.glowRing(0, 0, r, 4, F[5], 0.3 * (1 - sw));
+ for (let i = 0; i < 5; i++) {
+ const a = R.range(0, TAU), d = R.range(RAD * 0.1, RAD * 0.5);
+ ps.spawn(P.SMOKE, Math.cos(a) * d, Y + Math.sin(a) * d, Math.cos(a) * 30, Math.sin(a) * 20 - 30, R.range(0.9, 1.5), rgb(34, 29, 38), R.range(RAD * 0.15, RAD * 0.26), R.range(0.06, 0.2), PF.BIG);
}
- // sparks: streaks along their velocity, falling, cooling yellow to red
- burst(14, S + 1, (r) => {
- const a = r.range(0, TAU), sp = r.range(60, 120) * k, life = r.range(0.3, 0.55);
- if (t > life) return;
- const q = t / life, vx0 = Math.cos(a) * sp, vy0 = Math.sin(a) * sp - 30;
- const [x, y] = fly(0, 0, vx0, vy0, t, 160, 2.5), [vx, vy] = flyV(vx0, vy0, t, 160, 2.5);
- p.line(x, y, x - vx * 0.025, y - vy * 0.025, q < 0.3 ? F[7] : q < 0.6 ? F[5] : F[3]);
- p.light(x, y, F[5], 0.6 * (1 - q));
- });
- // the blast lights everything up, then lets go fast
- const L = 1 - seg(t, 0, 0.5);
- p.glow(0, -2, 42 * k, F[5], 0.55 * L * L);
+ for (let i = 0; i < 5; i++) ps.spawn(P.FIRE, R.range(-RAD * 0.25, RAD * 0.25), Y, R.range(-12, 12), R.range(-180, -100), R.range(0.8, 1.3), 0, R.range(RAD * 0.24, RAD * 0.36), R.range(0, 0.1), R.chance(0.6) ? PF.SMOKES | PF.BIG : 0);
+ for (let i = 0; i < Math.round(10 * POWER); i++) {
+ const a = R.range(0, TAU), d = R.range(0, RAD * 0.7), sp = R.range(15, 100);
+ ps.spawn(P.SMOKE, Math.cos(a) * d, Y + Math.sin(a) * d, Math.cos(a) * sp, Math.sin(a) * sp * 0.6 - 35, R.range(1.8, 2.8), 0, R.range(RAD * 0.26, RAD * 0.44), R.range(0.12, 0.45), PF.BIG);
+ }
+ for (let i = 0; i < Math.round(80 * POWER); i++) {
+ const a = R.range(0, TAU), sp = R.range(140, 380) * POWER;
+ ps.spawn(P.SPARK, 0, Y, Math.cos(a) * sp, Math.sin(a) * sp - 70, R.range(0.18, 0.6));
+ }
+ for (let i = 0; i < Math.round(40 * POWER); i++) {
+ const a = R.range(0, TAU), sp = R.range(30, 150);
+ ps.spawn(P.EMBER, Math.cos(a) * RAD * 0.4, Y + Math.sin(a) * RAD * 0.4, Math.cos(a) * sp, Math.sin(a) * sp - 75, R.range(1.2, 2.6), F[3]);
+ }
+ for (let i = 0; i < Math.round(R.range(9, 14) * Math.max(0, POWER - 0.55)); i++) {
+ const a = -Math.PI / 2 + R.range(-1.35, 1.35), sp = R.range(170, 330);
+ ps.spawn(P.BRAND, 0, Y, Math.cos(a) * sp, Math.sin(a) * sp, R.range(0.7, 1.3));
+ }
+ // the ground's part: dust rolling out along the floor, rocks and grit thrown up, a dust column
+ for (let i = 0; i < Math.round(RAD * 0.5); i++) {
+ const s = R.sign();
+ ps.spawn(P.SMOKE, s * R.range(0, RAD * 0.6), -R.range(1, 5 + RAD * 0.04), s * R.range(3, 9.5) * RAD, -R.range(2, 15), R.range(1.1, 2.0), st.dust, R.range(4, 7) + RAD / 6, R.range(0, 0.06), PF.BIG);
+ }
+ for (let i = 0; i < 26 * Math.min(1.5, S); i++)
+ rocks.add({ kind: B.CHUNK, x: R.range(-0.4, 0.4) * RAD, y: -3, vx: R.range(-9, 9) * RAD * 0.25, vy: -R.range(7, 16) * RAD * 0.9, g: 1, drag: 0.4, bounce: 0.3, life: R.range(1.8, 2.6), a: R.range(0, TAU), va: R.range(-16, 16), s: R.int(1, 3) });
+ for (let i = 0; i < Math.round(EARTH * RAD * 4); i++) {
+ const u = R.range(-1, 1), a = -Math.PI / 2 + u * 0.5, sp = R.range(5, 15) * RAD * (1 - 0.45 * Math.abs(u));
+ ps.spawn(P.GRIT, u * 0.25 * RAD, -1, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1.2, 2.2), R.pick([st.light, st.body, st.body, st.shade]), R.chance(0.45) ? 2 : 1);
+ }
+ for (let i = 0; i < Math.round(EARTH * 12); i++)
+ ps.spawn(P.SMOKE, R.range(-0.3, 0.3) * RAD, -R.range(2, RAD * 0.6), R.range(-15, 15), -R.range(60, 190) * EARTH * 0.6, R.range(1.6, 2.6), st.dust, R.range(5, 9) * Math.sqrt(S) + RAD / 7, R.range(0, 0.15), PF.BIG);
+
+ return {
+ update(dt) {
+ t += dt;
+ for (const a of [flashes, rings]) for (let i = a.length - 1; i >= 0; i--) if ((a[i].life -= dt) <= 0) a.splice(i, 1);
+ rocks.update(dt);
+ // rocks that hit hard kick up dust
+ for (const b of rocks.list)
+ if (b.rest && !b.dusted) {
+ b.dusted = true;
+ for (let i = 0; i < 3; i++) ps.spawn(P.DUST, b.x + R.range(-1.5, 1.5), -0.5, R.sign() * R.range(10, 55) * 0.6, -R.range(2, 22), R.range(0.3, 0.65), st.dust, R.range(1.3, 2.8));
+ }
+ blazes.update(dt);
+ ps.update(dt);
+ lights.update(dt);
+ },
+ drawBack(p) {
+ scorch(p, F, t, 22 * S, 1.2 + RAD / 14, 1 - smooth(meta.duration - 1.2, meta.duration - 0.2, t));
+ ps.draw(p, "back");
+ blazes.drawBack(p);
+ const k = t / 0.5;
+ if (k < 1) band(p, 0, 0.5, 80 * S * ease.outCubic(k), 0.16, Math.max(1, (2 + RAD / 9) * (1 - k)), 1.15 - k, [st.body, st.light, F[3], F[6]], (g) => Math.sin(g) < 0);
+ },
+ draw(p) {
+ const k = t / 0.5;
+ if (k < 1) band(p, 0, 0.5, 80 * S * ease.outCubic(k), 0.16, Math.max(1, (2 + RAD / 9) * (1 - k)), 1.15 - k, [st.body, st.light, F[3], F[6]], (g) => Math.sin(g) >= 0);
+ for (const b of rocks.list) rock(p, b, st);
+ ps.draw(p, "front");
+ for (const f of flashes) {
+ const k2 = f.life / f.max, r = f.r * (0.8 + 0.2 * k2);
+ p.circle(0, Y, r + 1.2, F[2]);
+ p.circle(0, Y, r, k2 > 0.45 ? F[6] : F[5]);
+ p.circle(0, Y, r * 0.6, k2 > 0.45 ? WHITE : F[6]);
+ }
+ for (const r of rings) {
+ const k2 = r.life / r.max, e = 1 - Math.pow(k2, 3);
+ p.ring(0, Y, r.r0 + (r.r1 - r.r0) * e, Math.max(1, r.thick * k2 + 0.4), r.c, Math.min(1, k2 * 1.6));
+ }
+ lights.draw(p);
+ },
+ };
}
diff --git a/src/fx/ice/frost-nova.js b/src/fx/ice/frost-nova.js
index 989641a..9f38ea6 100644
--- a/src/fx/ice/frost-nova.js
+++ b/src/fx/ice/frost-nova.js
@@ -1,80 +1,192 @@
-import { PAL, burst, rng, seg, ease, fly, noise2, TAU, WHITE } from "../../core/index.js";
-import { fit, spike, shard, shardPts, glint } from "./_lib.js";
+import { Particles, Bits, Lights, P, B, Rng, fit, crystal, band, flare, clamp, smooth, ease, rand, TAU, WHITE } from "../../core/index.js";
export const meta = {
name: "Frost nova",
- desc: "A white flash at the feet, then a ring of ice crystals bursts outward across a frosting floor, slows, shatters into spinning shards and melts away.",
- tags: ["ice", "nova", "frost", "aoe", "spell", "burst", "one-shot"],
- size: [128, 64],
- origin: [64, 48],
- duration: 1.3,
+ desc: "Frost spirals into a spinning snowflake, then a wave blooms three rings of ice crystals round the caster; snow drifts, frost creeps, and the ice melts back into the floor.",
+ tags: ["ice", "nova", "aoe", "frost", "magic", "one-shot"],
+ size: [288, 192],
+ origin: [144, 150],
+ duration: 3.4,
loop: false,
fps: 30,
bg: "ground",
- actor: true,
- options: { palette: PAL.ice, radius: 46, count: 18, seed: 22 },
+ actor: 2,
+ options: { palette: ["#151a3d", "#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#a6ecff", "#dcfbff", "#ffffff"], reach: 104, seed: 4 },
};
-const Q = 0.28; // how flat the floor looks
+const CHARGE = 0.42, SPREAD = 0.62, HOLD = 1.95, MELT = 0.7, CORE_Y = -24;
+// three rings of crystals: tall ones hugging the caster, smaller ones further out
+const RINGS = [
+ { q: [0.15, 0.24], h: [24, 32], w: [10, 13], n: 2, kids: 2 },
+ { q: [0.36, 0.52], h: [13, 19], w: [7, 9], n: 3, kids: 1 },
+ { q: [0.62, 0.9], h: [5, 10], w: [4, 6], n: 4, kids: 0 },
+];
-// the ring's radius, how tall its crystals stand, when each one shatters
-const ringR = (t, R) => 4 + (R - 4) * ease.outCubic(seg(t, 0.02, 0.5));
-const brk = (r) => 0.52 + r.range(0, 0.12);
-
-export function drawBack(p, t, o) {
- const I = fit(o.palette), S = o.seed, R = ringR(t, o.radius);
- // the frosted floor inside the ring: pale, veined with cracks, melting away at the end
- const melt = ease.inQuad(seg(t, 0.7, 1.2)), fr = R * (1 - melt);
- if (t > 0.02 && fr > 2)
- p.shade(-fr, -fr * Q, fr, fr * Q, (x, y) => {
- const d = Math.hypot(x / fr, y / (fr * Q));
- if (d > 1 + noise2(Math.atan2(y / Q, x) * 3, 0, S) * 0.08) return;
- // a bright frosted band behind the ring, the floor inside only tinted, veined with frost
- const vein = Math.abs(noise2(x * 0.14, y * 0.45, S + 1)) < 0.07;
- if (d > 0.9) return I[6];
- if (d > 0.72 - melt * 0.3) return vein ? I[6] : I[5];
- return vein ? I[5] : I[3];
- });
- crystals(p, t, o, I, false);
+// frost on the floor: a white crust, little tufts, a dithered bloom under the surface
+function frost(p, C, x0, x1, reach, a, edge) {
+ for (let x = Math.floor(x0); x <= Math.ceil(x1); x++) {
+ const d = Math.abs(x + 0.5), q = d / reach, k = clamp((a * 1.15 - q) / 0.15);
+ if (k <= 0) continue;
+ const h = rand(x, 17), fresh = edge > 0 && d > edge - 3, tuft = h < 0.45 ? Math.round((1 + rand(x, 5) * 3) * (1 - q * 0.6)) : 0, D = (4 + rand(x, 11) * 4) * (1 - q * 0.5);
+ p.dot(x, 0, fresh || h < 0.25 ? WHITE : C[6], k);
+ for (let j = 1; j <= tuft; j++) p.dot(x, -j, j === tuft ? WHITE : C[5], k);
+ if (tuft > 1 && rand(x, 9) < 0.5) p.dot(x + (rand(x, 3) < 0.5 ? -1 : 1), -tuft + 1, C[6], k);
+ for (let j = 1; j <= D; j++) {
+ const v = j / D;
+ p.dot(x, j, rand(x * 31 + j, 7) < 0.06 ? WHITE : v < 0.25 ? C[6] : v < 0.55 ? C[5] : C[4], k * (1.1 - v) * (fresh ? 1.3 : 1));
+ }
+ }
}
-export function draw(p, t, o) {
- const I = fit(o.palette);
- crystals(p, t, o, I, true);
- // the flash at the feet, and light that rides the ring then lets go
- if (t < 0.07) {
- p.ellipse(0, 0, 12, 4, WHITE);
- p.rect(-2, -26, 5, 26, WHITE);
- p.glow(0, -8, 40, I[5], 0.6);
+// the snowflake the cold gathers into: six arms with side branches, spinning, pulsing
+function snowflake(p, C, x, y, L, spin, k) {
+ if (L < 0.8) return;
+ for (let i = 0; i < 6; i++) {
+ const a = spin + (i * TAU) / 6, ca = Math.cos(a), sa = Math.sin(a);
+ for (let d = 0; d <= L; d += 0.5) p.dot(x + ca * d, y + sa * d, d < L * 0.4 ? WHITE : C[6], k + 0.2);
+ if (L > 3)
+ for (const s of [-1, 1]) {
+ const bx = x + ca * L * 0.6, by = y + sa * L * 0.6, ba = a + s * 0.9;
+ for (let d = 0; d <= L * 0.35; d += 0.5) p.dot(bx + Math.cos(ba) * d, by + Math.sin(ba) * d, C[5], k);
+ }
}
- const R = ringR(t, o.radius), L = 1 - seg(t, 0.1, 0.8);
- for (const [x, y] of [[-R, 0], [R, 0], [0, R * Q]]) p.glow(x, y - 3, 18, I[5], 0.18 * L);
- p.glow(0, -6, 30, I[4], 0.2 * L);
+ p.px(x, y, WHITE);
+ p.glow(x, y, 10 + L * 3, C[5], 0.35 + 0.5 * k);
}
-function crystals(p, t, o, I, front) {
- const S = o.seed, n = o.count, R = ringR(t, o.radius);
- for (let i = 0; i < n; i++) {
- const r = rng(S, i), a = (i / n) * TAU + r.range(-0.12, 0.12), s = Math.sin(a);
- if (s > 0 !== front) continue;
- const cx = Math.cos(a), x = cx * R, y = s * R * Q, h = r.range(6, 13) * (front ? 1.1 : 0.85), b = brk(r);
- const up = ease.outBack(seg(t, 0.02, 0.14), 2), J = front ? I : [I[0], I[1], I[1], I[2], I[3], I[4], I[5], I[6]];
- if (t < b) {
- spike(p, x - cx * 1.5, y, 1.6, h * 0.6 * up, -cx * 2 - 1.5, J);
- spike(p, x, y, 2.2, h * up, cx * h * 0.45, J);
- if (r.next() < 0.5) spike(p, x + cx * 2, y, 1.3, h * 0.45 * up, cx * h * 0.6 + 1, J);
- if (t > 0.2 && Math.sin(t * 20 + i * 2.7) > 0.93) glint(p, x + cx * h * 0.3, y - h * 0.7, 1, I[6], WHITE);
- continue;
- }
- // shattered: shards thrown outward and up, spinning, falling, fading
- const age = t - b;
- burst(3, S + 50 + i, (rr) => {
- const life = rr.range(0.35, 0.55);
- if (age > life) return;
- const [sx, sy] = fly(x, y - h * rr.range(0.2, 0.8), cx * rr.range(15, 38) + rr.range(-8, 8), -rr.range(30, 70), age, 300, 1.5);
- if (sy > y - 1) return;
- shard(p, sx, sy, shardPts(rr, rr.range(1.4, 2.4)), rr.range(0, TAU) + age * rr.range(-14, 14), J, 1 - seg(age, life * 0.6, life));
+export function create(o) {
+ const C = fit(o.palette, 8), DIM = [C[0], C[0], C[1], C[2], C[3], C[4], C[5], C[6]], REACH = o.reach;
+ const R = new Rng(o.seed), floor = () => 0;
+ const ps = new Particles({ rng: R, ground: floor, sparks: [C[7], C[6], C[5], C[4]], haze: C[5] });
+ const bits = new Bits({ ground: floor }), lights = new Lights();
+ const front = (t) => (t < CHARGE ? 0 : REACH * (1 - Math.pow(1 - clamp((t - CHARGE) / SPREAD), 3)));
+ const reachedAt = (d) => CHARGE + SPREAD * (1 - Math.cbrt(1 - Math.min(1, d / REACH)));
+ // lay out the crystals: both sides, three rings, alternating back and front rows
+ const sites = [];
+ for (const side of [-1, 1])
+ RINGS.forEach((ring, ri) => {
+ for (let i = 0; i < ring.n; i++) {
+ const q = ring.q[0] + ((ring.q[1] - ring.q[0]) * (i + R.range(0.2, 0.8))) / ring.n, h = R.range(...ring.h), w = R.range(...ring.w);
+ const parts = [{ dx: 0, h, w, lean: side * h * R.range(0.1, 0.28) }];
+ for (let k = 0; k < ring.kids; k++) {
+ const s = k % 2 ? -side : side, kh = h * R.range(0.4, 0.62);
+ parts.unshift({ dx: s * R.range(0.3, 0.5) * w, h: kh, w: w * 0.62, lean: s * kh * R.range(0.35, 0.6) });
+ }
+ sites.push({ x: side * q * REACH, d: q * REACH, h, back: (i + ri + (side > 0 ? 1 : 0)) % 2 === 1, t0: reachedAt(q * REACH) + R.range(0, 0.03), up: false, parts, phase: R.next() });
+ }
});
- if (age < 0.05) p.circle(x, y - h * 0.4, 2.5, WHITE);
- }
+ let t = 0, released = false;
+ const sink = (tt) => smooth(HOLD, HOLD + MELT, tt);
+
+ const drawCrystals = (p, back) => {
+ const m = sink(t);
+ for (const s of sites) {
+ if (!s.up || s.back !== back || m >= 1) continue;
+ const g = ease.outBack(clamp((t - s.t0) / 0.1), 2.6), white = t < s.t0 + 0.03, sw = (((t - s.t0) * 0.7 + s.phase * 3) % 1.6) / 0.5;
+ for (const q of s.parts)
+ crystal(p, s.x + q.dx, back ? -1 : 0, q.h * g * (1 - m), q.w * (1 - m * 0.3), q.lean * g * (1 - m), back ? DIM : C, { white, glint: sw <= 1 ? sw : -1 });
+ }
+ };
+ const ring = (p, back) => {
+ if (t < CHARGE) return;
+ const u = clamp((t - CHARGE) / (SPREAD + 0.15));
+ if (u >= 1) return;
+ band(p, 0, 0, front(t) + 2, 0.16, Math.max(2, 10 * Math.pow(1 - u, 0.7)), u < 0.75 ? 1 : (1 - u) / 0.25, C, (g) => Math.sin(g) < 0 === back, t - CHARGE < 0.1);
+ if (!back) for (const s of [-1, 1]) p.glow(s * (front(t) + 2), -2, 22, C[5], 0.55 * (1 - u));
+ };
+
+ return {
+ update(dt) {
+ t += dt;
+ if (t < CHARGE - 0.06) {
+ // the cold gathers: streaks spiral in to the core, vapour slides in along the floor
+ if (R.chance(0.9)) {
+ const a = R.range(0, TAU), D = R.range(26, 58), T = R.range(0.2, 0.3), v = (D * 3) / (Math.exp(3 * T) - 1);
+ const x = Math.cos(a) * D, y = Math.min(CORE_Y + Math.sin(a) * D * 0.8, -2), l = Math.hypot(x, y - CORE_Y) || 1;
+ ps.spawn(P.STREAK, x, y, (-x / l) * v, ((CORE_Y - y) / l) * v, T, R.chance(0.5) ? C[6] : C[5]);
+ }
+ if (R.chance(0.14)) {
+ const s = R.sign();
+ ps.spawn(P.VAPOUR, s * R.range(28, 60), -R.range(0, 2), -s * R.range(35, 70), -R.range(0, 3), R.range(0.35, 0.5), C[6], R.range(2, 3));
+ }
+ }
+ if (t >= CHARGE && !released) {
+ released = true;
+ lights.add(0, CORE_Y, 84, C[4], 0.8, 0.55);
+ lights.add(0, CORE_Y, 45, WHITE, 0.7, 0.12);
+ for (let i = 0; i < 22; i++) {
+ const a = R.range(-Math.PI, 0.25), sp = R.range(110, 280);
+ bits.add({ kind: B.SHARD, x: R.range(-3, 3), y: CORE_Y, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 0.7, drag: 0.6, bounce: 0.3, life: R.range(0.9, 1.5), a: R.range(0, TAU), va: R.range(-20, 20), s: R.range(1.5, 3.5), c: R.pick([C[7], C[6], C[5]]) });
+ }
+ for (let i = 0; i < 14; i++) {
+ const a = R.range(-Math.PI, 0), sp = R.range(40, 160);
+ ps.spawn(P.FLAKE, 0, CORE_Y, Math.cos(a) * sp, Math.sin(a) * sp, R.range(1.2, 1.8), R.chance(0.6) ? WHITE : C[6], R.range(0.5, 1.6));
+ }
+ }
+ const fr = front(t);
+ if (t > CHARGE && t < CHARGE + SPREAD)
+ for (const s of [-1, 1]) {
+ ps.spawn(P.VAPOUR, s * fr + R.range(-2, 2), -R.range(0, 5), s * R.range(15, 75), -R.range(2, 15), R.range(0.6, 1), R.chance(0.7) ? C[6] : C[5], R.range(3, 5.5) * (1 - 0.4 * (fr / REACH)));
+ if (R.chance(0.45)) ps.spawn(P.FLAKE, s * fr, -2, s * R.range(10, 45), -R.range(30, 85), R.range(1.1, 1.9), R.chance(0.5) ? WHITE : C[6], R.range(0.5, 1.2));
+ }
+ for (const s of sites) {
+ if (!s.up && t >= s.t0) {
+ s.up = true;
+ // each crystal punches up with a spray of shards, a puff and a glint
+ for (let i = 0; i < 2 + Math.round(s.h / 8); i++) {
+ const a = -Math.PI / 2 + R.range(-1.3, 1.3), sp = R.range(60, 200) * (0.5 + s.h / 40);
+ bits.add({ kind: B.SHARD, x: s.x + R.range(-3, 3), y: 0, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp, g: 0.8, drag: 0.6, bounce: 0.3, life: R.range(0.9, 1.6), a: R.range(0, TAU), va: R.range(-18, 18), s: R.range(1.5, 3), c: R.pick([C[7], C[6], C[5]]) });
+ }
+ ps.spawn(P.VAPOUR, s.x, -1, R.range(-30, 30), -R.range(2, 8), R.range(0.5, 0.9), C[6], R.range(2.5, 4));
+ if (s.h > 10) ps.spawn(P.STAR, s.x + R.range(-3, 3), -R.range(4, s.h * 0.8), 0, -3, R.range(0.3, 0.6), C[6], R.range(1, 2.4));
+ }
+ }
+ // while it holds: glints run over the crystals, snow drifts down
+ if (t > CHARGE + 0.2 && t < HOLD + 0.2) {
+ if (R.chance(0.5)) {
+ const s = R.pick(sites);
+ if (s.up) ps.spawn(P.STAR, s.x + R.range(-3, 3), -R.range(2, s.h * 0.9), 0, -3, R.range(0.3, 0.6), R.chance(0.6) ? C[6] : WHITE, R.range(0.6, 2.2));
+ }
+ if (t < HOLD - 0.3 && R.chance(0.16)) ps.spawn(P.FLAKE, R.range(-1, 1) * fr, -R.range(40, 90), R.range(-5, 5), R.range(3, 10), R.range(1.1, 1.5), R.chance(0.5) ? WHITE : C[6], R.range(0.5, 1.4));
+ }
+ // melting: drips run off the crystals, vapour lifts off the floor
+ if (t > HOLD && t < HOLD + MELT) {
+ if (R.chance(0.5)) {
+ const s = R.pick(sites);
+ bits.add({ kind: B.DRIP, x: s.x + R.range(-3, 3), y: -R.range(3, s.h * 0.6 * (1 - sink(t))), vy: 10, g: 0.6, life: 1, c: C[5] });
+ }
+ if (R.chance(0.25)) ps.spawn(P.VAPOUR, R.range(-1, 1) * REACH * 0.8, -R.range(0, 3), R.range(-10, 10), -R.range(6, 16), R.range(0.6, 1), C[5], R.range(3, 5));
+ }
+ ps.update(dt);
+ bits.update(dt);
+ lights.update(dt);
+ },
+ drawBack(p) {
+ const out = 1 - smooth(HOLD + 0.2, HOLD + MELT + 0.6, t), fr = front(t);
+ if (out > 0 && t > CHARGE) frost(p, C, -Math.max(12, fr + 1), Math.max(12, fr + 1), REACH, out, fr);
+ ring(p, true);
+ drawCrystals(p, true);
+ ps.draw(p, "back");
+ },
+ draw(p) {
+ ring(p, false);
+ drawCrystals(p, false);
+ if (t < CHARGE) {
+ const k = t / CHARGE, beat = 1 + 0.25 * Math.exp(-((t - CHARGE * 0.55) ** 2) / 0.002) + 0.3 * Math.exp(-((t - CHARGE * 0.85) ** 2) / 0.002);
+ snowflake(p, C, 0, CORE_Y, (2 + 5.5 * k * k) * beat, t * 4, k);
+ } else if (t < CHARGE + 0.22) {
+ const a = (t - CHARGE) / 0.22;
+ flare(p, 0, CORE_Y, 36 * Math.pow(1 - a, 1.5), 1 - a, C);
+ p.glow(0, CORE_Y, 46, WHITE, 0.6 * (1 - a));
+ }
+ // the frosted floor gives off a cold light while the ice stands
+ if (t > CHARGE) {
+ const k = (1 - smooth(HOLD, HOLD + MELT + 0.3, t)) * (0.85 + 0.15 * Math.sin(t * 2.4)), fr = front(t);
+ for (let i = -3; i <= 3; i++) p.glow((i / 3.5) * fr, -4, 26, C[4], 0.16 * k);
+ }
+ bits.draw(p);
+ ps.draw(p, "front");
+ lights.draw(p);
+ },
+ };
}
diff --git a/src/fx/melee/sword-slash.js b/src/fx/melee/sword-slash.js
index 884614f..b0850e2 100644
--- a/src/fx/melee/sword-slash.js
+++ b/src/fx/melee/sword-slash.js
@@ -1,47 +1,117 @@
-import { fit, at, burst, fly, seg, ease, clamp, smooth, TAU, WHITE } from "../../core/index.js";
+// The crescent, echo, trail, glint and spark recipe is adapted from Sprite Fusion's open-source slash
+// (https://www.spritefusion.com/pixel-art-vfx/slash), MIT License, Copyright (c) 2026 Hugo Duprez.
+import { Particles, P, Rng, fit, sparkle, clamp, smooth, ease, TAU } from "../../core/index.js";
export const meta = {
name: "Sword slash",
- desc: "A fast crescent smear: the white edge whips through in four frames, the tail catches up and dissolves, glints fly off.",
+ desc: "A tilted crescent whips round in two frames, cools from white to deep blue as it trails off, glints at the tip and throws sparks.",
tags: ["melee", "slash", "sword", "combat", "directional", "one-shot"],
- size: [72, 68],
- origin: [26, 42],
- duration: 0.4,
+ size: [136, 104],
+ origin: [44, 92],
+ duration: 0.75,
loop: false,
fps: 30,
bg: "ground",
- actor: true,
- options: { palette: ["#1f4f94", "#2f7fcc", "#58b4ec", "#9bdcff", "#d8f4ff", "#ffffff"], radius: 24, seed: 2 },
+ actor: 2,
+ options: {
+ palette: ["#212f6b", "#2c58aa", "#3a8bd8", "#62c8f4", "#b8c9e8", "#e8f1ff", "#ffffff"],
+ sparks: ["#fff3a6", "#ffe26b", "#ff8a2a", "#f2561d"],
+ radius: 42,
+ seed: 2,
+ },
};
-export function draw(p, t, o) {
- const C = fit(o.palette, 6), R = o.radius, S = o.seed;
- const A0 = -1.95, A1 = 0.62, cx = 1, cy = -13; // from over the shoulder to low in front
- const lead = A0 + (A1 - A0) * ease.outQuart(seg(t, 0, 0.1));
- const tail = A0 + (A1 - A0) * ease.inCubic(seg(t, 0.02, 0.24));
- if (lead - tail > 0.02) {
- const W = 9;
- // the smear: thick behind the edge, tapering to nothing at the tail, a hard white rim outside
- p.arc(cx, cy, R, (u) => W * Math.pow(u, 0.55) * (u > 0.94 ? (1 - u) / 0.06 : 1) + 1, tail, lead,
- (u, v) => (v > 0.82 ? WHITE : at(C.slice(1), v * 0.9 + u * 0.15)),
- (u, v) => clamp(smooth(0, 0.45, u) * (v > 0.82 ? 1.4 : 0.6 + v)) * (1 - seg(t, 0.14, 0.24) * (1 - v)));
- // an inner echo, thinner, a beat behind
- const echo = Math.max(tail, lead - 0.9);
- if (lead - echo > 0.05) p.arc(cx, cy, R - 7, (u) => 2 * u, echo, lead - 0.15, C[3], (u) => 0.7 * u * (1 - seg(t, 0.12, 0.26)));
- // light rides the edge
- const lx = cx + Math.cos(lead) * (R - 3), ly = cy + Math.sin(lead) * (R - 3);
- p.glow(lx, ly, 16, C[3], 0.5 * (1 - seg(t, 0.1, 0.35)));
- }
- // glints thrown off the edge as it passes
- burst(7, S, (r) => {
- const a = A0 + (A1 - A0) * r.range(0.25, 0.95), born = 0.13 * ease.inQuad(r.next()) + 0.01, life = r.range(0.14, 0.22);
- const age = t - born;
- if (age < 0 || age > life) return;
- const sp = r.range(30, 70), dx = Math.cos(a), dy = Math.sin(a);
- const [x, y] = fly(cx + dx * R, cy + dy * R, dx * sp - dy * 25, dy * sp + dx * 25, age, 40, 3);
- const k = age / life;
- if (k < 0.5) p.px(x - 1, y, C[4]), p.px(x + 1, y, C[4]), p.px(x, y - 1, C[4]), p.px(x, y + 1, C[4]);
- p.px(x, y, WHITE);
- p.light(x, y, C[3], 0.5 * (1 - k));
+// a point on the slash's tilted ellipse
+function onArc(s, r, a) {
+ const lx = Math.cos(a) * r, ly = Math.sin(a) * r * s.sy, c = Math.cos(s.rot), n = Math.sin(s.rot);
+ return [s.cx + lx * c - ly * n, s.cy + lx * n + ly * c];
+}
+
+// the smear: thickest just behind the leading edge, tapering to a hair at the tail, white on the outer rim,
+// cooling down the ramp with age and towards the tail; the tail dissolves through the dither
+function crescent(p, s, ta, L, W, age) {
+ if (Math.abs(L) < 0.02 || W < 0.3) return;
+ const R = s.ramp, n = R.length, dir = Math.sign(L), span = Math.abs(L), c = Math.cos(s.rot), sn = Math.sin(s.rot), B = s.R + 2;
+ p.shade(s.cx - B, s.cy - B, s.cx + B, s.cy + B, (x, y, out) => {
+ const dx = x - s.cx, dy = y - s.cy, lx = dx * c + dy * sn, ly = (-dx * sn + dy * c) / s.sy, r = Math.hypot(lx, ly);
+ if (r > s.R + 0.5 || r < s.R - W - 1) return;
+ let u = (dir * (Math.atan2(ly, lx) - ta)) % TAU;
+ if (u < 0) u += TAU;
+ if (u > span) return;
+ const v = u / span, w = W * Math.pow(Math.sin(Math.PI * Math.pow(v, 2.2)), 0.6);
+ if (w < 0.35) return;
+ const q = (s.R - r) / w;
+ if (q < 0 || q > 1) return;
+ // brightest step at the rim while it's young, then darker steps inward, with age and towards the tail
+ const ci = q < 0.22 && age < 0.5 ? 0 : Math.round(q * (n - 1) * 0.75 + age * 2.4 - v * 0.8 + 0.4);
+ out.c = R[n - 1 - clamp(ci, 0, n - 1)];
+ out.a = Math.min(1, v / 0.4);
});
+ for (let u = 0; u <= span; u += 0.3) {
+ const [x, y] = onArc(s, s.R - W * 0.4, ta + dir * u);
+ p.glow(x, y, 5 + W, R[n - 3], 0.22 * (1 - age) * (u / span));
+ }
+}
+
+function drawSlash(p, s, t) {
+ const u = t - s.t0;
+ if (u < 0) return;
+ const span = s.a1 - s.a0, head = ease.outExpo(clamp(u / s.sweep)), tail = smooth(s.sweep + s.hold, s.sweep + s.hold + s.trail, u);
+ const age = clamp(u / (s.sweep + s.hold + s.trail));
+ if (tail < 1) crescent(p, s, s.a0 + span * tail, span * (head - tail), s.W * (1 - tail * 0.55), age);
+ // a dotted trace of the blade's path lingers where the smear has already gone
+ const th = 0.7 * (1 - clamp((u - s.sweep - s.hold) / (s.trail + 0.2)));
+ if (tail > 0.02 && th > 0)
+ for (let k = 0; k <= tail; k += 0.6 / (Math.abs(span) * s.R)) {
+ const [x, y] = onArc(s, s.R - 0.5, s.a0 + span * k);
+ p.dot(x, y, s.ramp[1], th * (0.4 + 0.6 * k));
+ }
+}
+
+function tipOf(s) {
+ const [x, y] = onArc(s, s.R - s.W * 0.3, s.a1), [x2, y2] = onArc(s, s.R - s.W * 0.3, s.a1 + Math.sign(s.a1 - s.a0) * 0.05);
+ const l = Math.hypot(x2 - x, y2 - y) || 1;
+ return { x, y, dx: (x2 - x) / l, dy: (y2 - y) / l };
+}
+
+export function create(o) {
+ const C = fit(o.palette, 7), Rg = new Rng(o.seed), ps = new Particles({ rng: Rg, ground: () => 0, sparks: o.sparks });
+ const R0 = o.radius, a0 = -2.55, a1 = 0.95;
+ // the main smear, and a thinner echo just inside it a beat behind
+ const A = { cx: 6, cy: -26, R: R0, sy: 0.6, rot: -0.38, a0, a1, W: 12, t0: 0, sweep: 0.06, hold: 0.06, trail: 0.24, ramp: C };
+ const E = { ...A, R: R0 * (33 / 42), W: R0 * (4.5 / 42), a0: a0 + (a1 - a0) * 0.1, a1: a1 - (a1 - a0) * (0.15 / 3.5), t0: 0.017, hold: 0.03, trail: 0.2, ramp: C.slice(0, 6) };
+ const tip = tipOf(A);
+ let t = 0, landed = false;
+ return {
+ update(dt) {
+ t += dt;
+ if (!landed && t >= A.sweep) {
+ landed = true;
+ // sparks off the edge where it stops, and bright shavings flung off the arc
+ for (let i = 0; i < 10; i++) {
+ const a = Math.atan2(tip.dy, tip.dx) + Rg.range(-0.5, 0.5), sp = Rg.range(150, 400);
+ ps.spawn(P.SPARK, tip.x, tip.y, Math.cos(a) * sp, Math.sin(a) * sp, Rg.range(0.12, 0.35));
+ }
+ for (let i = 0; i < 16; i++) {
+ const a = a0 + (a1 - a0) * Rg.range(0.3, 1), [x, y] = onArc(A, A.R, a);
+ const ox = x - A.cx, oy = y - A.cy, l = Math.hypot(ox, oy) || 1, sp = Rg.range(30, 100);
+ ps.spawn(P.MOTE, x, y, (ox / l) * sp, (oy / l) * sp - 10, Rg.range(0.25, 0.55), C[4 + Rg.int(0, 1)], 0.6);
+ }
+ }
+ ps.update(dt);
+ },
+ draw(p) {
+ drawSlash(p, E, t);
+ drawSlash(p, A, t);
+ // the tip glints as the edge arrives
+ const g = t - A.sweep * 0.6;
+ if (g > 0 && g < 0.22) sparkle(p, tip.x, tip.y, 9 * ease.outBack(Math.min(1, g / 0.05)) * (1 - g / 0.22), C[5], C[3], 0.6);
+ // light rides the head of the swing
+ if (t < 0.3) {
+ const [x, y] = onArc(A, A.R - 4, A.a0 + (A.a1 - A.a0) * ease.outExpo(clamp(t / A.sweep)));
+ p.glow(x, y, 40, C[3], 0.5 * (1 - t / 0.3));
+ }
+ ps.draw(p);
+ },
+ };
}
diff --git a/tools/check.mjs b/tools/check.mjs
index 2ac01c5..9662381 100644
--- a/tools/check.mjs
+++ b/tools/check.mjs
@@ -50,7 +50,7 @@ for (const id of ids) {
return x >= 0 && y >= 0 && x < W && y < H;
};
const opts = { ...(meta.options ?? {}), seed: meta.options?.seed ?? 1 };
- if (meta.actor) opts.actor = stockActor();
+ if (meta.actor) opts.actor = stockActor(meta.actor === 2 ? 2 : 1);
const n = Math.max(2, Math.round(meta.duration * meta.fps));
let maxPx = 0, spill = 0, spillLight = 0, ms = [], bx0 = Infinity, by0 = Infinity, bx1 = -Infinity, by1 = -Infinity;
const bounds = () => frame.color.forEach((c, j) => {
@@ -123,14 +123,36 @@ for (const id of ids) {
const med = ms[ms.length >> 1];
if (med > 4) notes.push(`slow: ${med.toFixed(1)} ms a frame`);
} else {
- const inst = createFx(mod, { x: meta.origin[0], y: meta.origin[1], ...opts });
- for (let i = 0; i <= n; i++) {
- if (i) inst.update(1 / meta.fps);
- clearFrame(frame);
- inst.draw(frame);
- maxPx = Math.max(maxPx, count(frame.color, (c) => c >>> 24));
- }
+ // a simulation: step it in order, as a game would, and check every frame
+ const run = (seed) => {
+ const inst = createFx(mod, { x: meta.origin[0], y: meta.origin[1], ...opts, seed });
+ const shots = [];
+ for (let i = 0; i <= n; i++) {
+ if (i) inst.update(1 / meta.fps);
+ clearFrame(frame);
+ const t0 = performance.now();
+ inst.draw(frame);
+ ms.push(performance.now() - t0);
+ shots.push(frame.color.slice());
+ maxPx = Math.max(maxPx, count(frame.color, (c, j) => c >>> 24 && inside(j)), count(frame.light, (c, j) => (c & 0xffffff) && inside(j)));
+ const sp = count(frame.color, (c, j) => c >>> 24 && !inside(j));
+ if (sp > spill) (spill = sp), bounds();
+ spillLight = Math.max(spillLight, count(frame.light, (c, j) => (c & 255) + ((c >>> 8) & 255) + ((c >>> 16) & 255) > 90 && !inside(j)));
+ }
+ return shots;
+ };
+ const a = run(opts.seed), b = run(opts.seed);
+ for (const seed of [2, 3, 7]) run(seed);
if (maxPx === 0) errs.push("draws nothing");
+ if (spill > 0) notes.push(`${spill} px drawn outside the ${W}x${H} canvas (drawing spans x ${bx0}..${bx1}, y ${by0}..${by1}): grow size or move origin`);
+ if (spillLight > 60) notes.push(`glow spills ${spillLight} px past the canvas`);
+ if (a.some((s, i) => count(s, (c, j) => c !== b[i][j]) > 0)) errs.push("not deterministic: two runs with the same seed differ");
+ if (!meta.loop) {
+ const left = count(a[a.length - 1], (c, j) => c >>> 24 && inside(j));
+ if (left > 0) notes.push(`${left} px still drawn at t = duration: one-shots should end empty`);
+ }
+ ms.sort((x, y) => x - y);
+ if (ms[ms.length >> 1] > 4) notes.push(`slow: ${ms[ms.length >> 1].toFixed(1)} ms a frame`);
}
} catch (e) {
errs.push(String(e.message ?? e).split("\n")[0]);