/* ===================================================================== THREE-POINT SHOOTOUT — Sport on Earth Games arcade Single-file canvas game in the Family Arcade house style. EMBED (inline):
Or serve the matching three-point-shootout.html wrapper in an iframe. CONTROLS: drag / ◀ ▶ arrows to slide along the arc. Hold (pointer on court or SHOOT button, or hold Space) to charge the power meter, release to shoot. SCORING: 60 seconds. Make = 2 pts. Make from a gold money spot = 4. Streak of 3+ = ON FIRE: green zone widens, +1 bonus per make. ===================================================================== */ (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 "three-point-shootout" 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 = "three-point-shootout"; 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 • Streak: 0 • Best streak: 0 • Time: 60s
    ' + '
    ' + '
    ' + '
    Drag or use ◀ ▶ to slide along the arc. Hold to charge the meter, release in the green to score!
    ' + '
    ' + '
    ' + "
    " + '

    Leaderboard — Three-Point Shootout

    1. Loading…
    '; var cv = mount.querySelector("canvas"), ctx = cv.getContext("2d"); var el = { score: mount.querySelector(".sc"), streak: mount.querySelector(".streak"), best: mount.querySelector(".best"), time: mount.querySelector(".time"), msg: mount.querySelector(".arcade-msg"), start: mount.querySelector(".start"), shoot: mount.querySelector(".shoot"), 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; var HOOP = { x: 200, y: 84 }, ARC_R = 205; var SPOTS = [55, 72.5, 90, 107.5, 125]; // money-ball rack angles (deg) var state = "idle"; // idle | playing | done (ball flight is a sub-state) var score = 0, streak = 0, bestStreak = 0, makes = 0, attempts = 0; var timeLeft = 60, gameStart = 0; var theta = 90, targetTheta = 90, keys = {}; var charging = false, power = 0, powerDir = 1; var ball = null, ballTimer = 0, floaters = [], netJiggle = 0, lastShotMoney = false; function shooterPos() { var a = theta * Math.PI / 180; return { x: HOOP.x + ARC_R * Math.cos(a), y: HOOP.y + ARC_R * Math.sin(a) }; } function onMoneySpot() { for (var i = 0; i < SPOTS.length; i++) if (Math.abs(theta - SPOTS[i]) <= 4) return true; return false; } function greenZone() { var half = onMoneySpot() ? 12 : 9; if (streak >= 3) half += 2; // ON FIRE widens the zone return { c: 74, lo: 74 - half, hi: 74 + half }; } function reset() { state = "idle"; score = 0; streak = 0; bestStreak = 0; makes = 0; attempts = 0; timeLeft = 60; theta = 90; targetTheta = 90; charging = false; power = 0; ball = null; floaters = []; updateUI(); } function updateUI() { el.score.textContent = score; el.streak.textContent = streak; el.best.textContent = bestStreak; el.time.textContent = Math.ceil(timeLeft); } function startGame() { reset(); state = "playing"; gameStart = Date.now(); el.start.textContent = "Restart"; el.msg.textContent = "You're live! Slide to a gold spot for money balls worth 4."; } function shoot() { if (state !== "playing" || ball) return; var gz = greenZone(); var p = power, pos = shooterPos(); attempts++; lastShotMoney = onMoneySpot(); var err = Math.abs(p - gz.c); var kind = err <= (gz.hi - gz.c) * 0.35 ? "swish" : err <= (gz.hi - gz.c) ? "make" : err <= (gz.hi - gz.c) + 7 ? "rimout" : "miss"; var tx = HOOP.x, ty = HOOP.y + 6; if (kind === "rimout") { tx += (p < gz.c ? -13 : 13); } if (kind === "miss") { tx += (p < gz.c ? -46 : 46) * (0.7 + Math.random() * 0.5); ty += p < gz.c ? 26 : -6; } ball = { x0: pos.x, y0: pos.y - 26, x1: tx, y1: ty, cx: (pos.x + tx) / 2, cy: Math.min(pos.y, ty) - 130, t: 0, kind: kind, done: false, bx: 0, by: 0, bvx: 0, bvy: 0, bouncing: false }; ballTimer = 0; } function resolveBall() { var kind = ball.kind; if (kind === "swish" || kind === "make") { var pts = lastShotMoney ? 4 : 2; if (streak >= 3) pts += 1; // ON FIRE bonus score += pts; makes++; streak++; if (streak > bestStreak) bestStreak = streak; netJiggle = 14; floaters.push({ x: HOOP.x, y: HOOP.y + 34, text: "+" + pts + (kind === "swish" ? " SWISH!" : ""), life: 1, money: lastShotMoney }); el.msg.textContent = kind === "swish" ? "Nothing but net!" : "Bucket!"; if (streak === 3) el.msg.textContent = "🔥 ON FIRE! Green zone wider, +1 per make!"; if (streak > 3) el.msg.textContent = "🔥 Still burning — streak at " + streak + "!"; } else { streak = 0; floaters.push({ x: HOOP.x, y: HOOP.y + 34, text: kind === "rimout" ? "Off the rim!" : "Miss", life: 1, money: false }); el.msg.textContent = kind === "rimout" ? "So close — rattled out." : "Off target. Reset and fire again!"; } updateUI(); } function drawCourt() { // Hardwood ctx.fillStyle = "#b57e3e"; ctx.fillRect(0, 0, W, H); ctx.fillStyle = "rgba(0,0,0,.05)"; for (var x = 0; x < W; x += 50) ctx.fillRect(x, 0, 2, H); ctx.fillStyle = "#a06c30"; ctx.fillRect(0, 430, W, 50); // Paint + key ctx.fillStyle = "rgba(200,16,46,.20)"; ctx.fillRect(HOOP.x - 49, 0, 98, 190); ctx.strokeStyle = "rgba(255,255,255,.75)"; ctx.lineWidth = 2; ctx.strokeRect(HOOP.x - 49, 0, 98, 190); ctx.beginPath(); ctx.arc(HOOP.x, 190, 49, 0, Math.PI); ctx.stroke(); // Three-point arc + corner lines ctx.beginPath(); ctx.arc(HOOP.x, HOOP.y, ARC_R, 48 * Math.PI / 180, 132 * Math.PI / 180); ctx.stroke(); var a1 = 48 * Math.PI / 180, a2 = 132 * Math.PI / 180; ctx.beginPath(); ctx.moveTo(HOOP.x + ARC_R * Math.cos(a1), HOOP.y + ARC_R * Math.sin(a1)); ctx.lineTo(HOOP.x + ARC_R * Math.cos(a1), 330); ctx.moveTo(HOOP.x + ARC_R * Math.cos(a2), HOOP.y + ARC_R * Math.sin(a2)); ctx.lineTo(HOOP.x + ARC_R * Math.cos(a2), 330); ctx.stroke(); // Money spots SPOTS.forEach(function (deg) { var a = deg * Math.PI / 180; var x = HOOP.x + ARC_R * Math.cos(a), y = HOOP.y + ARC_R * Math.sin(a); ctx.fillStyle = "#ffd700"; ctx.beginPath(); ctx.arc(x, y, 11, 0, 7); ctx.fill(); ctx.fillStyle = "#7a5200"; ctx.font = "bold 12px sans-serif"; ctx.textAlign = "center"; ctx.fillText("★", x, y + 4); }); // Backboard + rim ctx.fillStyle = "#f4f4f4"; ctx.fillRect(HOOP.x - 34, HOOP.y - 30, 68, 26); ctx.strokeStyle = "#c8102e"; ctx.lineWidth = 2; ctx.strokeRect(HOOP.x - 34, HOOP.y - 30, 68, 26); ctx.strokeRect(HOOP.x - 11, HOOP.y - 20, 22, 15); ctx.strokeStyle = "#e25822"; ctx.lineWidth = 4; ctx.beginPath(); ctx.moveTo(HOOP.x - 16, HOOP.y); ctx.lineTo(HOOP.x + 16, HOOP.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(HOOP.x + i * 14, HOOP.y + 2); ctx.lineTo(HOOP.x + i * 7 + jig, HOOP.y + 26); ctx.stroke(); } } function drawShooter() { var pos = shooterPos(); var fire = streak >= 3; // Shadow ctx.fillStyle = "rgba(0,0,0,.2)"; ctx.beginPath(); ctx.ellipse(pos.x, pos.y + 16, 16, 5, 0, 0, 7); ctx.fill(); var Fig = window.HoopsFig || null; if (Fig) { var apS = Fig.appearance('tps-shooter'); Fig.draw(ctx, { x: pos.x, y: pos.y + 15, s: 0.8, pose: 'shoot', t: Date.now() / 1000, ball: !ball, jersey: fire ? '#ff7b00' : '#14418f', num: '30', skin: apS.skin, hair: apS.hair, hairColor: apS.hairColor }); } else { // Body ctx.fillStyle = fire ? "#ff7b00" : "#14418f"; ctx.beginPath(); ctx.arc(pos.x, pos.y + 2, 13, 0, 7); ctx.fill(); // Head ctx.fillStyle = "#f2c79b"; ctx.beginPath(); ctx.arc(pos.x, pos.y - 15, 7, 0, 7); ctx.fill(); // Ball in hands (when not flying) if (!ball) { ctx.fillStyle = "#e25822"; ctx.beginPath(); ctx.arc(pos.x, pos.y - 26, 8, 0, 7); ctx.fill(); ctx.strokeStyle = "rgba(0,0,0,.35)"; ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(pos.x, pos.y - 26, 8, 0, 7); ctx.stroke(); } } if (fire) { ctx.font = "15px sans-serif"; ctx.textAlign = "center"; ctx.fillText("🔥", pos.x, pos.y - 34); } } function drawMeter() { if (!charging) return; var gz = greenZone(); var x = 356, y = 150, hgt = 200; 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); // Green zone band var gy = y + hgt * (1 - gz.hi / 100), gh = hgt * (gz.hi - gz.lo) / 100; ctx.fillStyle = "#2ecc40"; ctx.fillRect(x, gy, 28, gh); // Fill up to current power var fh = hgt * power / 100; ctx.fillStyle = power >= gz.lo && power <= gz.hi ? "#2ecc40" : "#ffd700"; ctx.fillRect(x, y + hgt - fh, 28, fh); ctx.strokeStyle = "#fff"; ctx.lineWidth = 1; ctx.strokeRect(x, y, 28, hgt); } function drawBall() { if (!ball) return; var bx, by; if (!ball.bouncing) { var t = ball.t; bx = (1 - t) * (1 - t) * ball.x0 + 2 * (1 - t) * t * ball.cx + t * t * ball.x1; by = (1 - t) * (1 - t) * ball.y0 + 2 * (1 - t) * t * ball.cy + t * t * ball.y1; } else { bx = ball.bx; by = ball.by; } ctx.fillStyle = "#e25822"; ctx.beginPath(); ctx.arc(bx, by, 9, 0, 7); ctx.fill(); ctx.strokeStyle = "rgba(0,0,0,.4)"; ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(bx, by, 9, 0, 7); ctx.stroke(); ctx.beginPath(); ctx.moveTo(bx - 9, by); ctx.lineTo(bx + 9, by); ctx.stroke(); if (streak >= 3) { ctx.font = "12px sans-serif"; ctx.textAlign = "center"; ctx.fillText("🔥", bx, by - 13); } } function draw() { ctx.clearRect(0, 0, W, H); drawCourt(); drawShooter(); drawBall(); drawMeter(); // Floaters floaters.forEach(function (f) { ctx.globalAlpha = Math.max(0, f.life); ctx.fillStyle = f.money ? "#ffd700" : "#fff"; ctx.font = "bold 17px sans-serif"; ctx.textAlign = "center"; ctx.fillText(f.text, f.x, f.y); ctx.globalAlpha = 1; }); // Clock bar 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) / 60, 18); ctx.fillStyle = "#fff"; ctx.font = "bold 11px sans-serif"; ctx.textAlign = "center"; ctx.fillText(Math.ceil(timeLeft) + "s", W / 2, 13); } if (state === "idle") { ctx.fillStyle = "rgba(0,0,0,.55)"; ctx.fillRect(0, 190, W, 92); ctx.fillStyle = "#fff"; ctx.font = "bold 22px sans-serif"; ctx.textAlign = "center"; ctx.fillText("🏀 THREE-POINT SHOOTOUT", W / 2, 226); ctx.font = "14px sans-serif"; ctx.fillText("60 seconds — how many can you drain?", W / 2, 250); } if (state === "done") { ctx.fillStyle = "rgba(0,0,0,.72)"; ctx.fillRect(0, 168, W, 128); ctx.fillStyle = "#fff"; ctx.font = "bold 24px sans-serif"; ctx.textAlign = "center"; ctx.fillText("⏰ Time!", W / 2, 204); ctx.font = "16px sans-serif"; ctx.fillText("Final score: " + score, W / 2, 230); ctx.fillText(makes + "/" + attempts + " shooting • Best streak: " + bestStreak, W / 2, 254); ctx.font = "13px sans-serif"; ctx.fillText("Enter your name below and Save Score!", W / 2, 278); } } 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, 60 - (now - gameStart) / 1000); el.time.textContent = Math.ceil(timeLeft); // Movement if (keys["ArrowLeft"]) targetTheta = Math.min(130, targetTheta + 62 * dt); if (keys["ArrowRight"]) targetTheta = Math.max(50, targetTheta - 62 * dt); theta += (targetTheta - theta) * Math.min(1, dt * 14); // Charge oscillation if (charging) { power += powerDir * 150 * dt; if (power >= 100) { power = 100; powerDir = -1; } if (power <= 0) { power = 0; powerDir = 1; } } // Ball flight if (ball) { if (!ball.bouncing) { ball.t += dt / 0.6; if (ball.t >= 1) { resolveBall(); if (ball.kind === "swish" || ball.kind === "make") { ball = null; } else { ball.bouncing = true; ball.bx = ball.x1; ball.by = ball.y1; ball.bvx = (ball.x1 < HOOP.x ? -1 : 1) * (40 + Math.random() * 50); ball.bvy = -120; } } } else { ball.bvy += 700 * dt; ball.bx += ball.bvx * dt; ball.by += ball.bvy * dt; ballTimer += dt; if (ballTimer > 0.45 || ball.by > H - 8) ball = null; } } 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 && !ball) { state = "done"; charging = false; el.msg.textContent = "Time! Final score " + score + " — save it to the board!"; } } draw(); requestAnimationFrame(loop); } /* ================= INPUT ================= */ function canvasPos(e) { var rect = cv.getBoundingClientRect(); return { x: (e.clientX - rect.left) * (cv.width / rect.width), y: (e.clientY - rect.top) * (cv.height / rect.height) }; } function aimAt(e) { var p = canvasPos(e); var deg = Math.atan2(p.y - HOOP.y, p.x - HOOP.x) * 180 / Math.PI; if (deg > 0) targetTheta = Math.max(50, Math.min(130, deg)); } var dragging = false; cv.addEventListener("pointerdown", function (e) { e.preventDefault(); if (state !== "playing") return; dragging = true; aimAt(e); if (!ball && !charging) { charging = true; power = 0; powerDir = 1; } }); cv.addEventListener("pointermove", function (e) { if (dragging) aimAt(e); }); function release() { if (charging) { charging = false; shoot(); power = 0; } dragging = false; } cv.addEventListener("pointerup", release); window.addEventListener("pointerup", release); el.shoot.addEventListener("pointerdown", function (e) { e.preventDefault(); if (state === "playing" && !ball && !charging) { charging = true; power = 0; powerDir = 1; } }); el.shoot.addEventListener("pointerup", release); el.shoot.addEventListener("pointerleave", function () { if (charging) release(); }); window.addEventListener("keydown", function (e) { if (e.key === "ArrowLeft" || e.key === "ArrowRight") { keys[e.key] = true; if (state === "playing") e.preventDefault(); } 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; } if (!ball && !charging) { charging = true; power = 0; powerDir = 1; } } }); window.addEventListener("keyup", function (e) { keys[e.key] = false; if (e.code === "Space" && charging) { charging = false; shoot(); power = 0; } }); 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(); })();