Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion game.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const B_PTS = 100; // points per letter
let chars = [];
let dead = [];
let particles = [];
let ripples = [];
let dividers = [];

let ball = {};
Expand Down Expand Up @@ -95,6 +96,7 @@ function initPhysics() {

dead = [];
particles = [];
ripples = [];
bPhase = 'playing';
bLives = B_LIVES_MAX;
bScore = 0;
Expand Down Expand Up @@ -160,6 +162,9 @@ function killChar(ch) {
color: ch.color,
});
}

// Ripple — expanding ring that displaces nearby alive letters as it passes
ripples.push({ x: ch.x + ch.w * 0.5, y: ch.y - ch.h * 0.5, r: 0, strength: 1 });
}

/* ── Prevent nearly-horizontal ball ──────────────────────────────── */
Expand Down Expand Up @@ -285,6 +290,14 @@ function update() {
p.life -= p.decay;
if (p.life <= 0) particles.splice(i, 1);
}

// ── Ripples — expand and fade
for (let i = ripples.length - 1; i >= 0; i--) {
const rp = ripples[i];
rp.r += 4.5;
rp.strength -= 0.03;
if (rp.strength <= 0) ripples.splice(i, 1);
}
}

/* ═══════════════════════════════════════════════════════════════════
Expand Down Expand Up @@ -332,12 +345,24 @@ function draw() {
// ── Alive characters
ctx.textBaseline = 'alphabetic';
ctx.textAlign = 'left';
const RIPPLE_BW = 30; // ring bandwidth (px)
const RIPPLE_AMP = 7; // max vertical displacement (px)
let lastFont = null, lastColor = null;
for (const ch of chars) {
if (!ch.alive) continue;
if (ch.font !== lastFont) { ctx.font = ch.font; lastFont = ch.font; }
if (ch.color !== lastColor) { ctx.fillStyle = ch.color; lastColor = ch.color; }
ctx.fillText(ch.char, ch.x, ch.y);
let dy = 0;
if (ripples.length > 0) {
const cx = ch.x + ch.w * 0.5, cy = ch.y - ch.h * 0.5;
for (const rp of ripples) {
const dwave = Math.hypot(cx - rp.x, cy - rp.y) - rp.r;
if (Math.abs(dwave) < RIPPLE_BW) {
dy += Math.sin((dwave / RIPPLE_BW) * Math.PI) * RIPPLE_AMP * rp.strength;
}
}
}
ctx.fillText(ch.char, ch.x, ch.y + dy);
}

// ── Ball trail
Expand Down
Loading