/* ===================================================================== HOOPS BLITZ — Sport on Earth Games arcade Single-file canvas game in the Family Arcade house style. EMBED (inline):
Or serve the matching hoops-blitz.html wrapper in an iframe. CONTROLS (tap/click the court, or press Space): Tap 1 — start the aim sweep. Tap 2 — lock your aim. Tap 3 — lock the power (green zone) and shoot! The hoop slides along its rail (and bobs late in the game) — lead it. The defender jumps: if he swats your ball, the combo dies. SCORING: 90 seconds. Make = 2 pts. Consecutive makes build a combo: combo 3-5 pays 4 pts a make, combo 6+ pays 6. Miss or a block resets the combo. ===================================================================== */ (function () { "use strict"; /* ================= LEADERBOARD BACKEND — UPGRADE HOOK ================= Default: LOCAL board (localStorage top-10) so the game runs standalone. To switch to the shared family KV leaderboard later, set KV_ENABLED to true. The site must then serve the paper's functions/api/arcade.js with "hoops-blitz" added to its GAMES list and ARCADE_KV bound — the fetch calls below already mirror that API exactly: GET /api/arcade/leaderboard?game= -> { game, scores:[{manager,score,at}] } POST /api/arcade/score {game, manager, score} -> { ok, rank } No other code changes are needed. */ var KV_ENABLED = false; var GAME_ID = "hoops-blitz"; var LS_KEY = "fbiArcade." + GAME_ID; var LS_NAME = "fbiArcade.name"; /* Team Account identity (Batch 3.1, Task I, Oct 22, 2026): when a Team Account session is live, ACCT = { username, club } (from the accounts function's GET /api/accounts/me) and score saves go under that identity automatically — the visitor never re-types who they are. The board itself stays exactly what it has always been: this device's localStorage top-10 (KV_ENABLED above remains off — there is no /api/arcade backend on this site, and none is invented here). Guests keep the free-text name flow unchanged. */ var ACCT = null; function escapeHtml(s) { return String(s).replace(/[&<>"']/g, function (c) { return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]; }); } function localScores() { try { return JSON.parse(localStorage.getItem(LS_KEY)) || []; } catch (e) { return []; } } function renderBoard(el, scores) { if (!scores || !scores.length) { el.innerHTML = "
  • No scores yet — be the first!
  • "; return; } el.innerHTML = scores.slice(0, 10).map(function (s, i) { return "
  • #" + (i + 1) + " " + escapeHtml(s.manager) + (s.club ? " · " + escapeHtml(s.club) : "") + " — " + s.score + "
  • "; }).join(""); } function loadBoard(el) { if (!KV_ENABLED) { renderBoard(el, localScores()); return; } fetch("/api/arcade/leaderboard?game=" + encodeURIComponent(GAME_ID)) .then(function (r) { return r.json(); }) .then(function (d) { renderBoard(el, d.scores || []); }) .catch(function () { el.innerHTML = "
  • Could not load scores.
  • "; }); } function saveScore(name, score, msgEl, boardEl) { if (ACCT) name = ACCT.username; name = (name || "").trim(); if (!name) { msgEl.textContent = "Enter your name first!"; return; } try { localStorage.setItem(LS_NAME, name); } catch (e) {} if (!KV_ENABLED) { var scores = localScores(); var entry = { manager: name.slice(0, 40), score: Math.floor(score), at: new Date().toISOString() }; if (ACCT) { entry.club = ACCT.club || ""; entry.account = true; } scores.push(entry); scores.sort(function (a, b) { return b.score - a.score; }); scores = scores.slice(0, 10); try { localStorage.setItem(LS_KEY, JSON.stringify(scores)); } catch (e) {} var rank = scores.indexOf(entry) + 1; msgEl.textContent = rank ? ("Saved! You rank #" + rank + " on this device's board.") : "Score saved!"; renderBoard(boardEl, scores); return; } fetch("/api/arcade/score", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ game: GAME_ID, manager: name, club: ACCT ? (ACCT.club || "") : "", score: Math.floor(score) }) }).then(function (r) { return r.json(); }) .then(function (d) { msgEl.textContent = d.rank ? ("Saved! You rank #" + d.rank + " on the family board.") : "Score saved!"; loadBoard(boardEl); }) .catch(function () { msgEl.textContent = "Could not save score."; }); } /* ================= SHARED ARCADE CSS (injected once per page) ================= */ if (!document.getElementById("hoopsArcadeCss")) { var st = document.createElement("style"); st.id = "hoopsArcadeCss"; st.textContent = ".hoops-arcade{max-width:440px;margin:0 auto;font-family:inherit;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}" + ".hoops-arcade *{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}" + ".hoops-arcade input,.hoops-arcade select{-webkit-user-select:text;user-select:text;-webkit-touch-callout:default}" + ".hoops-arcade .arcade-canvas{display:block;width:100%;max-width:400px;height:auto;margin:0 auto;background:#8a5a2b;border:3px solid var(--line,#d8cfc0);border-radius:8px;touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}" + ".hoops-arcade .arcade-ui{text-align:center;margin:12px 0}" + ".hoops-arcade .arcade-score{font-size:.85rem;margin-bottom:8px}" + ".hoops-arcade .arcade-score b{color:var(--red,#c8102e)}" + ".hoops-arcade .arcade-btn{background:var(--red,#c8102e);color:#fff;border:none;border-radius:6px;padding:10px 24px;font-size:1rem;font-weight:700;cursor:pointer}" + ".hoops-arcade .arcade-btn.small{padding:6px 12px;font-size:.8rem}" + ".hoops-arcade .arcade-btn:disabled{opacity:.5;cursor:default}" + ".hoops-arcade .arcade-msg{min-height:2.4em;font-size:.8rem;color:var(--muted,#666);margin:8px 0}" + ".hoops-arcade .arcade-name{display:flex;gap:8px;justify-content:center;margin:8px 0}" + ".hoops-arcade .arcade-name input{padding:8px;border:1px solid var(--line,#d8cfc0);border-radius:6px;font-size:.9rem;max-width:220px}" + ".hoops-arcade .arcade-board{margin-top:16px}" + ".hoops-arcade .arcade-board h3{font-size:1rem;margin-bottom:8px}" + ".hoops-arcade .arcade-board ol{list-style-position:inside;padding:0}" + ".hoops-arcade .arcade-board li{padding:4px 0;border-bottom:1px solid var(--line,#d8cfc0);font-size:.85rem}"; document.head.appendChild(st); } /* Long-press fix (iOS copy callout on held controls): kill the context menu anywhere inside an arcade mount. Installed once per page. */ if (!window.__hoopsNoCallout) { window.__hoopsNoCallout = true; document.addEventListener("contextmenu", function (e) { var t = e.target; if (t && t.closest && t.closest(".hoops-arcade")) e.preventDefault(); }); } /* ================= MOUNT ================= */ var mount = document.querySelector('[data-hoops-game="' + GAME_ID + '"]'); if (!mount) { mount = document.createElement("div"); mount.setAttribute("data-hoops-game", GAME_ID); var cs = document.currentScript; if (cs && cs.parentNode) cs.parentNode.insertBefore(mount, cs); else document.body.appendChild(mount); } mount.classList.add("hoops-arcade"); mount.innerHTML = '' + '
    ' + '
    Score: 0 • Combo: ×0 • Time: 90s
    ' + '
    ' + '
    Tap the court (or Space): once to start the aim sweep, again to lock aim, a third time to lock power and shoot!
    ' + '
    ' + '
    ' + "
    " + '

    Leaderboard — Hoops Blitz

    1. Loading…
    '; var cv = mount.querySelector("canvas"), ctx = cv.getContext("2d"); var el = { score: mount.querySelector(".sc"), combo: mount.querySelector(".combo"), time: mount.querySelector(".time"), msg: mount.querySelector(".arcade-msg"), start: mount.querySelector(".start"), name: mount.querySelector(".arcade-name input"), save: mount.querySelector(".save"), board: mount.querySelector(".arcade-board ol") }; try { el.name.value = localStorage.getItem(LS_NAME) || ""; } catch (e) {} /* Team Account session check (Task I): non-blocking; any failure simply leaves the guest flow exactly as it was. */ try { fetch("/api/accounts/me", { credentials: "same-origin" }) .then(function (r) { if (!r.ok) throw 0; return r.json(); }) .then(function (d) { if (!d || !d.ok || !d.username) return; ACCT = { username: d.username, club: d.club || "" }; el.name.value = d.username; el.name.readOnly = true; el.name.title = "Signed in — your scores save under your team account"; var hint = document.createElement("div"); hint.className = "arcade-msg acct-hint"; hint.textContent = "🏀 Signed in as " + d.username + (d.club ? " · " + d.club : "") + " — your high scores save under your account, no typing needed."; el.name.parentNode.parentNode.insertBefore(hint, el.name.parentNode); }) .catch(function () {}); } catch (e) {} /* ================= GAME ================= */ var W = 400, H = 480, FLOOR = 436; var state = "idle"; // idle | playing | done var phase = "ready"; // ready | aim | power | flying (sub-states while playing) var score = 0, combo = 0, bestCombo = 0, makes = 0, attempts = 0; var timeLeft = 90, gameStart = 0; var PLAYER = { x: 66, handY: FLOOR - 78 }; var hoop = { x: 285, dir: 1, baseY: 138, y: 138, t: 0 }; var defender = { x: 285, jumpT: 0, nextJump: 1.6, airborne: false }; var aimX = 110, aimDir = 1, lockedAim = 0; var power = 0, powerDir = 1; var ball = null, floaters = [], netJiggle = 0; var GREEN = { lo: 66, hi: 90, c: 78 }; function comboPay() { return combo >= 6 ? 6 : combo >= 3 ? 4 : 2; } function reset() { state = "idle"; phase = "ready"; score = 0; combo = 0; bestCombo = 0; makes = 0; attempts = 0; timeLeft = 90; ball = null; floaters = []; hoop.x = 285; hoop.dir = 1; hoop.t = 0; defender.x = 285; defender.airborne = false; defender.jumpT = 0; defender.nextJump = 1.6; updateUI(); } function updateUI() { el.score.textContent = score; el.combo.textContent = "×" + combo; el.time.textContent = Math.ceil(timeLeft); } function startGame() { reset(); state = "playing"; gameStart = Date.now(); el.start.textContent = "Restart"; el.msg.textContent = "Tap to start your aim sweep — the hoop won't sit still!"; } function tap() { if (state !== "playing") return; if (phase === "ready") { phase = "aim"; aimX = 110; aimDir = 1; el.msg.textContent = "Aim sweeping… tap to lock it where the hoop will be!"; } else if (phase === "aim") { lockedAim = aimX; phase = "power"; power = 0; powerDir = 1; el.msg.textContent = "Aim locked! Tap to stop the power in the green!"; } else if (phase === "power") { launch(); } } function launch() { attempts++; var T = 0.85, g = 620; var hx = PLAYER.x + 12, hy = PLAYER.handY; var vx = (lockedAim - hx) / T; // Perfect vy lands the ball at rim height at t=T. Power nudges vy // gently (+-0.09%/pt): dead-center power crosses the rim plane right // at the aim point, green-edge power crosses ~15px long/short (still // makeable), and wild power misses by a mile. var vyPerfect = (hoop.y - hy - 0.5 * g * T * T) / T; var vy = vyPerfect * (1 + (power - GREEN.c) * 0.0009); ball = { x: hx, y: hy, vx: vx, vy: vy, scored: false, blocked: false, dead: false }; phase = "flying"; el.msg.textContent = "It's up…"; } function makeShot() { var pts = comboPay(); combo++; makes++; if (combo > bestCombo) bestCombo = combo; score += pts; netJiggle = 14; floaters.push({ x: hoop.x, y: hoop.y + 36, text: "+" + pts + (combo >= 3 ? " COMBO ×" + combo + "!" : ""), life: 1 }); el.msg.textContent = combo >= 6 ? "🔥🔥 Can't miss! 6 pts a make!" : combo >= 3 ? "🔥 Combo ×" + combo + " — makes pay 4!" : "Bucket! Combo building…"; updateUI(); } function missShot(why) { if (combo >= 3) floaters.push({ x: hoop.x, y: hoop.y + 36, text: "Combo lost!", life: 1 }); combo = 0; el.msg.textContent = why; updateUI(); } function drawCourt() { // Hardwood + stands ctx.fillStyle = "#5b3a17"; ctx.fillRect(0, 0, W, 90); ctx.fillStyle = "rgba(255,255,255,.13)"; for (var i = 0; i < 40; i++) ctx.fillRect((i * 37) % W, 12 + (i * 13) % 60, 5, 5); ctx.fillStyle = "#b57e3e"; ctx.fillRect(0, 90, W, FLOOR - 90); ctx.fillStyle = "rgba(0,0,0,.05)"; for (var y = 110; y < FLOOR; y += 42) ctx.fillRect(0, y, W, 2); ctx.fillStyle = "#8a5a2b"; ctx.fillRect(0, FLOOR, W, H - FLOOR); ctx.strokeStyle = "rgba(255,255,255,.8)"; ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(0, FLOOR); ctx.lineTo(W, FLOOR); ctx.stroke(); // Hoop rail ctx.strokeStyle = "rgba(0,0,0,.35)"; ctx.lineWidth = 3; ctx.beginPath(); ctx.moveTo(168, 96); ctx.lineTo(392, 96); ctx.stroke(); } function drawHoop() { var x = hoop.x, y = hoop.y; // Hanger ctx.strokeStyle = "#444"; ctx.lineWidth = 3; ctx.beginPath(); ctx.moveTo(x, 96); ctx.lineTo(x, y - 34); ctx.stroke(); // Backboard ctx.fillStyle = "#f4f4f4"; ctx.fillRect(x - 30, y - 34, 60, 40); ctx.strokeStyle = "#c8102e"; ctx.lineWidth = 2; ctx.strokeRect(x - 30, y - 34, 60, 40); ctx.strokeRect(x - 10, y - 22, 20, 15); // Rim ctx.strokeStyle = "#e25822"; ctx.lineWidth = 4; ctx.beginPath(); ctx.moveTo(x - 16, y); ctx.lineTo(x + 16, y); ctx.stroke(); // Net ctx.strokeStyle = "rgba(255,255,255,.9)"; ctx.lineWidth = 1.5; var jig = netJiggle > 0 ? Math.sin(netJiggle * 1.4) * 3 : 0; for (var i = -1; i <= 1; i++) { ctx.beginPath(); ctx.moveTo(x + i * 13, y + 2); ctx.lineTo(x + i * 6 + jig, y + 24); ctx.stroke(); } } function drawPlayer() { var x = PLAYER.x, feet = FLOOR; var Fig = window.HoopsFig || null; if (Fig) { var apP = Fig.appearance('blitz-shooter'); var inHand = !ball && phase !== 'flying'; var poseP = inHand ? 'dribble' : (phase === 'flying' ? 'shoot' : 'idle'); Fig.draw(ctx, { x: PLAYER.x, y: FLOOR, s: 0.88, pose: poseP, t: Date.now() / 1000, ball: poseP !== 'shoot', jersey: '#14418f', num: '23', skin: apP.skin, hair: apP.hair, hairColor: apP.hairColor }); return; } ctx.fillStyle = "rgba(0,0,0,.2)"; ctx.beginPath(); ctx.ellipse(x, feet + 4, 16, 4, 0, 0, 7); ctx.fill(); ctx.fillStyle = "#14418f"; ctx.fillRect(x - 4, feet - 42, 8, 42); // legs hint ctx.beginPath(); ctx.arc(x, feet - 56, 14, 0, 7); ctx.fill(); // jersey body ctx.fillStyle = "#f2c79b"; ctx.beginPath(); ctx.arc(x, feet - 78, 8, 0, 7); ctx.fill(); // head // Shooting arm toward the hoop ctx.strokeStyle = "#f2c79b"; ctx.lineWidth = 5; ctx.beginPath(); ctx.moveTo(x + 6, feet - 62); ctx.lineTo(x + 16, feet - 84); ctx.stroke(); if (!ball && phase !== "flying") { ctx.fillStyle = "#e25822"; ctx.beginPath(); ctx.arc(x + 12, PLAYER.handY, 9, 0, 7); ctx.fill(); ctx.strokeStyle = "rgba(0,0,0,.35)"; ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(x + 12, PLAYER.handY, 9, 0, 7); ctx.stroke(); } } function drawDefender() { var x = defender.x, feet = FLOOR; var lift = defender.airborne ? Math.sin(Math.min(1, defender.jumpT / 0.7) * Math.PI) * 64 : 0; var by = feet - lift; var Fig = window.HoopsFig || null; if (Fig) { var apD = Fig.appearance('blitz-defender'); Fig.draw(ctx, { x: defender.x, y: FLOOR, lift: lift, s: 0.88, pose: defender.airborne ? 'shoot' : 'defend', t: Date.now() / 1000, ball: false, jersey: '#c8102e', num: '9', label: 'DEF', flip: true, skin: apD.skin, hair: apD.hair, hairColor: apD.hairColor }); return; } ctx.fillStyle = "rgba(0,0,0,.2)"; ctx.beginPath(); ctx.ellipse(x, feet + 4, 16, 4, 0, 0, 7); ctx.fill(); ctx.fillStyle = "#c8102e"; ctx.beginPath(); ctx.arc(x, by - 46, 14, 0, 7); ctx.fill(); ctx.fillStyle = "#f2c79b"; ctx.beginPath(); ctx.arc(x, by - 68, 8, 0, 7); ctx.fill(); // Arms — straight up when airborne (block threat), down otherwise ctx.strokeStyle = "#f2c79b"; ctx.lineWidth = 5; ctx.beginPath(); if (defender.airborne) { ctx.moveTo(x - 8, by - 52); ctx.lineTo(x - 12, by - 92); ctx.moveTo(x + 8, by - 52); ctx.lineTo(x + 12, by - 92); } else { ctx.moveTo(x - 8, by - 52); ctx.lineTo(x - 18, by - 34); ctx.moveTo(x + 8, by - 52); ctx.lineTo(x + 18, by - 34); } ctx.stroke(); ctx.fillStyle = "#fff"; ctx.font = "bold 10px sans-serif"; ctx.textAlign = "center"; ctx.fillText("DEF", x, by - 42); } function drawAimAndPower() { if (phase === "aim" || phase === "power") { // Aim reticle at rim height ctx.strokeStyle = phase === "aim" ? "#ffd700" : "#2ecc40"; ctx.lineWidth = 2.5; var ax = phase === "aim" ? aimX : lockedAim; ctx.beginPath(); ctx.arc(ax, hoop.y, 13, 0, 7); ctx.stroke(); ctx.beginPath(); ctx.moveTo(ax - 19, hoop.y); ctx.lineTo(ax - 7, hoop.y); ctx.moveTo(ax + 7, hoop.y); ctx.lineTo(ax + 19, hoop.y); ctx.moveTo(ax, hoop.y - 19); ctx.lineTo(ax, hoop.y - 7); ctx.moveTo(ax, hoop.y + 7); ctx.lineTo(ax, hoop.y + 19); ctx.stroke(); // Projected landing tick on the floor ctx.fillStyle = "rgba(255,215,0,.5)"; ctx.fillRect(ax - 2, FLOOR - 4, 4, 4); } if (phase === "power") { var x = 356, y = 170, hgt = 190; ctx.fillStyle = "rgba(0,0,0,.55)"; ctx.fillRect(x - 6, y - 24, 40, hgt + 52); ctx.fillStyle = "#fff"; ctx.font = "bold 10px sans-serif"; ctx.textAlign = "center"; ctx.fillText("POWER", x + 14, y - 10); ctx.fillStyle = "#333"; ctx.fillRect(x, y, 28, hgt); var gy = y + hgt * (1 - GREEN.hi / 100), gh = hgt * (GREEN.hi - GREEN.lo) / 100; ctx.fillStyle = "#2ecc40"; ctx.fillRect(x, gy, 28, gh); var fh = hgt * power / 100; ctx.fillStyle = power >= GREEN.lo && power <= GREEN.hi ? "#2ecc40" : "#ffd700"; ctx.fillRect(x, y + hgt - fh, 28, fh); ctx.strokeStyle = "#fff"; ctx.lineWidth = 1; ctx.strokeRect(x, y, 28, hgt); } } function draw() { ctx.clearRect(0, 0, W, H); drawCourt(); drawHoop(); drawDefender(); drawPlayer(); drawAimAndPower(); if (ball) { ctx.fillStyle = ball.blocked ? "#999" : "#e25822"; ctx.beginPath(); ctx.arc(ball.x, ball.y, 9, 0, 7); ctx.fill(); ctx.strokeStyle = "rgba(0,0,0,.4)"; ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(ball.x, ball.y, 9, 0, 7); ctx.stroke(); if (combo >= 3) { ctx.font = "12px sans-serif"; ctx.textAlign = "center"; ctx.fillText("🔥", ball.x, ball.y - 13); } } floaters.forEach(function (f) { ctx.globalAlpha = Math.max(0, f.life); ctx.fillStyle = "#ffd700"; ctx.font = "bold 17px sans-serif"; ctx.textAlign = "center"; ctx.fillText(f.text, f.x, f.y); ctx.globalAlpha = 1; }); if (state === "playing") { ctx.fillStyle = "rgba(0,0,0,.45)"; ctx.fillRect(0, 0, W, 18); ctx.fillStyle = timeLeft <= 10 ? "#ff4136" : "#2ecc40"; ctx.fillRect(0, 0, W * Math.max(0, timeLeft) / 90, 18); ctx.fillStyle = "#fff"; ctx.font = "bold 11px sans-serif"; ctx.textAlign = "center"; ctx.fillText(Math.ceil(timeLeft) + "s" + (combo >= 3 ? " • COMBO ×" + combo : ""), W / 2, 13); } if (state === "idle") { ctx.fillStyle = "rgba(0,0,0,.55)"; ctx.fillRect(0, 216, W, 92); ctx.fillStyle = "#fff"; ctx.font = "bold 24px sans-serif"; ctx.textAlign = "center"; ctx.fillText("⚡ HOOPS BLITZ", W / 2, 252); ctx.font = "14px sans-serif"; ctx.fillText("90 seconds — moving hoop, live defender!", W / 2, 276); } if (state === "done") { ctx.fillStyle = "rgba(0,0,0,.72)"; ctx.fillRect(0, 190, W, 128); ctx.fillStyle = "#fff"; ctx.font = "bold 24px sans-serif"; ctx.textAlign = "center"; ctx.fillText("⏰ Time!", W / 2, 226); ctx.font = "16px sans-serif"; ctx.fillText("Final score: " + score, W / 2, 252); ctx.fillText(makes + "/" + attempts + " shooting • Best combo: ×" + bestCombo, W / 2, 276); ctx.font = "13px sans-serif"; ctx.fillText("Enter your name below and Save Score!", W / 2, 300); } } var lastFrame = Date.now(); function loop() { var now = Date.now(); var dt = Math.min(0.05, (now - lastFrame) / 1000); lastFrame = now; if (state === "playing") { timeLeft = Math.max(0, 90 - (now - gameStart) / 1000); el.time.textContent = Math.ceil(timeLeft); var elapsed = 90 - timeLeft; // Hoop motion: faster over time, bob in the last 30s hoop.t += dt; hoop.x += hoop.dir * (55 + elapsed * 1.15) * dt; if (hoop.x > 362) { hoop.x = 362; hoop.dir = -1; } if (hoop.x < 186) { hoop.x = 186; hoop.dir = 1; } hoop.y = hoop.baseY + (timeLeft <= 30 ? Math.sin(hoop.t * 2.4) * 13 : 0); // Defender: shadows the hoop with lag, jumps on a timer defender.x += (hoop.x - defender.x) * Math.min(1, dt * 1.6); defender.nextJump -= dt; if (!defender.airborne && defender.nextJump <= 0) { defender.airborne = true; defender.jumpT = 0; } if (defender.airborne) { defender.jumpT += dt; if (defender.jumpT >= 0.7) { defender.airborne = false; defender.nextJump = 1.5 + Math.random() * 0.9; } } // Aim sweep (paused while a drag is steering the aim point) if (phase === "aim" && !(blitzDrag && blitzDrag.moved)) { aimX += aimDir * 265 * dt; if (aimX > 386) { aimX = 386; aimDir = -1; } if (aimX < 108) { aimX = 108; aimDir = 1; } } // Power oscillation (house pattern; paused while a drag sets it) if (phase === "power" && !(blitzDrag && blitzDrag.moved)) { power += powerDir * 165 * dt; if (power >= 100) { power = 100; powerDir = -1; } if (power <= 0) { power = 0; powerDir = 1; } } // Ball physics if (ball) { ball.vy += 620 * dt; ball.x += ball.vx * dt; ball.y += ball.vy * dt; // Defender block: ball rising through his reach near his x if (!ball.blocked && !ball.scored && defender.airborne && ball.vy < 0) { var reachTop = FLOOR - 64 - 92; // feet - jump lift - arm reach if (Math.abs(ball.x - defender.x) < 26 && ball.y < FLOOR - 60 && ball.y > reachTop) { ball.blocked = true; ball.vx = -ball.vx * 0.4 - 60; ball.vy = 60; missShot("🚫 BLOCKED! The defender swatted it — combo gone."); } } // Score check: descending through the rim if (!ball.scored && !ball.blocked && ball.vy > 0 && Math.abs(ball.x - hoop.x) < 17 && Math.abs(ball.y - hoop.y) < 13) { ball.scored = true; makeShot(); } if (ball.y > FLOOR - 6 || ball.x < -20 || ball.x > W + 20) { if (!ball.scored && !ball.blocked) missShot("Off the mark — combo reset."); ball = null; phase = "ready"; if (timeLeft > 0) el.msg.textContent = combo >= 3 ? "Combo ×" + combo + " alive! Tap to aim again." : "Tap to start your aim sweep!"; } } if (netJiggle > 0) netJiggle--; floaters.forEach(function (f) { f.life -= dt * 0.9; f.y -= 26 * dt; }); floaters = floaters.filter(function (f) { return f.life > 0; }); if (timeLeft <= 0 && phase !== "flying") { state = "done"; el.msg.textContent = "Time! Final score " + score + " — save it to the board!"; } if (timeLeft <= 0 && phase === "flying" && !ball) { state = "done"; el.msg.textContent = "Time! Final score " + score + " — save it to the board!"; } } draw(); requestAnimationFrame(loop); } /* ================= INPUT ================= Tap-to-lock (original) plus drag control (touch overhaul): while the aim sweep or the power meter is live, DRAGGING on the court steers it directly — slide left/right to place the aim point, slide up/down the power bar to set power — and releasing the finger locks it in (the same tap() the tap path uses). A press that never really moves is a plain tap and locks on release. */ var blitzDrag = null; function blitzPos(e) { var r = cv.getBoundingClientRect(); return { x: (e.clientX - r.left) * (W / r.width), y: (e.clientY - r.top) * (H / r.height) }; } function blitzSteer(p) { if (phase === "aim") aimX = Math.max(108, Math.min(386, p.x)); else if (phase === "power") power = Math.max(0, Math.min(100, (360 - p.y) / 190 * 100)); } cv.addEventListener("pointerdown", function (e) { e.preventDefault(); if (state !== "playing") return; if (phase === "aim" || phase === "power") { var p = blitzPos(e); blitzDrag = { x0: p.x, y0: p.y, moved: false }; return; } tap(); }); cv.addEventListener("pointermove", function (e) { if (!blitzDrag) return; var p = blitzPos(e); if (Math.abs(p.x - blitzDrag.x0) + Math.abs(p.y - blitzDrag.y0) > 8) blitzDrag.moved = true; if (blitzDrag.moved) blitzSteer(p); }); function blitzRelease() { if (!blitzDrag) return; blitzDrag = null; if (state === "playing") tap(); } cv.addEventListener("pointerup", blitzRelease); cv.addEventListener("pointercancel", function () { blitzDrag = null; }); window.addEventListener("pointerup", blitzRelease); window.addEventListener("keydown", function (e) { if (e.code === "Space") { if (document.activeElement && /INPUT|BUTTON/.test(document.activeElement.tagName)) return; e.preventDefault(); if (e.repeat) return; if (state !== "playing") { startGame(); return; } tap(); } }); el.start.addEventListener("click", startGame); el.save.addEventListener("click", function () { saveScore(el.name.value, score, el.msg, el.board); }); loadBoard(el.board); reset(); draw(); loop(); })();