Source code
Play itBlock Bloom
Exactly what your browser runs — written by Claude Opus 5.5. 489 lines across 1 file, plus the shared arcade kit (pause menu, audio, scores) every game loads.
games/play/block-bloom.html · 489 lines
<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
<title>Block Bloom — PromptArcade</title>
<style>
html,body{margin:0;height:100%;background:#0b0718;color:#f6f0ff;overflow:hidden;font-family:Manrope,system-ui,sans-serif;touch-action:none;-webkit-user-select:none;user-select:none}
#c{display:block;position:fixed;inset:0}
</style></head><body>
<canvas id="c" aria-label="Block Bloom board"></canvas>
<script>
window.paConfig = {
slug: "block-bloom", title: "Block Bloom", native: true, music: "lofi", unit: "points",
controls: [["← → / A D", "Move"], ["↑ / W / X", "Turn the piece"], ["Z", "Turn the other way"], ["↓ / S", "Drop faster"], ["Space", "Drop now"], ["C / Shift", "Dew drop: change the piece's colour"], ["Touch", "Tap to turn, drag to move, flick down to drop"]]
};
</script>
<script src="/games/play/pa-score.js"></script>
<script src="/games/play/pa-gate.js"></script>
<script src="/games/play/pa-kit.js"></script>
<script>
(() => {
"use strict";
// Falling gem blocks with a garden of twists: you never see which piece comes next (each one appears
// at the top the moment the last one lands); a row cleared in a single colour scores ten times as much
// and goes to Full Bloom, bursting every gem of that colour on the board so the columns cascade down
// and can chain into more rows; and dew drops, earned by clearing rows, recolour the falling piece.
const COLS = 8, ROWS = 14, TAU = Math.PI * 2;
const fx = new PA.Particles(1500), texts = new PA.Texts();
const PAL = [["#ff7eb6", "#c2367a"], ["#ffd36b", "#d68a1a"], ["#7dffb0", "#1fa56a"], ["#6ec8ff", "#2a6fd6"], ["#c49bff", "#6a3dd6"]];
const NAMES = ["PINK", "GOLD", "JADE", "BLUE", "VIOLET"];
const SHAPES = [
[[0, 0], [1, 0], [2, 0], [3, 0]], // I
[[0, 0], [1, 0], [0, 1], [1, 1]], // O
[[0, 0], [1, 0], [2, 0], [1, 1]], // T
[[0, 0], [0, 1], [0, 2], [1, 2]], // L
[[1, 0], [1, 1], [1, 2], [0, 2]], // J
[[1, 0], [2, 0], [0, 1], [1, 1]], // S
[[0, 0], [1, 0], [1, 1], [2, 1]], // Z
[[0, 0], [1, 0], [2, 0]], // short bar
[[0, 0], [1, 0], [0, 1]], // little corner
[[0, 0], [1, 0]], // domino
[[0, 0]] // single gem
];
const WEIGHT = [3, 3, 3, 3, 3, 2.5, 2.5, 2, 1.6, 1.2, .6];
const LINE_PTS = [0, 100, 300, 500, 800];
const SAME_COLOUR = 10;
const DEW_START = 2, DEW_MAX = 3;
let board, piece, score, shownScore, best = 0, lines, level, combo, placed, mono, over, dropT, lockT, lockMoves, bloomT, clearing;
let dew, bursts, bestChain, dewFlash = 0;
try { best = +localStorage.getItem("bb_best") || 0; } catch (e) {}
/* ---------- layout ---------- */
// On a wide screen the score and stats sit in panels beside the board, so the board can use the full
// height; on a narrow one they go above it.
let view = null, ctx = null, L = { cell: 30, bx: 0, by: 0, side: false };
function layout(v) {
const w = v.w, h = v.h, touch = PA.isTouch;
const bottom = touch ? 96 : 22;
const sideW = Math.min(220, Math.max(130, w * .2));
const sideCell = Math.min((w - sideW * 2 - 40) / COLS, (h - 30 - bottom) / ROWS);
const top = 100, topCell = Math.min((w - 24) / COLS, (h - top - bottom) / ROWS);
const side = sideCell >= topCell * .98 && sideCell >= 20;
const cell = Math.max(16, Math.floor(side ? sideCell : topCell));
const t = side ? 18 : top;
L = { cell, side, sideW, bx: Math.round((w - cell * COLS) / 2), by: Math.round(t + (h - t - bottom - cell * ROWS) / 2) };
}
/* ---------- pieces ---------- */
function randShape() {
let tot = 0; for (const w of WEIGHT) tot += w;
let r = Math.random() * tot;
for (let i = 0; i < SHAPES.length; i++) { r -= WEIGHT[i]; if (r <= 0) return i; }
return 0;
}
function size(cells) { let w = 0, h = 0; for (const [x, y] of cells) { w = Math.max(w, x + 1); h = Math.max(h, y + 1); } return { w, h }; }
function rotated(cells, dir) {
const { w, h } = size(cells);
return cells.map(([x, y]) => (dir > 0 ? [h - 1 - y, x] : [y, w - 1 - x]));
}
function fits(cells, px, py) {
for (const [x, y] of cells) {
const X = px + x, Y = py + y;
if (X < 0 || X >= COLS || Y >= ROWS) return false;
if (Y >= 0 && board[Y][X]) return false;
}
return true;
}
function spawn() {
let s = SHAPES[randShape()].map((c) => c.slice());
const turns = (Math.random() * 4) | 0;
for (let i = 0; i < turns; i++) s = rotated(s, 1);
const { w } = size(s);
piece = { cells: s, c: (Math.random() * PAL.length) | 0, x: Math.floor((COLS - w) / 2), y: 0, born: performance.now() };
dropT = 0; lockT = 0; lockMoves = 0;
if (!fits(piece.cells, piece.x, piece.y)) { piece.y = -1; if (!fits(piece.cells, piece.x, piece.y)) { gameOver(); return; } }
PA.sfx("whoosh", { pitch: 1.6, vol: .3 });
}
function gravity() { return Math.max(.07, .85 * Math.pow(.84, level - 1)); }
function reset() {
board = Array.from({ length: ROWS }, () => Array(COLS).fill(null));
score = 0; shownScore = 0; lines = 0; level = 1; combo = 0; placed = 0; mono = 0; over = false; bloomT = 0; clearing = [];
dew = DEW_START; bursts = 0; bestChain = 0;
fx.clear(); texts.clear();
das = { dir: 0, t: 0 };
PA.music.intensity(0);
spawn();
}
/* ---------- moves ---------- */
function move(dx) {
if (!piece || over) return false;
if (!fits(piece.cells, piece.x + dx, piece.y)) return false;
piece.x += dx;
touchLock();
PA.sfx("click", { pitch: 1.6, vol: .25 });
return true;
}
function turn(dir) {
if (!piece || over) return;
const r = rotated(piece.cells, dir);
// turn about the piece's middle rather than its top-left corner (trunc keeps a turn and its undo symmetric)
const a = size(piece.cells), z = size(r);
const cx = Math.trunc((a.w - z.w) / 2), cy = Math.trunc((a.h - z.h) / 2);
// small wall kicks so a piece can turn next to a wall or another block
for (const [kx, ky] of [[0, 0], [-1, 0], [1, 0], [-2, 0], [2, 0], [0, -1], [-1, -1], [1, -1]]) {
if (fits(r, piece.x + cx + kx, piece.y + cy + ky)) {
piece.cells = r; piece.x += cx + kx; piece.y += cy + ky;
touchLock();
PA.sfx("select", { pitch: 1.5, vol: .35 });
return;
}
}
PA.sfx("blip", { pitch: .5, vol: .25 });
}
function touchLock() { if (lockT > 0 && lockMoves < 14) { lockT = 0; lockMoves++; } }
// a dew drop turns the falling piece to the next colour, so a near-finished single-colour row can be kept pure
function recolour() {
if (!piece || over) return;
if (dew <= 0) { PA.sfx("blip", { pitch: .45, vol: .3 }); dewFlash = -1; return; }
dew--; dewFlash = 1;
piece.c = (piece.c + 1) % PAL.length;
piece.born = performance.now() - 120;
PA.sfx("pickup", { pitch: 1.3 + piece.c * .08, vol: .45 });
fx.burst(L.bx + (piece.x + .5) * L.cell, L.by + (piece.y + .5) * L.cell, { n: 10, colors: [PAL[piece.c][0], "#e8fbff"], speed: 160, life: .5, size: 2.5 });
}
function hardDrop() {
if (!piece || over) return;
let n = 0;
while (fits(piece.cells, piece.x, piece.y + 1)) { piece.y++; n++; }
score += n * 2;
PA.shake(2 + Math.min(4, n * .3), .15);
lock();
}
function lock() {
const now = performance.now();
for (const [x, y] of piece.cells) {
const X = piece.x + x, Y = piece.y + y;
if (Y < 0) { gameOver(); return; }
board[Y][X] = { c: piece.c, t: now };
}
placed++;
PA.sfx("thud", { pitch: 1.1 + Math.random() * .2, vol: .55 });
const chain = settle(now, 1);
if (!chain) combo = 0;
piece = null;
spawn();
}
// Clear full rows, burst colours, let the columns cascade and repeat while new rows fill: each round
// of the chain scores more than the last. Returns how many rounds cleared something.
function settle(now, round) {
const full = [];
for (let y = 0; y < ROWS; y++) if (board[y].every(Boolean)) full.push(y);
if (!full.length) return round - 1;
if (round === 1) combo++;
clearRows(full, now, round);
if (round > 1) {
bestChain = Math.max(bestChain, round);
texts.add(L.bx + L.cell * COLS / 2, L.by + L.cell * (full[0] + .5) - 64, "CHAIN ×" + round, { color: "#7dffb0", size: 28, life: 1.4, vy: -24 });
PA.sfx("combo", { pitch: 1 + round * .15 });
}
return round >= 8 ? round : settle(now + 260, round + 1);
}
function clearRows(full, now, round) {
const n = full.length;
let gain = 0, monoRows = 0, monoColour = 0;
const bloomColours = new Set();
const per = (LINE_PTS[Math.min(n, 4)] + Math.max(0, n - 4) * 400) / n;
for (const y of full) {
const c0 = board[y][0].c, same = board[y].every((b) => b.c === c0);
let pts = per * level;
if (same) { pts *= SAME_COLOUR; monoRows++; monoColour = c0; bloomColours.add(c0); }
gain += pts * round;
for (let x = 0; x < COLS; x++) clearing.push({ x, y, c: board[y][x].c, t: now + x * 18, same });
if (same) texts.add(L.bx + L.cell * COLS / 2, L.by + (y + .5) * L.cell, "ALL " + NAMES[c0] + " ×" + SAME_COLOUR, { color: PAL[c0][0], size: 30, life: 1.8, vy: -30 });
}
if (combo > 1 && round === 1) gain += 50 * (combo - 1) * level;
lines += n; mono += monoRows;
if (dew < DEW_MAX) { dew = Math.min(DEW_MAX, dew + 1); dewFlash = 1; }
// drop the rows above
const keep = board.filter((_, y) => !full.includes(y));
while (keep.length < ROWS) keep.unshift(Array(COLS).fill(null));
board = keep;
// Full Bloom: every other gem of a single-colour row's colour bursts too, and the columns cascade
if (bloomColours.size) {
let burst = 0;
for (let y = 0; y < ROWS; y++) for (let x = 0; x < COLS; x++) {
const b = board[y][x];
if (b && bloomColours.has(b.c)) { clearing.push({ x, y, c: b.c, t: now + 200 + burst * 14, same: true }); board[y][x] = null; burst++; }
}
if (burst) {
bursts += burst;
gain += burst * 40 * level * round;
texts.add(L.bx + L.cell * COLS / 2, L.by + L.cell * 5, "FULL BLOOM " + burst + " GEMS", { color: PAL[monoColour][0], size: 22, life: 1.6, vy: -20 });
}
cascade(now + 260);
}
gain = Math.round(gain);
score += gain;
const midY = L.by + (full[0] + .5) * L.cell;
texts.add(L.bx + L.cell * COLS / 2, midY - 30, "+" + gain.toLocaleString(), { color: "#fff", size: 26 + n * 3, life: 1.1 });
if (n >= 2) texts.add(L.bx + L.cell * COLS / 2, midY + 6, ["", "", "DOUBLE!", "TRIPLE!", "FULL BLOOM!"][Math.min(4, n)], { color: "#ffd36b", size: 24, life: 1.2, vy: -30 });
if (combo > 1) texts.add(L.bx + L.cell * COLS / 2, midY + 34, "COMBO ×" + combo, { color: "#c49bff", size: 18, life: 1.1, vy: -40 });
if (monoRows) { PA.sfx("power"); PA.flash(PAL[monoColour][0], 380); PA.shake(10, .4); }
else { PA.sfx(n >= 3 ? "levelup" : "combo", { pitch: .9 + Math.min(.8, combo * .08) }); PA.shake(2 + n * 2, .25); }
const newLevel = 1 + Math.floor(lines / 8);
if (newLevel > level) {
level = newLevel;
texts.add(L.bx + L.cell * COLS / 2, L.by + L.cell * 3, "LEVEL " + level, { color: "#7dffb0", size: 30, life: 1.6, vy: -15 });
PA.sfx("levelup", { pitch: 1.2 });
}
PA.music.intensity(Math.min(1, (level - 1) / 8));
bloomT = 1;
}
// gems fall straight down into any gaps below them
function cascade(t) {
for (let x = 0; x < COLS; x++) {
let to = ROWS - 1;
for (let y = ROWS - 1; y >= 0; y--) {
const b = board[y][x];
if (!b) continue;
if (y !== to) { board[to][x] = b; board[y][x] = null; b.fy = y; b.ft = t; }
to--;
}
}
}
function gameOver() {
if (over) return;
over = true; piece = null;
PA.shake(8, .4);
setTimeout(() => {
PA.sfx("gameover");
if (score > best) { best = score; try { localStorage.setItem("bb_best", best); } catch (e) {} }
PA.gameOver(score, {
kicker: "The garden is full",
title: bestChain > 1 ? "Chain of " + bestChain + "!" : mono ? mono + " single-colour " + (mono === 1 ? "row" : "rows") + "!" : score > 3000 ? "Garden of light!" : "Board full",
stats: [["Lines", lines], ["Same colour", mono], ["Bloomed gems", bursts], ["Best chain", bestChain > 1 ? "×" + bestChain : "—"], ["Level", level], ["Pieces", placed]]
});
if (window.paXP) window.paXP.award("block-bloom", { score, lines });
}, 700);
}
/* ---------- input ---------- */
let das = { dir: 0, t: 0 };
PA.onKey((e) => {
if (over || !piece) return;
const c = e.code;
if (c === "ArrowUp" || c === "KeyW" || c === "KeyX") { e.preventDefault(); if (!e.repeat) turn(1); }
else if (c === "KeyZ" || c === "KeyQ") { if (!e.repeat) turn(-1); }
else if (c === "Space") { e.preventDefault(); if (!e.repeat) hardDrop(); }
else if ((c === "KeyC" || c === "ShiftLeft" || c === "ShiftRight") && !e.repeat) recolour();
else if ((c === "ArrowLeft" || c === "KeyA") && !e.repeat) { move(-1); das = { dir: -1, t: 0 }; }
else if ((c === "ArrowRight" || c === "KeyD") && !e.repeat) { move(1); das = { dir: 1, t: 0 }; }
});
PA.touchControls({
left: [
{ label: "◀", key: "ArrowLeft", code: "ArrowLeft", aria: "Move left" },
{ label: "▶", key: "ArrowRight", code: "ArrowRight", aria: "Move right" }
],
right: [
{ label: "💧", key: "c", code: "KeyC", aria: "Dew drop: change colour" },
{ label: "⟳", key: "ArrowUp", code: "ArrowUp", aria: "Turn piece" },
{ label: "▼", key: "ArrowDown", code: "ArrowDown", aria: "Drop faster" },
{ label: "⤓", key: " ", code: "Space", aria: "Drop now" }
]
});
// Board gestures: tap turns, sideways drag moves a cell at a time, a quick flick down drops.
let g = null;
addEventListener("pointerdown", (e) => {
if (PA.state !== "play" || over || PA.isPaused()) return;
if (e.target.closest && e.target.closest("button,input,#pa-gate,.pa-layer,.pa-tb,.pa-touch")) return;
g = { id: e.pointerId, x0: e.clientX, y0: e.clientY, x: e.clientX, t0: performance.now(), moved: false };
});
addEventListener("pointermove", (e) => {
if (!g || e.pointerId !== g.id || !piece) return;
const step = Math.max(14, L.cell * .8);
while (e.clientX - g.x > step) { move(1); g.x += step; g.moved = true; }
while (g.x - e.clientX > step) { move(-1); g.x -= step; g.moved = true; }
});
addEventListener("pointerup", (e) => {
if (!g || e.pointerId !== g.id) return;
const dt = performance.now() - g.t0, dy = e.clientY - g.y0, dx = e.clientX - g.x0;
if (piece && !over) {
if (dy > L.cell * 2.2 && dt < 450 && Math.abs(dx) < dy) hardDrop();
else if (!g.moved && Math.abs(dx) < 12 && Math.abs(dy) < 12 && dt < 300) turn(1);
}
g = null;
});
addEventListener("pointercancel", () => { g = null; });
/* ---------- update ---------- */
function update(dt) {
fx.update(dt); texts.update(dt);
if (PA.state !== "play" || over || !piece) return;
// held left/right repeats after a short delay
const l = PA.down("ArrowLeft", "KeyA"), r = PA.down("ArrowRight", "KeyD");
const dir = r && !l ? 1 : l && !r ? -1 : 0;
if (dir !== das.dir) das = { dir, t: 0 };
else if (dir) { das.t += dt; while (das.t > .17) { das.t -= .05; if (!move(dir)) break; } }
const soft = PA.down("ArrowDown", "KeyS");
dropT += dt * (soft ? 12 : 1);
const gv = gravity();
while (dropT >= gv && piece) {
dropT -= gv;
if (fits(piece.cells, piece.x, piece.y + 1)) { piece.y++; if (soft) score += 1; lockT = 0; }
else break;
}
if (piece && !fits(piece.cells, piece.x, piece.y + 1)) {
dropT = Math.min(dropT, gv);
lockT += dt;
if (lockT >= .5) lock();
}
}
/* ---------- drawing ---------- */
function rr(x, y, w, h, r) { ctx.beginPath(); ctx.moveTo(x + r, y); ctx.arcTo(x + w, y, x + w, y + h, r); ctx.arcTo(x + w, y + h, x, y + h, r); ctx.arcTo(x, y + h, x, y, r); ctx.arcTo(x, y, x + w, y, r); ctx.closePath(); }
function gem(x, y, s, c, alpha, glow) {
const [a, b] = PAL[c];
ctx.globalAlpha = alpha == null ? 1 : alpha;
if (glow) { ctx.shadowColor = a; ctx.shadowBlur = glow; }
const gr = ctx.createLinearGradient(x, y, x + s, y + s);
gr.addColorStop(0, a); gr.addColorStop(1, b);
ctx.fillStyle = gr;
rr(x + 1.5, y + 1.5, s - 3, s - 3, s * .2); ctx.fill();
ctx.shadowBlur = 0;
ctx.fillStyle = "rgba(255,255,255,.35)"; rr(x + s * .18, y + s * .14, s * .64, s * .2, s * .1); ctx.fill();
ctx.fillStyle = "rgba(0,0,0,.18)"; rr(x + s * .14, y + s * .72, s * .72, s * .12, s * .06); ctx.fill();
ctx.globalAlpha = 1;
}
const petals = Array.from({ length: 40 }, () => ({ x: Math.random(), y: Math.random(), s: Math.random(), r: Math.random() * TAU, c: (Math.random() * PAL.length) | 0 }));
function dewDrops(x, y, r, t) {
for (let i = 0; i < DEW_MAX; i++) {
const cx = x + i * r * 2.6, full = i < dew;
ctx.beginPath();
ctx.moveTo(cx, y - r * 1.5);
ctx.bezierCurveTo(cx + r * 1.1, y - r * .3, cx + r, y + r, cx, y + r);
ctx.bezierCurveTo(cx - r, y + r, cx - r * 1.1, y - r * .3, cx, y - r * 1.5);
if (full) {
const gr = ctx.createLinearGradient(cx, y - r, cx, y + r);
gr.addColorStop(0, "#e8fbff"); gr.addColorStop(1, "#6ec8ff");
ctx.fillStyle = gr; ctx.shadowColor = "#6ec8ff"; ctx.shadowBlur = 8 + Math.max(0, dewFlash) * 16; ctx.fill(); ctx.shadowBlur = 0;
} else { ctx.strokeStyle = dewFlash < -.2 ? "#ff7eb6" : "rgba(185,168,255,.45)"; ctx.lineWidth = 1.5; ctx.stroke(); }
}
}
function label(txt, x, y, size, color, align) {
ctx.textAlign = align || "center"; ctx.font = `700 ${size}px 'JetBrains Mono', monospace`; ctx.fillStyle = color; ctx.fillText(txt, x, y);
}
function hudTop(bx, by, bw, t) {
const sx = bx + bw / 2, sy = by - 52, C = L.cell;
ctx.textAlign = "center";
ctx.font = `800 ${Math.round(Math.min(C * 1.25, 44))}px Manrope, sans-serif`;
ctx.fillStyle = "#fff"; ctx.shadowColor = "#c49bff"; ctx.shadowBlur = 24;
ctx.fillText(Math.round(shownScore).toLocaleString(), sx, sy); ctx.shadowBlur = 0;
const fs = Math.max(10, Math.min(13, C * .42));
label("LV " + level + " · LINES " + lines + " · BEST " + Math.max(best, score).toLocaleString(), sx, sy + 20, fs, "#b9a8ff");
label("DEW", sx - 34, sy + 42, fs, "#8fd8ff", "right");
dewDrops(sx - 18, sy + 37, fs * .45, t);
}
function hudSide(bx, by, bw, bh, t) {
const W = L.sideW, lx = bx - 28 - W / 2, rx = bx + bw + 28 + W / 2;
const big = Math.round(Math.min(46, W * .2)), fs = Math.round(Math.max(11, Math.min(14, W * .075)));
const panel = (cx, y, h) => { ctx.fillStyle = "rgba(20,12,48,.55)"; rr(cx - W / 2, y, W, h, 16); ctx.fill(); ctx.strokeStyle = "rgba(196,155,255,.18)"; ctx.lineWidth = 1; ctx.stroke(); };
// left: score and best
panel(lx, by, big * 2.9);
label("SCORE", lx, by + fs + 14, fs, "#b9a8ff");
ctx.textAlign = "center"; ctx.font = `800 ${big}px Manrope, sans-serif`; ctx.fillStyle = "#fff"; ctx.shadowColor = "#c49bff"; ctx.shadowBlur = 22;
ctx.fillText(Math.round(shownScore).toLocaleString(), lx, by + fs + 22 + big); ctx.shadowBlur = 0;
label("BEST " + Math.max(best, score).toLocaleString(), lx, by + fs + 26 + big + fs * 1.6, fs, "#8f84c8");
// left, lower: how scoring works
const ty = by + big * 2.9 + 18, tips = [["ONE COLOUR ROW", "×10 + FULL BLOOM"], ["BLOOM", "bursts that colour"], ["CASCADE", "chains score more"]];
panel(lx, ty, tips.length * fs * 3.1 + 14);
tips.forEach(([a, b], i) => { label(a, lx, ty + 12 + fs * 1.2 + i * fs * 3.1, fs * .85, "#ffd36b"); label(b, lx, ty + 12 + fs * 2.5 + i * fs * 3.1, fs * .85, "#cfc6ff"); });
// right: level, lines, dew (kept clear of the pause and sound buttons in the top corner)
const ry = by + 58;
panel(rx, ry, fs * 13.5);
const row = (name, val, y) => { label(name, rx, y, fs, "#b9a8ff"); ctx.textAlign = "center"; ctx.font = `800 ${Math.round(fs * 2)}px Manrope, sans-serif`; ctx.fillStyle = "#fff"; ctx.fillText(val, rx, y + fs * 2.3); };
row("LEVEL", level, ry + fs + 14);
row("LINES", lines, ry + fs * 5.6 + 14);
label("DEW DROPS", rx, ry + fs * 10.2 + 14, fs, "#8fd8ff");
dewDrops(rx - fs * 1.2, ry + fs * 12 + 14, fs * .55, t);
label("C / SHIFT recolours", rx, ry + fs * 13.5 + fs * 1.4, fs * .8, "#7f76b0");
}
function render(t) {
const w = view.w, h = view.h, C = L.cell, now = performance.now();
ctx.setTransform(view.dpr, 0, 0, view.dpr, 0, 0);
const bg = ctx.createRadialGradient(w / 2, h * .3, 0, w / 2, h * .3, Math.max(w, h));
bg.addColorStop(0, "#24164a"); bg.addColorStop(1, "#0b0718");
ctx.fillStyle = bg; ctx.fillRect(0, 0, w, h);
for (const p of petals) {
p.y += .0004 * (.5 + p.s); p.r += .01; if (p.y > 1.05) { p.y = -.05; p.x = Math.random(); }
ctx.save(); ctx.translate(p.x * w + Math.sin(t + p.s * 9) * 30, p.y * h); ctx.rotate(p.r);
ctx.fillStyle = PAL[p.c][0]; ctx.globalAlpha = .12 + p.s * .12;
ctx.beginPath(); ctx.ellipse(0, 0, 6 + p.s * 8, 3 + p.s * 3, 0, 0, TAU); ctx.fill(); ctx.restore();
}
ctx.globalAlpha = 1;
if (!board) return;
const sh = PA.shakeOffset();
ctx.save(); ctx.translate(sh.x, sh.y);
const bx = L.bx, by = L.by, bw = C * COLS, bh = C * ROWS;
// score, stats and dew drops: beside the board on wide screens, above it on narrow ones
shownScore += (score - shownScore) * .2;
dewFlash *= .93;
if (L.side) hudSide(bx, by, bw, bh, t); else hudTop(bx, by, bw, t);
// board
ctx.fillStyle = "rgba(10,6,30,.7)"; rr(bx - 8, by - 8, bw + 16, bh + 16, 16); ctx.fill();
ctx.strokeStyle = `rgba(196,155,255,${.25 + bloomT * .55})`; ctx.lineWidth = 2; ctx.stroke();
bloomT = Math.max(0, bloomT - .02);
for (let y = 0; y < ROWS; y++) for (let x = 0; x < COLS; x++) {
ctx.fillStyle = (x + y) % 2 ? "rgba(255,255,255,.03)" : "rgba(255,255,255,.05)";
rr(bx + x * C + 2, by + y * C + 2, C - 4, C - 4, C * .18); ctx.fill();
}
// a row that is still all one colour glows softly, to hint at the ×10
for (let y = 0; y < ROWS; y++) {
const row = board[y], first = row.find(Boolean);
if (!first || row.filter(Boolean).length < 4 || !row.every((b) => !b || b.c === first.c)) continue;
ctx.fillStyle = PAL[first.c][0]; ctx.globalAlpha = .08 + .05 * Math.sin(t * 4);
rr(bx + 1, by + y * C + 1, bw - 2, C - 2, C * .2); ctx.fill(); ctx.globalAlpha = 1;
}
for (let y = 0; y < ROWS; y++) for (let x = 0; x < COLS; x++) {
const b = board[y][x];
if (!b) continue;
const age = (now - b.t) / 1000, pop = age < .18 ? 1 + Math.sin(age / .18 * Math.PI) * .1 : 1;
const s = C * pop, o = (C - s) / 2;
// gems sliding down after a Full Bloom
let yy = y;
if (b.fy != null) {
const k = (now - b.ft) / 240;
if (k >= 1) b.fy = null; else yy = b.fy + (y - b.fy) * (k <= 0 ? 0 : k * k);
}
gem(bx + x * C + o, by + yy * C + o, s, b.c, 1, 0);
}
ctx.save();
ctx.beginPath(); ctx.rect(bx - 2, by - 2, bw + 4, bh + 4); ctx.clip();
if (piece) {
// landing shadow
let gy = piece.y; while (fits(piece.cells, piece.x, gy + 1)) gy++;
ctx.strokeStyle = PAL[piece.c][0]; ctx.lineWidth = 2; ctx.globalAlpha = .45;
for (const [x, y] of piece.cells) {
if (gy + y < 0) continue;
rr(bx + (piece.x + x) * C + 4, by + (gy + y) * C + 4, C - 8, C - 8, C * .18); ctx.stroke();
}
ctx.globalAlpha = 1;
const e = PA.ease.outBack(Math.min(1, (now - piece.born) / 220));
for (const [x, y] of piece.cells) {
const s = C * e, o = (C - s) / 2;
gem(bx + (piece.x + x) * C + o, by + (piece.y + y) * C + o, s, piece.c, 1, 14);
}
}
ctx.restore();
// clearing animation
for (const c of clearing) {
const k = (now - c.t) / 420;
if (k < 0) { gem(bx + c.x * C, by + c.y * C, C, c.c, 1, 22); continue; }
if (!c.burst) { c.burst = true; fx.burst(bx + c.x * C + C / 2, by + c.y * C + C / 2, { n: c.same ? 16 : 7, colors: [PAL[c.c][0], "#fff"], speed: c.same ? 380 : 260, life: c.same ? 1 : .7, size: 3.5, gravity: 300 }); }
if (k < 1) { const s = C * (1 - k) * (1 + k * .5); gem(bx + c.x * C + (C - s) / 2, by + c.y * C + (C - s) / 2, s, c.c, 1 - k, 30); }
}
clearing = clearing.filter((c) => now - c.t < 420);
fx.draw(ctx); texts.draw(ctx);
ctx.restore();
}
view = PA.canvas(document.getElementById("c"), { onResize: layout });
ctx = view.ctx;
PA.onStart(reset);
PA.loop(update, render);
window.__bb = {
get board() { return board; }, get piece() { return piece; }, get score() { return score; }, get lines() { return lines; },
get over() { return over; }, get mono() { return mono; }, move, turn, hardDrop,
// test helper: lay down a row of gems (colour index or null per column)
setRow(y, cols) { board[y] = cols.map((c) => (c == null ? null : { c, t: 0 })); },
setPiece(cells, c, x, y) { piece = { cells, c, x, y, born: 0 }; },
get dew() { return dew; }, get bestChain() { return bestChain; }, recolour,
// test helper: resolve full rows, blooms and cascades now; returns the chain length
settle() { return settle(performance.now(), 1); }
};
})();
</script>
</body></html>