Run details
- Model
- minimax/minimax-m3
- Route
- OpenRouter API
- Served by
- Minimax
- Effort
- model default
- Limits
- 60 min · 512,000 output tokens (model max)
- Date
- 24 Oct 2026
- Time
- 12 min 54 s
- Size
- 62 kB
- Tokens
- 275 in, 56,220 out (37,551 thinking)
- List price
- $0.068 at today's price ($0.30 in / $1.20 out per M)
- Paid
- $0.068
Prompt
Make a Breakout game I can play right now with the keyboard or the mouse. Give it several levels, a score and some juice. It must be one complete, self-contained HTML file: inline all CSS and JavaScript, and make no network requests of any kind (no CDNs, web fonts or remote images). Reply with the file in a single ```html code block.
Source
62 kB 2,170 lines Raw
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#070b18">
<title>Neon Breakout</title>
<style>
:root {
color-scheme: dark;
--bg: #070b18;
--panel: rgba(14, 22, 48, 0.78);
--line: rgba(140, 180, 255, 0.16);
--text: #edf6ff;
--muted: #8493b5;
--cyan: #55e6ff;
--pink: #ff4fa3;
--green: #70ff9b;
}
* {
box-sizing: border-box;
}
html,
body {
min-height: 100%;
}
body {
margin: 0;
min-height: 100svh;
display: grid;
place-items: center;
padding: 22px;
overflow-x: hidden;
color: var(--text);
background:
radial-gradient(circle at 18% 8%, rgba(55, 107, 255, 0.2), transparent 35%),
radial-gradient(circle at 86% 78%, rgba(255, 54, 143, 0.13), transparent 35%),
linear-gradient(145deg, #070a16 0%, #090e20 55%, #060812 100%);
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
opacity: 0.24;
background-image:
linear-gradient(rgba(255,255,255,0.018) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,0.018) 1px, transparent 1px);
background-size: 36px 36px;
mask-image: linear-gradient(to bottom, black, transparent 85%);
}
button,
canvas {
-webkit-tap-highlight-color: transparent;
}
button {
font: inherit;
}
.app {
position: relative;
width: min(100%, 990px);
}
.topbar {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 18px;
margin-bottom: 14px;
}
.brand {
display: flex;
align-items: center;
gap: 11px;
min-width: max-content;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
transform: rotate(-8deg);
}
.brand-mark i {
position: absolute;
width: 16px;
height: 8px;
border-radius: 3px;
background: linear-gradient(90deg, var(--cyan), #7e7bff);
box-shadow: 0 0 16px rgba(85, 230, 255, 0.65);
}
.brand-mark i:nth-child(1) { left: 1px; top: 5px; }
.brand-mark i:nth-child(2) { left: 18px; top: 5px; background: linear-gradient(90deg, #8e7cff, var(--pink)); }
.brand-mark i:nth-child(3) { left: 10px; top: 16px; }
.brand-mark i:nth-child(4) { left: 10px; top: 27px; background: linear-gradient(90deg, var(--pink), #ffb14b); }
.brand h1 {
margin: 0;
font-size: clamp(17px, 2.2vw, 23px);
line-height: 1;
letter-spacing: 0.12em;
font-weight: 900;
}
.brand h1 span {
color: var(--cyan);
}
.brand small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.24em;
}
.stats {
justify-self: center;
display: flex;
align-items: stretch;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(9, 15, 33, 0.66);
box-shadow: inset 0 1px rgba(255,255,255,0.04), 0 10px 30px rgba(0,0,0,0.18);
backdrop-filter: blur(12px);
}
.stat {
min-width: 95px;
padding: 8px 15px 9px;
text-align: center;
border-right: 1px solid var(--line);
}
.stat:last-child {
border-right: 0;
}
.stat span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.2em;
}
.stat strong {
display: block;
margin-top: 3px;
color: #f7fbff;
font-size: 15px;
line-height: 1;
letter-spacing: 0.08em;
font-variant-numeric: tabular-nums;
}
#livesValue {
color: var(--pink);
letter-spacing: 0.08em;
}
.actions {
display: flex;
gap: 7px;
}
.btn {
appearance: none;
border: 1px solid rgba(150, 190, 255, 0.18);
border-radius: 10px;
padding: 9px 11px;
color: #c7d4ef;
background: rgba(17, 27, 55, 0.72);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
cursor: pointer;
transition: 140ms ease;
}
.btn:hover:not(:disabled) {
color: white;
border-color: rgba(85, 230, 255, 0.48);
background: rgba(28, 47, 84, 0.85);
transform: translateY(-1px);
}
.btn:active:not(:disabled) {
transform: translateY(1px);
}
.btn:disabled {
opacity: 0.36;
cursor: default;
}
.game-card {
position: relative;
overflow: hidden;
border: 1px solid rgba(131, 183, 255, 0.2);
border-radius: 20px;
background: #070b18;
box-shadow:
0 28px 80px rgba(0, 0, 0, 0.48),
0 0 0 1px rgba(255,255,255,0.025) inset,
0 0 60px rgba(56, 90, 255, 0.09);
}
.canvas-wrap {
position: relative;
width: 100%;
aspect-ratio: 3 / 2;
overflow: hidden;
background: #070b18;
}
canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: crosshair;
outline: none;
}
canvas:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: -5px;
}
.scanlines {
position: absolute;
inset: 0;
pointer-events: none;
opacity: 0.1;
mix-blend-mode: soft-light;
background: repeating-linear-gradient(
to bottom,
transparent 0,
transparent 3px,
rgba(255,255,255,0.16) 4px
);
}
.statusbar {
height: 42px;
display: grid;
grid-template-columns: 1fr minmax(150px, 260px) auto;
align-items: center;
gap: 16px;
padding: 0 17px;
border-top: 1px solid var(--line);
background: linear-gradient(90deg, rgba(12,19,40,0.96), rgba(9,14,31,0.96));
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
}
.status-copy {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
#statusText {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.status-dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px currentColor;
}
.progress-wrap {
display: flex;
align-items: center;
gap: 9px;
}
.progress-track {
flex: 1;
height: 5px;
overflow: hidden;
border-radius: 99px;
background: rgba(255,255,255,0.07);
}
.progress-track i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), #a47aff, var(--pink));
box-shadow: 0 0 12px rgba(85, 230, 255, 0.6);
transition: width 250ms ease;
}
#comboText {
min-width: 76px;
text-align: right;
color: #7283a7;
transition: color 120ms ease, transform 120ms ease;
}
#comboText.hot {
color: #ffd05b;
transform: scale(1.08);
}
.controls {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 8px 20px;
padding: 15px 8px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.controls span {
display: inline-flex;
align-items: center;
gap: 7px;
}
kbd {
min-width: 23px;
padding: 3px 7px;
border: 1px solid rgba(164, 195, 255, 0.2);
border-bottom-color: rgba(164, 195, 255, 0.34);
border-radius: 6px;
color: #dce8ff;
background: rgba(18, 28, 55, 0.82);
box-shadow: 0 2px 0 rgba(0,0,0,0.35);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
body {
padding: 10px;
}
.topbar {
grid-template-columns: 1fr auto;
gap: 10px;
}
.stats {
grid-column: 1 / -1;
grid-row: 2;
width: 100%;
}
.stat {
flex: 1;
min-width: 0;
padding-inline: 8px;
}
.actions {
grid-column: 2;
grid-row: 1;
}
.btn {
padding: 9px;
}
.statusbar {
grid-template-columns: 1fr auto;
}
.progress-wrap {
display: none;
}
}
@media (max-width: 480px) {
.brand small {
display: none;
}
.brand h1 {
font-size: 16px;
}
.brand-mark {
transform: scale(0.84) rotate(-8deg);
}
.btn {
padding: 8px 7px;
font-size: 9px;
}
.stat strong {
font-size: 12px;
}
.stat {
padding-inline: 4px;
}
.statusbar {
padding-inline: 10px;
}
.controls {
gap: 7px 12px;
font-size: 10px;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand" aria-label="Neon Breakout">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div>
<h1>NEON <span>BREAKOUT</span></h1>
<small>Eight circuits. One signal.</small>
</div>
</div>
<div class="stats" aria-label="Game statistics">
<div class="stat"><span>LEVEL</span><strong id="levelValue">01 / 08</strong></div>
<div class="stat"><span>SCORE</span><strong id="scoreValue">000000</strong></div>
<div class="stat"><span>BEST</span><strong id="bestValue">000000</strong></div>
<div class="stat"><span>LIVES</span><strong id="livesValue">♥♥♥♡♡</strong></div>
</div>
<div class="actions">
<button class="btn" id="soundBtn" type="button" aria-pressed="true">♪ SOUND ON</button>
<button class="btn" id="pauseBtn" type="button">Ⅱ PAUSE</button>
<button class="btn" id="restartBtn" type="button">↻ RESTART</button>
</div>
</header>
<main class="game-card">
<div class="canvas-wrap">
<canvas id="game" width="960" height="640" tabindex="0" aria-label="Neon Breakout game. Move with the mouse or arrow keys. Press Space to launch." aria-describedby="controls">
Your browser needs HTML canvas support to play Neon Breakout.
</canvas>
<div class="scanlines" aria-hidden="true"></div>
</div>
<div class="statusbar">
<div class="status-copy">
<span class="status-dot" id="statusDot" aria-hidden="true"></span>
<span id="statusText">AWAITING INPUT</span>
</div>
<div class="progress-wrap">
<span>BREAKDOWN</span>
<div class="progress-track"><i id="progressFill"></i></div>
</div>
<div id="comboText">COMBO —</div>
</div>
</main>
<footer class="controls" id="controls">
<span><kbd>MOUSE</kbd> move paddle</span>
<span><kbd>←</kbd><kbd>→</kbd> or <kbd>A</kbd><kbd>D</kbd> move</span>
<span><kbd>SPACE</kbd> launch / fire</span>
<span><kbd>P</kbd> pause</span>
<span><kbd>R</kbd> restart</span>
</footer>
<div id="live" class="sr-only" aria-live="polite"></div>
</div>
<script>
(() => {
"use strict";
const W = 960;
const H = 640;
const STEP = 1 / 120;
const BALL_R = 8;
const PADDLE_BASE = 122;
const PADDLE_WIDE = 198;
const PADDLE_Y = 574;
const PLAY = { left: 28, right: 932, top: 28, bottom: 624 };
const GRID = { x: 48, y: 82, width: 864, cols: 12, gap: 6, height: 25, rowGap: 7 };
const LEVELS = [
{
name: "FIRST CIRCUIT",
hint: "A warm-up for your reflexes",
accent: "#55e6ff",
palette: ["#42ddff", "#6c8cff", "#a66bff", "#ff62b6", "#b8ff62"],
rows: [
"111111111111",
"............",
"111111111111",
"............",
"............"
]
},
{
name: "PRISM WALL",
hint: "Watch the angles change",
accent: "#a779ff",
palette: ["#48e6ff", "#8d72ff", "#c75cff", "#ff5ca7", "#ffb84f"],
rows: [
"121212121212",
"212121212121",
"121212121212",
"212121212121"
]
},
{
name: "PYRAMID PROTOCOL",
hint: "Heavy bricks hide underneath",
accent: "#ff59a7",
palette: ["#42e6ff", "#667cff", "#a86bff", "#ff5aab", "#c4ff59"],
rows: [
"....1111....",
"...222222...",
"..33333333..",
".1111111111.",
"111111111111"
]
},
{
name: "HARD SHELL",
hint: "Crack the reinforced core",
accent: "#ff934d",
palette: ["#4ee9ff", "#6f8cff", "#b45fff", "#ff665c", "#ffd44e"],
rows: [
"333333333333",
".2222222222.",
"..11111111..",
"...111111...",
"....2222...."
]
},
{
name: "SPLIT DECISION",
hint: "Precision beats brute force",
accent: "#b9ff52",
palette: ["#45e5ff", "#697fff", "#ad65ff", "#ff596f", "#e5ff4f"],
rows: [
"11........11",
".22......22.",
"..33....33..",
"...44..44...",
"....5555...."
]
},
{
name: "THE FORTRESS",
hint: "Find the weak points",
accent: "#ff5c71",
palette: ["#4be5ff", "#687fff", "#ad64ff", "#ff5a72", "#ffb64f"],
rows: [
"333333333333",
"111111111111",
".22......22.",
"..2..11..2..",
"....1111....",
"............",
"222222222222"
]
},
{
name: "STARBURST",
hint: "A sparse field of dangerous stars",
accent: "#62dcff",
palette: ["#55edff", "#7387ff", "#b96aff", "#ff617e", "#d9ff57"],
rows: [
"1..1..1..1..",
".2..2..2..2.",
"..3..3..3...",
"...4..4..4..",
"....5..5....",
"............",
"111111111111"
]
},
{
name: "FINAL CORE",
hint: "Break everything. Finish the signal",
accent: "#ffe45e",
palette: ["#5aeaff", "#7086ff", "#b35fff", "#ff5a76", "#ffe052"],
rows: [
"333333333333",
"122222222221",
"121111111121",
"121......121",
"121.2222.121",
"121222222221",
"121111111121"
]
}
];
const POWERUPS = {
wide: { color: "#55e6ff", icon: "W", label: "WIDE PADDLE" },
multi: { color: "#ff5bd5", icon: "M", label: "MULTIBALL" },
slow: { color: "#ffe45e", icon: "S", label: "SLOW MOTION" },
rapid: { color: "#ff914d", icon: "L", label: "LASER READY" },
life: { color: "#70ff9b", icon: "+", label: "EXTRA LIFE" }
};
const canvas = document.getElementById("game");
const ctx = canvas.getContext("2d");
const ui = {
level: document.getElementById("levelValue"),
score: document.getElementById("scoreValue"),
best: document.getElementById("bestValue"),
lives: document.getElementById("livesValue"),
sound: document.getElementById("soundBtn"),
pause: document.getElementById("pauseBtn"),
restart: document.getElementById("restartBtn"),
status: document.getElementById("statusText"),
dot: document.getElementById("statusDot"),
combo: document.getElementById("comboText"),
progress: document.getElementById("progressFill"),
live: document.getElementById("live")
};
let scaleX = 1;
let scaleY = 1;
let state = "menu";
let levelIndex = 0;
let score = 0;
let lives = 3;
let best = loadBest();
let bricks = [];
let balls = [];
let particles = [];
let texts = [];
let pickups = [];
let bolts = [];
let totalBricks = 0;
let bricksDestroyedThisLevel = 0;
let pendingClear = false;
let combo = 0;
let comboTimer = 0;
let wideTimer = 0;
let slowTimer = 0;
let rapidTimer = 0;
let laserCooldown = 0;
let levelClearTimer = 0;
let levelClearBonus = 0;
let levelClearLife = false;
let levelBannerTimer = 0;
let shake = 0;
let whiteFlash = 0;
let redFlash = 0;
let time = 0;
let hudClock = 0;
let bestSaveTimer = 0;
let controlMode = "keyboard";
let soundOn = true;
let audioCtx = null;
const paddle = {
x: (W - PADDLE_BASE) / 2,
y: PADDLE_Y,
w: PADDLE_BASE,
h: 15,
vx: 0
};
const pointer = {
active: false,
down: false,
targetX: W / 2
};
const keys = new Set();
const stars = Array.from({ length: 76 }, () => ({
x: Math.random() * W,
y: 30 + Math.random() * (H - 50),
size: Math.random() < 0.85 ? 1 : 2,
alpha: 0.15 + Math.random() * 0.45,
speed: 0.6 + Math.random() * 1.6,
phase: Math.random() * Math.PI * 2
}));
function loadBest() {
try {
const value = Number(localStorage.getItem("neonBreakoutBest"));
return Number.isFinite(value) ? value : 0;
} catch {
return 0;
}
}
function commitBest() {
try {
localStorage.setItem("neonBreakoutBest", String(best));
} catch {
// Storage can be unavailable in private or restricted contexts.
}
}
function scheduleBestSave() {
clearTimeout(bestSaveTimer);
bestSaveTimer = setTimeout(commitBest, 250);
}
function announce(message) {
ui.live.textContent = message;
}
function parseHex(hex) {
let h = hex.replace("#", "");
if (h.length === 3) h = h.split("").map(c => c + c).join("");
return [
parseInt(h.slice(0, 2), 16),
parseInt(h.slice(2, 4), 16),
parseInt(h.slice(4, 6), 16)
];
}
function rgba(hex, alpha) {
const c = parseHex(hex);
return `rgba(${c[0]},${c[1]},${c[2]},${alpha})`;
}
function mixHex(a, b, amount) {
const ca = parseHex(a);
const cb = parseHex(b);
const c = ca.map((v, i) => Math.round(v + (cb[i] - v) * amount));
return `#${c.map(v => v.toString(16).padStart(2, "0")).join("")}`;
}
function roundedRect(x, y, w, h, radius) {
const r = Math.min(radius, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function ensureAudio() {
if (!soundOn) return;
try {
if (!audioCtx) {
const AudioContextClass = window.AudioContext || window.webkitAudioContext;
if (!AudioContextClass) return;
audioCtx = new AudioContextClass();
}
if (audioCtx.state === "suspended") audioCtx.resume().catch(() => {});
} catch {
audioCtx = null;
}
}
function tone(frequency, duration = 0.08, type = "sine", volume = 0.035, endFrequency = null, delay = 0) {
if (!soundOn) return;
ensureAudio();
if (!audioCtx) return;
const start = audioCtx.currentTime + delay;
const oscillator = audioCtx.createOscillator();
const gain = audioCtx.createGain();
oscillator.type = type;
oscillator.frequency.setValueAtTime(frequency, start);
if (endFrequency !== null) {
oscillator.frequency.exponentialRampToValueAtTime(Math.max(20, endFrequency), start + duration);
}
gain.gain.setValueAtTime(0.0001, start);
gain.gain.exponentialRampToValueAtTime(volume, start + 0.008);
gain.gain.exponentialRampToValueAtTime(0.0001, start + duration);
oscillator.connect(gain);
gain.connect(audioCtx.destination);
oscillator.start(start);
oscillator.stop(start + duration + 0.025);
}
function playSound(kind) {
if (!soundOn) return;
switch (kind) {
case "launch":
tone(220, 0.13, "triangle", 0.055, 540);
break;
case "paddle":
tone(170, 0.075, "triangle", 0.045, 115);
break;
case "wall":
tone(205, 0.045, "sine", 0.023, 145);
break;
case "tick":
tone(310, 0.055, "square", 0.022, 260);
break;
case "destroy":
tone(420, 0.085, "triangle", 0.05, 650);
tone(660, 0.09, "sine", 0.028, 780, 0.035);
break;
case "power":
tone(440, 0.11, "sine", 0.04, 660);
tone(660, 0.11, "sine", 0.035, 880, 0.07);
tone(880, 0.13, "triangle", 0.03, 1100, 0.14);
break;
case "laser":
tone(820, 0.055, "square", 0.018, 320);
break;
case "lose":
tone(260, 0.38, "sawtooth", 0.035, 65);
break;
case "clear":
[392, 494, 587, 784].forEach((f, i) => tone(f, 0.18, "triangle", 0.04, f * 1.05, i * 0.085));
break;
case "victory":
[392, 523, 659, 784, 1047].forEach((f, i) => tone(f, 0.24, "triangle", 0.04, f * 1.03, i * 0.11));
break;
}
}
function toggleSound() {
soundOn = !soundOn;
ui.sound.textContent = soundOn ? "♪ SOUND ON" : "♪ SOUND OFF";
ui.sound.setAttribute("aria-pressed", String(soundOn));
if (soundOn) {
ensureAudio();
tone(600, 0.08, "sine", 0.035, 800);
}
}
function buildLevel(index) {
bricks = [];
const level = LEVELS[index];
const cellWidth = (GRID.width - GRID.gap * (GRID.cols - 1)) / GRID.cols;
level.rows.forEach((row, r) => {
const cells = row.padEnd(GRID.cols, ".").slice(0, GRID.cols);
for (let c = 0; c < GRID.cols; c++) {
const hp = Number(cells[c]);
if (!hp) continue;
const color = level.palette[Math.min(hp - 1, level.palette.length - 1)];
bricks.push({
x: GRID.x + c * (cellWidth + GRID.gap),
y: GRID.y + r * (GRID.height + GRID.rowGap),
w: cellWidth,
h: GRID.height,
hp,
maxHp: hp,
row: r,
col: c,
color,
value: hp * 50,
flash: 0,
dead: false
});
}
});
totalBricks = bricks.length;
bricksDestroyedThisLevel = 0;
}
function resetBall() {
balls = [{
x: paddle.x,
y: paddle.y - BALL_R - 2,
vx: 0,
vy: 0,
r: BALL_R,
attached: true,
bounces: 0,
trail: []
}];
}
function prepareLevel(index) {
levelIndex = index;
buildLevel(index);
pickups = [];
bolts = [];
particles = [];
texts = [];
wideTimer = 0;
slowTimer = 0;
rapidTimer = 0;
laserCooldown = 0;
combo = 0;
comboTimer = 0;
pendingClear = false;
levelClearBonus = 0;
levelClearLife = false;
levelClearTimer = 0;
levelBannerTimer = 2.2;
paddle.x = (W - paddle.w) / 2;
paddle.w = PADDLE_BASE;
paddle.vx = 0;
resetBall();
state = "ready";
updateHUD();
announce(`Level ${index + 1}: ${LEVELS[index].name}`);
}
function resetGame() {
commitBest();
score = 0;
lives = 3;
combo = 0;
comboTimer = 0;
prepareLevel(0);
announce("New game started.");
}
function launchBall() {
if (state !== "ready") return;
for (const ball of balls) {
if (!ball.attached) continue;
const angle = -Math.PI / 2 + (Math.random() - 0.5) * 0.72;
const speed = getTargetSpeed(ball);
ball.vx = Math.cos(angle) * speed;
ball.vy = Math.sin(angle) * speed;
ball.attached = false;
ball.trail = [];
}
state = "playing";
playSound("launch");
emit(paddle.x, paddle.y, "#55e6ff", 14, 150);
updateHUD();
}
function addScore(points) {
score += Math.round(points);
if (score > best) {
best = score;
scheduleBestSave();
}
updateHUD();
}
function loseLife() {
lives = Math.max(0, lives - 1);
redFlash = 0.38;
shake = 13;
emit(paddle.x, H - 8, "#ff5478", 24, 220);
playSound("lose");
if (lives <= 0) {
balls = [];
state = "gameover";
commitBest();
announce(`Game over. Final score ${score}.`);
} else {
resetBall();
state = "ready";
announce(`${lives} lives remaining.`);
}
updateHUD();
}
function triggerLevelClear() {
pendingClear = false;
levelClearBonus = 600 + levelIndex * 200;
levelClearLife = lives < 3;
if (levelClearLife) lives++;
addScore(levelClearBonus);
balls = [];
pickups = [];
bolts = [];
state = "levelclear";
levelClearTimer = 0.9;
shake = 8;
whiteFlash = 0.18;
commitBest();
playSound("clear");
announce(`Level ${levelIndex + 1} clear. Bonus ${levelClearBonus}.`);
updateHUD();
}
function nextLevel() {
if (levelIndex >= LEVELS.length - 1) {
state = "won";
commitBest();
playSound("victory");
announce(`All levels cleared with ${score} points.`);
updateHUD();
} else {
prepareLevel(levelIndex + 1);
}
}
function primaryAction() {
ensureAudio();
if (state === "menu" || state === "gameover" || state === "won") {
resetGame();
} else if (state === "ready") {
launchBall();
} else if (state === "paused") {
state = "playing";
keys.clear();
updateHUD();
} else if (state === "levelclear") {
if (levelClearTimer <= 0.35) nextLevel();
}
}
function togglePause() {
if (state === "playing") {
state = "paused";
keys.clear();
} else if (state === "paused") {
state = "playing";
}
updateHUD();
}
function getTargetSpeed(ball) {
let speed = 370 + levelIndex * 15 + Math.min(65, (ball.bounces || 0) * 1.15);
if (slowTimer > 0) speed *= 0.72;
return speed;
}
function normalizeBall(ball, speed) {
if (!ball.vx && !ball.vy) {
ball.vy = -speed;
return;
}
const angle = Math.atan2(ball.vy, ball.vx);
ball.vx = Math.cos(angle) * speed;
ball.vy = Math.sin(angle) * speed;
}
function normalizeAllBalls() {
for (const ball of balls) {
if (!ball.attached) normalizeBall(ball, getTargetSpeed(ball));
}
}
function wallBounce(ball) {
ball.bounces++;
let speed = getTargetSpeed(ball);
if (Math.abs(ball.vy) < speed * 0.18) {
ball.vy = (ball.vy >= 0 ? 1 : -1) * speed * 0.18;
}
normalizeBall(ball, speed);
shake = Math.max(shake, 1.7);
whiteFlash = Math.max(whiteFlash, 0.035);
playSound("wall");
}
function findBrickCollision(ball) {
let bestHit = null;
const radiusSquared = ball.r * ball.r;
for (const brick of bricks) {
if (brick.dead) continue;
const nearX = clamp(ball.x, brick.x, brick.x + brick.w);
const nearY = clamp(ball.y, brick.y, brick.y + brick.h);
const dx = ball.x - nearX;
const dy = ball.y - nearY;
const distanceSquared = dx * dx + dy * dy;
if (distanceSquared < radiusSquared) {
const distance = Math.sqrt(distanceSquared);
if (!bestHit || distance < bestHit.distance) {
bestHit = { brick, distance, nx: distance > 0 ? dx / distance : 0, ny: distance > 0 ? dy / distance : 0 };
}
}
}
return bestHit;
}
function resolveBrickCollision(ball, hit) {
const brick = hit.brick;
if (hit.distance > 0.0001) {
const push = ball.r - hit.distance + 0.05;
ball.x += hit.nx * push;
ball.y += hit.ny * push;
if (hit.nx * ball.vx < 0) ball.vx *= -1;
if (hit.ny * ball.vy < 0) ball.vy *= -1;
} else {
if (ball.vy >= 0) {
ball.y = brick.y - ball.r - 0.05;
ball.vy = -Math.abs(ball.vy);
} else {
ball.y = brick.y + brick.h + ball.r + 0.05;
ball.vy = Math.abs(ball.vy);
}
}
ball.bounces++;
normalizeBall(ball, getTargetSpeed(ball));
}
function damageBrick(brick, amount = 1) {
if (!brick || brick.dead) return;
brick.hp = Math.max(0, brick.hp - amount);
brick.flash = 0.16;
if (brick.hp > 0) {
emit(brick.x + brick.w / 2, brick.y + brick.h / 2, brick.color, 5, 95);
addScore(5);
shake = Math.max(shake, 1.8);
playSound("tick");
return;
}
brick.dead = true;
bricksDestroyedThisLevel++;
combo++;
comboTimer = 1.65;
const multiplier = 1 + levelIndex * 0.12;
const points = Math.round(brick.value * multiplier + Math.min(combo - 1, 9) * 20);
addScore(points);
spawnText(brick.x + brick.w / 2, brick.y + brick.h / 2, `+${points}`, brick.color);
emit(brick.x + brick.w / 2, brick.y + brick.h / 2, brick.color, 18, 220);
emit(brick.x + brick.w / 2, brick.y + brick.h / 2, "#ffffff", 7, 130);
shake = Math.max(shake, 4.2 + Math.min(combo, 7) * 0.45);
playSound("destroy");
if (bricksDestroyedThisLevel === 1 || Math.random() < 0.15) {
spawnPickup(brick);
}
if (bricks.every(item => item.dead)) pendingClear = true;
}
function spawnPickup(brick) {
let type;
if (bricksDestroyedThisLevel === 1) {
const firstTypes = ["multi", "wide", "rapid", "slow", "life"];
type = firstTypes[levelIndex % firstTypes.length];
} else {
const roll = Math.random();
if (roll < 0.28) type = "wide";
else if (roll < 0.53) type = "multi";
else if (roll < 0.73) type = "slow";
else if (roll < 0.88) type = "rapid";
else type = "life";
}
pickups.push({
x: brick.x + brick.w / 2,
y: brick.y + brick.h / 2,
w: 31,
h: 15,
type,
vy: 94 + levelIndex * 4,
angle: 0,
phase: Math.random() * Math.PI * 2
});
}
function splitBalls() {
const source = balls.find(ball => !ball.attached);
if (!source) return;
const sourceAngle = Math.atan2(source.vy, source.vx);
for (const offset of [-0.48, 0.48]) {
if (balls.length >= 7) break;
const angle = sourceAngle + offset;
const speed = getTargetSpeed(source);
balls.push({
x: clamp(source.x + Math.cos(angle) * 10, PLAY.left + BALL_R, PLAY.right - BALL_R),
y: source.y + Math.sin(angle) * 10,
vx: Math.cos(angle) * speed,
vy: Math.sin(angle) * speed,
r: BALL_R,
attached: false,
bounces: source.bounces,
trail: []
});
}
}
function applyPowerup(type) {
const power = POWERUPS[type];
if (!power) return;
addScore(50);
emit(paddle.x, paddle.y - 10, power.color, 24, 190);
spawnText(paddle.x, paddle.y - 24, power.label, power.color);
playSound("power");
if (type === "wide") wideTimer = 12;
if (type === "multi") splitBalls();
if (type === "slow") {
slowTimer = 7;
normalizeAllBalls();
}
if (type === "rapid") rapidTimer = 12;
if (type === "life") lives = Math.min(5, lives + 1);
updateHUD();
}
function fireLaser() {
if (state !== "playing" || rapidTimer <= 0 || laserCooldown > 0) return;
laserCooldown = 0.18;
bolts.push(
{ x: paddle.x - paddle.w * 0.28, y: paddle.y - 7, w: 4, h: 16, vy: -620 },
{ x: paddle.x + paddle.w * 0.28, y: paddle.y - 7, w: 4, h: 16, vy: -620 }
);
playSound("laser");
}
function emit(x, y, color, count = 10, speed = 150) {
for (let i = 0; i < count; i++) {
const angle = Math.random() * Math.PI * 2;
const velocity = speed * (0.3 + Math.random() * 0.7);
const life = 0.3 + Math.random() * 0.45;
particles.push({
x, y,
vx: Math.cos(angle) * velocity,
vy: Math.sin(angle) * velocity,
life,
maxLife: life,
size: 1.5 + Math.random() * 3.5,
color,
gravity: 80 + Math.random() * 150,
spin: Math.random() * Math.PI,
kind: "spark"
});
}
}
function spawnText(x, y, text, color) {
texts.push({ x, y, text, color, life: 0.9, maxLife: 0.9 });
}
function updatePaddle(dt) {
const targetWidth = wideTimer > 0 ? PADDLE_WIDE : PADDLE_BASE;
paddle.w += (targetWidth - paddle.w) * (1 - Math.exp(-11 * dt));
const oldX = paddle.x;
const left = keys.has("ArrowLeft") || keys.has("KeyA");
const right = keys.has("ArrowRight") || keys.has("KeyD");
const direction = (right ? 1 : 0) - (left ? 1 : 0);
if (controlMode === "keyboard") {
if (direction !== 0) {
if (paddle.vx * direction < 0) paddle.vx = 0;
paddle.vx += direction * 3800 * dt;
paddle.vx = clamp(paddle.vx, -780, 780);
} else {
paddle.vx *= Math.exp(-10 * dt);
if (Math.abs(paddle.vx) < 1) paddle.vx = 0;
}
paddle.x += paddle.vx * dt;
} else {
const follow = 1 - Math.exp(-24 * dt);
paddle.x += (pointer.targetX - paddle.x) * follow;
paddle.vx = (paddle.x - oldX) / dt;
paddle.vx = clamp(paddle.vx, -900, 900);
}
const clampedX = clamp(paddle.x, PLAY.left, PLAY.right - paddle.w);
if (clampedX !== paddle.x) paddle.vx = 0;
paddle.x = clampedX;
}
function updateTimers(dt) {
if (wideTimer > 0) wideTimer = Math.max(0, wideTimer - dt);
if (slowTimer > 0) {
slowTimer = Math.max(0, slowTimer - dt);
if (slowTimer === 0) normalizeAllBalls();
}
if (rapidTimer > 0) rapidTimer = Math.max(0, rapidTimer - dt);
laserCooldown = Math.max(0, laserCooldown - dt);
}
function updateBalls(dt) {
for (const ball of balls) {
if (ball.attached) {
ball.x = paddle.x;
ball.y = paddle.y - ball.r - 2;
continue;
}
ball.trail.unshift({ x: ball.x, y: ball.y });
if (ball.trail.length > 9) ball.trail.pop();
ball.x += ball.vx * dt;
ball.y += ball.vy * dt;
if (ball.x - ball.r < PLAY.left) {
ball.x = PLAY.left + ball.r;
ball.vx = Math.abs(ball.vx);
wallBounce(ball);
} else if (ball.x + ball.r > PLAY.right) {
ball.x = PLAY.right - ball.r;
ball.vx = -Math.abs(ball.vx);
wallBounce(ball);
}
if (ball.y - ball.r < PLAY.top) {
ball.y = PLAY.top + ball.r;
ball.vy = Math.abs(ball.vy);
wallBounce(ball);
}
const hit = findBrickCollision(ball);
if (hit) {
resolveBrickCollision(ball, hit);
damageBrick(hit.brick, 1);
}
if (
ball.vy > 0 &&
ball.y + ball.r >= paddle.y &&
ball.y - ball.r <= paddle.y + paddle.h + 14 &&
ball.x >= paddle.x - ball.r - 8 &&
ball.x <= paddle.x + paddle.w + ball.r + 8
) {
const offset = clamp((ball.x - paddle.x) / (paddle.w / 2), -1, 1);
const english = clamp(paddle.vx / 1500, -0.13, 0.13);
const angle = -Math.PI / 2 + offset * 1.05 + english;
ball.bounces++;
const speed = getTargetSpeed(ball);
ball.vx = Math.cos(angle) * speed;
ball.vy = Math.sin(angle) * speed;
ball.y = paddle.y - ball.r - 0.5;
emit(ball.x, paddle.y, "#7cf4ff", 9, 105);
shake = Math.max(shake, 1.5);
playSound("paddle");
}
if (ball.y - ball.r > H + 10) {
ball.dead = true;
emit(clamp(ball.x, 20, W - 20), H - 5, "#ff5478", 10, 140);
}
}
balls = balls.filter(ball => !ball.dead);
if (balls.length === 0 && !pendingClear && state === "playing") loseLife();
}
function updatePickups(dt) {
for (let i = pickups.length - 1; i >= 0; i--) {
const pickup = pickups[i];
pickup.y += pickup.vy * dt;
pickup.angle = Math.sin(time * 4 + pickup.phase) * 0.18;
const overlaps =
pickup.y + pickup.h / 2 >= paddle.y &&
pickup.y - pickup.h / 2 <= paddle.y + paddle.h &&
pickup.x + pickup.w / 2 >= paddle.x &&
pickup.x - pickup.w / 2 <= paddle.x + paddle.w;
if (overlaps) {
applyPowerup(pickup.type);
pickups.splice(i, 1);
} else if (pickup.y > H + 20) {
pickups.splice(i, 1);
}
}
}
function updateBolts(dt) {
for (let i = bolts.length - 1; i >= 0; i--) {
const bolt = bolts[i];
bolt.y += bolt.vy * dt;
if (bolt.y < PLAY.top - 20) {
bolts.splice(i, 1);
continue;
}
for (const brick of bricks) {
if (brick.dead) continue;
if (
bolt.x >= brick.x && bolt.x <= brick.x + brick.w &&
bolt.y >= brick.y && bolt.y <= brick.y + brick.h
) {
damageBrick(brick, 1);
emit(bolt.x, bolt.y, "#ffad55", 7, 110);
bolts.splice(i, 1);
break;
}
}
}
}
function updateEffects(dt) {
for (const particle of particles) {
particle.life -= dt;
particle.vx *= Math.exp(-1.5 * dt);
particle.vy += particle.gravity * dt;
particle.x += particle.vx * dt;
particle.y += particle.vy * dt;
particle.spin += dt * 5;
if (particle.kind === "ring") particle.size += 75 * dt;
}
particles = particles.filter(particle => particle.life > 0);
for (const item of texts) {
item.life -= dt;
item.y -= 35 * dt;
}
texts = texts.filter(item => item.life > 0);
for (const brick of bricks) brick.flash = Math.max(0, brick.flash - dt);
shake = Math.max(0, shake - 30 * dt);
whiteFlash = Math.max(0, whiteFlash - dt * 1.8);
redFlash = Math.max(0, redFlash - dt * 1.4);
}
function update(dt) {
if (state === "paused") return;
time += dt;
if (levelBannerTimer > 0) levelBannerTimer = Math.max(0, levelBannerTimer - dt);
if (state === "levelclear") levelClearTimer = Math.max(0, levelClearTimer - dt);
updatePaddle(dt);
if (state === "playing") {
updateTimers(dt);
if (comboTimer > 0) {
comboTimer -= dt;
if (comboTimer <= 0) combo = 0;
}
if (keys.has("Space") && rapidTimer > 0) fireLaser();
updateBalls(dt);
if (state === "playing") {
if (pendingClear) {
triggerLevelClear();
} else {
updatePickups(dt);
updateBolts(dt);
if (pendingClear) triggerLevelClear();
}
}
} else if (state === "ready" || state === "menu") {
for (const ball of balls) {
if (!ball.attached) continue;
ball.x = paddle.x;
ball.y = paddle.y - ball.r - 2;
}
}
updateEffects(dt);
hudClock -= dt;
if (hudClock <= 0) {
hudClock = 0.08;
updateHUD();
}
}
function updateHUD() {
ui.level.textContent = `${String(levelIndex + 1).padStart(2, "0")} / ${String(LEVELS.length).padStart(2, "0")}`;
ui.score.textContent = String(score).padStart(6, "0");
ui.best.textContent = String(best).padStart(6, "0");
ui.lives.textContent = Array.from({ length: 5 }, (_, i) => i < lives ? "♥" : "♡").join("");
const remaining = bricks.reduce((count, brick) => count + (brick.dead ? 0 : 1), 0);
const progress = totalBricks ? (totalBricks - remaining) / totalBricks : 0;
ui.progress.style.width = `${progress * 100}%`;
ui.combo.textContent = combo > 0 ? `COMBO ×${combo}` : "COMBO —";
ui.combo.classList.toggle("hot", combo >= 3);
const statuses = {
menu: "AWAITING INPUT",
ready: `LEVEL ${String(levelIndex + 1).padStart(2, "0")} · ${LEVELS[levelIndex].name}`,
playing: "CIRCUIT ACTIVE",
paused: "PAUSED",
levelclear: "CIRCUIT COMPLETE",
gameover: "SIGNAL LOST",
won: "ALL SYSTEMS CLEAR"
};
ui.status.textContent = statuses[state] || "READY";
ui.dot.style.backgroundColor =
state === "paused" ? "#ffe45e" :
state === "gameover" ? "#ff5478" :
state === "won" ? "#70ff9b" :
state === "levelclear" ? "#b9ff52" : LEVELS[levelIndex].accent;
ui.pause.textContent = state === "paused" ? "▶ RESUME" : "Ⅱ PAUSE";
ui.pause.disabled = state !== "playing" && state !== "paused";
}
function drawBackground() {
const accent = LEVELS[levelIndex].accent;
const gradient = ctx.createLinearGradient(0, 0, 0, H);
gradient.addColorStop(0, "#0a1024");
gradient.addColorStop(0.55, "#070b18");
gradient.addColorStop(1, "#090716");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, W, H);
const glow = ctx.createRadialGradient(W * 0.18, 95, 0, W * 0.18, 95, 430);
glow.addColorStop(0, rgba(accent, 0.11));
glow.addColorStop(1, rgba(accent, 0));
ctx.fillStyle = glow;
ctx.fillRect(0, 0, W, H);
ctx.strokeStyle = "rgba(135, 174, 255, 0.027)";
ctx.lineWidth = 1;
ctx.beginPath();
for (let x = 0; x <= W; x += 48) {
ctx.moveTo(x, 0);
ctx.lineTo(x, H);
}
for (let y = 0; y <= H; y += 40) {
ctx.moveTo(0, y);
ctx.lineTo(W, y);
}
ctx.stroke();
for (const star of stars) {
const twinkle = 0.35 + 0.65 * (0.5 + 0.5 * Math.sin(time * star.speed + star.phase));
ctx.fillStyle = `rgba(190,225,255,${star.alpha * twinkle})`;
ctx.fillRect(star.x, star.y, star.size, star.size);
}
ctx.save();
ctx.shadowColor = accent;
ctx.shadowBlur = 13;
ctx.strokeStyle = rgba(accent, 0.43);
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(PLAY.left, H - 8);
ctx.lineTo(PLAY.left, PLAY.top + 12);
ctx.quadraticCurveTo(PLAY.left, PLAY.top, PLAY.left + 12, PLAY.top);
ctx.lineTo(PLAY.right - 12, PLAY.top);
ctx.quadraticCurveTo(PLAY.right, PLAY.top, PLAY.right, PLAY.top + 12);
ctx.lineTo(PLAY.right, H - 8);
ctx.stroke();
ctx.shadowBlur = 0;
ctx.strokeStyle = rgba("#ffffff", 0.11);
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(PLAY.left + 4, PLAY.top + 4);
ctx.lineTo(PLAY.right - 4, PLAY.top + 4);
ctx.stroke();
ctx.restore();
const danger = ctx.createLinearGradient(0, H - 110, 0, H);
danger.addColorStop(0, "rgba(255, 50, 105, 0)");
danger.addColorStop(1, "rgba(255, 50, 105, 0.12)");
ctx.fillStyle = danger;
ctx.fillRect(PLAY.left, H - 110, PLAY.right - PLAY.left, 110);
ctx.fillStyle = "rgba(255, 80, 120, 0.22)";
ctx.fillRect(PLAY.left, H - 3, PLAY.right - PLAY.left, 2);
}
function drawBricks() {
for (const brick of bricks) {
if (brick.dead) continue;
ctx.save();
const gradient = ctx.createLinearGradient(brick.x, brick.y, brick.x, brick.y + brick.h);
gradient.addColorStop(0, mixHex(brick.color, "#ffffff", 0.28));
gradient.addColorStop(0.42, brick.color);
gradient.addColorStop(1, mixHex(brick.color, "#000000", 0.36));
ctx.shadowColor = brick.color;
ctx.shadowBlur = brick.flash > 0 ? 22 : 6;
ctx.fillStyle = gradient;
roundedRect(brick.x, brick.y, brick.w, brick.h, 5);
ctx.fill();
ctx.shadowBlur = 0;
ctx.strokeStyle = "rgba(255,255,255,0.42)";
ctx.lineWidth = 1;
roundedRect(brick.x + 0.5, brick.y + 0.5, brick.w - 1, brick.h - 1, 5);
ctx.stroke();
ctx.fillStyle = "rgba(255,255,255,0.28)";
roundedRect(brick.x + 5, brick.y + 3, brick.w - 10, 2, 1);
ctx.fill();
if (brick.maxHp > 1) {
const start = brick.x + brick.w - 8 - (brick.maxHp - 1) * 6;
for (let i = 0; i < brick.maxHp; i++) {
ctx.fillStyle = i < brick.hp ? "rgba(255,255,255,0.9)" : "rgba(5,12,28,0.48)";
ctx.beginPath();
ctx.arc(start + i * 6, brick.y + brick.h - 6, 1.7, 0, Math.PI * 2);
ctx.fill();
}
}
if (brick.hp < brick.maxHp) {
ctx.strokeStyle = "rgba(4,10,25,0.54)";
ctx.lineWidth = 1.4;
ctx.beginPath();
ctx.moveTo(brick.x + brick.w * 0.24, brick.y);
ctx.lineTo(brick.x + brick.w * 0.43, brick.y + brick.h * 0.44);
ctx.lineTo(brick.x + brick.w * 0.34, brick.y + brick.h * 0.62);
ctx.lineTo(brick.x + brick.w * 0.53, brick.y + brick.h);
ctx.stroke();
}
if (brick.flash > 0) {
ctx.fillStyle = rgba("#ffffff", Math.min(0.65, brick.flash * 2.7));
roundedRect(brick.x, brick.y, brick.w, brick.h, 5);
ctx.fill();
}
ctx.restore();
}
}
function drawPickups() {
for (const pickup of pickups) {
const power = POWERUPS[pickup.type];
ctx.save();
ctx.translate(pickup.x, pickup.y);
ctx.rotate(pickup.angle);
ctx.shadowColor = power.color;
ctx.shadowBlur = 17;
ctx.fillStyle = rgba(power.color, 0.16);
ctx.strokeStyle = power.color;
ctx.lineWidth = 1.5;
roundedRect(-pickup.w / 2, -pickup.h / 2, pickup.w, pickup.h, 7);
ctx.fill();
ctx.stroke();
ctx.shadowBlur = 0;
ctx.fillStyle = power.color;
ctx.font = "900 10px ui-sans-serif, system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(power.icon, 0, 0.5);
ctx.restore();
}
}
function drawBolts() {
ctx.save();
ctx.shadowColor = "#ff994d";
ctx.shadowBlur = 15;
ctx.fillStyle = "#ffd083";
for (const bolt of bolts) {
roundedRect(bolt.x - bolt.w / 2, bolt.y, bolt.w, bolt.h, 2);
ctx.fill();
}
ctx.restore();
}
function drawPaddle() {
ctx.save();
ctx.shadowColor = wideTimer > 0 ? "#ff71d4" : "#54eaff";
ctx.shadowBlur = wideTimer > 0 ? 28 : 21;
const gradient = ctx.createLinearGradient(paddle.x, 0, paddle.x + paddle.w, 0);
gradient.addColorStop(0, wideTimer > 0 ? "#b653ff" : "#488dff");
gradient.addColorStop(0.5, wideTimer > 0 ? "#ff72d3" : "#6cf3ff");
gradient.addColorStop(1, wideTimer > 0 ? "#8f60ff" : "#4e8cff");
ctx.fillStyle = gradient;
roundedRect(paddle.x, paddle.y, paddle.w, paddle.h, 8);
ctx.fill();
ctx.shadowBlur = 0;
ctx.strokeStyle = "rgba(255,255,255,0.75)";
ctx.lineWidth = 1;
roundedRect(paddle.x + 0.5, paddle.y + 0.5, paddle.w - 1, paddle.h - 1, 8);
ctx.stroke();
ctx.fillStyle = "rgba(255,255,255,0.65)";
roundedRect(paddle.x + paddle.w * 0.32, paddle.y + 3, paddle.w * 0.36, 3, 2);
ctx.fill();
if (rapidTimer > 0) {
ctx.fillStyle = "#ffe45e";
ctx.shadowColor = "#ff9d45";
ctx.shadowBlur = 12;
ctx.fillRect(paddle.x - 3, paddle.y - 2, 6, 6);
ctx.fillRect(paddle.x + paddle.w - 3, paddle.y - 2, 6, 6);
}
ctx.restore();
}
function drawBalls() {
ctx.save();
ctx.globalCompositeOperation = "lighter";
for (const ball of balls) {
for (let i = 1; i < ball.trail.length; i++) {
const alpha = (1 - i / ball.trail.length) * 0.32;
ctx.strokeStyle = rgba("#6cf4ff", alpha);
ctx.lineWidth = ball.r * 1.55 * (1 - i / ball.trail.length);
ctx.beginPath();
ctx.moveTo(ball.trail[i - 1].x, ball.trail[i - 1].y);
ctx.lineTo(ball.trail[i].x, ball.trail[i].y);
ctx.stroke();
}
ctx.shadowColor = "#55e6ff";
ctx.shadowBlur = 18;
const gradient = ctx.createRadialGradient(ball.x - 2, ball.y - 3, 1, ball.x, ball.y, ball.r);
gradient.addColorStop(0, "#ffffff");
gradient.addColorStop(0.4, "#b9fbff");
gradient.addColorStop(1, "#42cfff");
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.arc(ball.x, ball.y, ball.r, 0, Math.PI * 2);
ctx.fill();
if (ball.attached) {
ctx.shadowBlur = 8;
ctx.strokeStyle = rgba("#55e6ff", 0.55 + Math.sin(time * 8) * 0.2);
ctx.lineWidth = 1.5;
ctx.beginPath();
ctx.arc(ball.x, ball.y, ball.r + 5 + Math.sin(time * 7), 0, Math.PI * 2);
ctx.stroke();
}
}
ctx.restore();
}
function drawParticles() {
ctx.save();
ctx.globalCompositeOperation = "lighter";
for (const particle of particles) {
const alpha = clamp(particle.life / particle.maxLife, 0, 1);
ctx.fillStyle = rgba(particle.color, alpha);
ctx.strokeStyle = rgba(particle.color, alpha);
if (particle.kind === "ring") {
ctx.lineWidth = 2 * alpha;
ctx.beginPath();
ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
ctx.stroke();
} else {
ctx.save();
ctx.translate(particle.x, particle.y);
ctx.rotate(particle.spin);
ctx.fillRect(-particle.size / 2, -particle.size / 2, particle.size, particle.size);
ctx.restore();
}
}
ctx.restore();
}
function drawTexts() {
ctx.save();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 15px ui-sans-serif, system-ui, sans-serif";
for (const item of texts) {
const alpha = clamp(item.life / item.maxLife, 0, 1);
ctx.fillStyle = rgba(item.color, alpha);
ctx.shadowColor = item.color;
ctx.shadowBlur = 10;
ctx.fillText(item.text, item.x, item.y);
}
ctx.restore();
}
function drawStatusPill(x, y, text, color) {
ctx.save();
ctx.font = "800 10px ui-sans-serif, system-ui, sans-serif";
const width = ctx.measureText(text).width + 20;
ctx.fillStyle = rgba(color, 0.1);
ctx.strokeStyle = rgba(color, 0.48);
ctx.lineWidth = 1;
roundedRect(x, y, width, 20, 10);
ctx.fill();
ctx.stroke();
ctx.fillStyle = color;
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText(text, x + 10, y + 10.5);
ctx.restore();
return width;
}
function drawCanvasHud() {
ctx.save();
const accent = LEVELS[levelIndex].accent;
let x = 38;
if (wideTimer > 0) x += drawStatusPill(x, 37, `WIDE ${wideTimer.toFixed(1)}s`, POWERUPS.wide.color) + 6;
if (slowTimer > 0) x += drawStatusPill(x, 37, `SLOW ${slowTimer.toFixed(1)}s`, POWERUPS.slow.color) + 6;
if (rapidTimer > 0) x += drawStatusPill(x, 37, `LASER ${rapidTimer.toFixed(1)}s`, POWERUPS.rapid.color) + 6;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = rgba(accent, 0.9);
ctx.shadowColor = accent;
ctx.shadowBlur = 10;
ctx.font = `900 ${levelBannerTimer > 0 ? 17 : 12}px ui-sans-serif, system-ui, sans-serif`;
ctx.fillText(`LEVEL ${String(levelIndex + 1).padStart(2, "0")} // ${LEVELS[levelIndex].name}`, W / 2, 48);
ctx.shadowBlur = 0;
const remaining = bricks.reduce((count, brick) => count + (brick.dead ? 0 : 1), 0);
const progress = totalBricks ? (totalBricks - remaining) / totalBricks : 0;
const px = 778;
const pw = 145;
ctx.textAlign = "left";
ctx.font = "800 9px ui-sans-serif, system-ui, sans-serif";
ctx.fillStyle = "rgba(160,185,225,0.65)";
ctx.fillText("BREAKDOWN", px, 35);
ctx.fillStyle = "rgba(255,255,255,0.08)";
roundedRect(px, 43, pw, 6, 3);
ctx.fill();
ctx.fillStyle = accent;
ctx.shadowColor = accent;
ctx.shadowBlur = 10;
roundedRect(px, 43, pw * progress, 6, 3);
ctx.fill();
ctx.restore();
}
function drawOverlay() {
let title;
let subtitle;
let action;
let hint;
let accent = LEVELS[levelIndex].accent;
if (state === "menu") {
title = "NEON BREAKOUT";
subtitle = "Break every brick across 8 handcrafted circuits.";
action = "CLICK OR PRESS SPACE TO START";
hint = "Mouse or arrow keys · Space launches · P pauses";
} else if (state === "ready") {
title = LEVELS[levelIndex].name;
subtitle = `${LEVELS[levelIndex].hint} · ${lives} lives remaining`;
action = "CLICK OR PRESS SPACE TO LAUNCH";
hint = "Collect falling power-ups for an extra edge";
} else if (state === "paused") {
title = "PAUSED";
subtitle = "The circuit is frozen exactly where you left it.";
action = "PRESS P OR CLICK TO RESUME";
hint = "Your score is safe";
accent = "#ffe45e";
} else if (state === "levelclear") {
title = levelIndex === LEVELS.length - 1 ? "FINAL CIRCUIT CLEARED" : "LEVEL CLEAR";
subtitle = `+${levelClearBonus} bonus points${levelClearLife ? " · +1 life restored" : ""}`;
action = levelClearTimer > 0.35
? `NEXT CIRCUIT IN ${Math.max(1, Math.ceil(levelClearTimer))}`
: levelIndex === LEVELS.length - 1
? "PRESS SPACE / CLICK TO CLAIM VICTORY"
: "PRESS SPACE / CLICK TO CONTINUE";
hint = "Signal integrity restored";
accent = "#b9ff52";
} else if (state === "gameover") {
title = "SIGNAL LOST";
subtitle = `Final score ${score.toLocaleString()} · Best ${best.toLocaleString()}`;
action = "PRESS SPACE OR CLICK TO REPLAY";
hint = "Tip: chain bricks to build a combo";
accent = "#ff5478";
} else {
title = "ALL CIRCUITS CLEAR";
subtitle = `Final score ${score.toLocaleString()} · Best ${best.toLocaleString()}`;
action = "PRESS SPACE OR CLICK TO PLAY AGAIN";
hint = "You mastered the Neon Breakout gauntlet";
accent = "#70ff9b";
}
const panelX = 160;
const panelY = 181;
const panelW = 640;
const panelH = 269;
ctx.save();
ctx.fillStyle = "rgba(3,6,16,0.73)";
ctx.fillRect(0, 0, W, H);
ctx.shadowColor = rgba(accent, 0.4);
ctx.shadowBlur = 42;
const panelGradient = ctx.createLinearGradient(panelX, panelY, panelX, panelY + panelH);
panelGradient.addColorStop(0, "rgba(17,27,57,0.98)");
panelGradient.addColorStop(1, "rgba(8,13,31,0.98)");
ctx.fillStyle = panelGradient;
roundedRect(panelX, panelY, panelW, panelH, 23);
ctx.fill();
ctx.shadowBlur = 0;
ctx.strokeStyle = rgba(accent, 0.55);
ctx.lineWidth = 1.4;
roundedRect(panelX + 0.7, panelY + 0.7, panelW - 1.4, panelH - 1.4, 23);
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(panelX + panelW / 2 - 56, panelY, 112, 4, 2);
ctx.fill();
for (let i = 0; i < 5; i++) {
ctx.fillStyle = rgba(accent, 0.28 + i * 0.1);
roundedRect(panelX + 250 + i * 19, panelY + 22, 13, 6, 2);
ctx.fill();
}
ctx.textAlign = "center";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = "#f4f8ff";
ctx.shadowColor = rgba(accent, 0.5);
ctx.shadowBlur = 18;
ctx.font = "900 42px ui-sans-serif, system-ui, sans-serif";
ctx.fillText(title, W / 2, panelY + 79, panelW - 70);
ctx.shadowBlur = 0;
ctx.fillStyle = "rgba(203,218,245,0.78)";
ctx.font = "600 16px ui-sans-serif, system-ui, sans-serif";
ctx.fillText(subtitle, W / 2, panelY + 112, panelW - 70);
ctx.font = "900 13px ui-sans-serif, system-ui, sans-serif";
const actionWidth = Math.min(510, ctx.measureText(action).width + 42);
ctx.fillStyle = rgba(accent, 0.13);
ctx.strokeStyle = rgba(accent, 0.62);
ctx.lineWidth = 1;
roundedRect(W / 2 - actionWidth / 2, panelY + 143, actionWidth, 43, 21);
ctx.fill();
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillText(action, W / 2, panelY + 170, panelW - 70);
ctx.fillStyle = "rgba(132,151,190,0.72)";
ctx.font = "700 11px ui-sans-serif, system-ui, sans-serif";
ctx.fillText(hint, W / 2, panelY + 221);
ctx.restore();
}
function draw() {
ctx.setTransform(scaleX, 0, 0, scaleY, 0, 0);
ctx.clearRect(0, 0, W, H);
drawBackground();
ctx.save();
if (shake > 0) {
ctx.translate((Math.random() - 0.5) * shake, (Math.random() - 0.5) * shake);
}
drawBricks();
drawPickups();
drawBolts();
drawPaddle();
drawBalls();
drawParticles();
drawTexts();
ctx.restore();
drawCanvasHud();
if (whiteFlash > 0) {
ctx.fillStyle = rgba("#ffffff", Math.min(0.22, whiteFlash));
ctx.fillRect(0, 0, W, H);
}
if (redFlash > 0) {
ctx.fillStyle = rgba("#ff315f", Math.min(0.3, redFlash));
ctx.fillRect(0, 0, W, H);
}
if (state !== "playing") drawOverlay();
}
function resizeCanvas() {
const rect = canvas.getBoundingClientRect();
if (!rect.width || !rect.height) return;
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const width = Math.max(1, Math.round(rect.width * dpr));
const height = Math.max(1, Math.round(rect.height * dpr));
if (canvas.width !== width || canvas.height !== height) {
canvas.width = width;
canvas.height = height;
}
scaleX = canvas.width / W;
scaleY = canvas.height / H;
}
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.targetX = clamp((event.clientX - rect.left) * W / rect.width, PLAY.left, PLAY.right);
pointer.active = true;
controlMode = "mouse";
}
canvas.addEventListener("pointermove", event => {
if (event.pointerType === "mouse" || pointer.down) updatePointer(event);
});
canvas.addEventListener("pointerdown", event => {
if (event.pointerType === "mouse" && event.button !== 0) return;
event.preventDefault();
updatePointer(event);
pointer.down = true;
canvas.focus({ preventScroll: true });
ensureAudio();
try {
canvas.setPointerCapture(event.pointerId);
} catch {}
if (state === "playing") {
if (rapidTimer > 0) fireLaser();
} else {
primaryAction();
}
});
canvas.addEventListener("pointerup", () => { pointer.down = false; });
canvas.addEventListener("pointercancel", () => { pointer.down = false; });
canvas.addEventListener("pointerleave", event => {
if (event.pointerType === "mouse") pointer.active = false;
});
canvas.addEventListener("contextmenu", event => event.preventDefault());
window.addEventListener("keydown", event => {
if (event.ctrlKey || event.metaKey || event.altKey) return;
const controlled = [
"ArrowLeft", "ArrowRight", "KeyA", "KeyD",
"Space", "Enter", "KeyP", "KeyR", "KeyM"
];
if (controlled.includes(event.code)) event.preventDefault();
if (event.code === "ArrowLeft" || event.code === "KeyA" ||
event.code === "ArrowRight" || event.code === "KeyD") {
controlMode = "keyboard";
keys.add(event.code);
return;
}
if (event.code === "Space") {
keys.add("Space");
if (!event.repeat) {
if (state === "playing") {
if (rapidTimer > 0) fireLaser();
} else {
primaryAction();
}
}
return;
}
if (event.repeat) return;
if (event.code === "Enter") primaryAction();
if (event.code === "KeyP") togglePause();
if (event.code === "KeyR") resetGame();
if (event.code === "KeyM") toggleSound();
});
window.addEventListener("keyup", event => {
keys.delete(event.code);
});
window.addEventListener("blur", () => {
keys.clear();
if (state === "playing") {
state = "paused";
updateHUD();
}
});
document.addEventListener("visibilitychange", () => {
if (document.hidden && state === "playing") {
state = "paused";
keys.clear();
updateHUD();
}
});
ui.sound.addEventListener("click", () => {
ensureAudio();
toggleSound();
ui.sound.blur();
});
ui.pause.addEventListener("click", () => {
ensureAudio();
togglePause();
ui.pause.blur();
});
ui.restart.addEventListener("click", () => {
ensureAudio();
resetGame();
canvas.focus({ preventScroll: true });
});
window.addEventListener("resize", resizeCanvas);
if ("ResizeObserver" in window) {
new ResizeObserver(resizeCanvas).observe(canvas.parentElement);
}
prepareLevel(0);
state = "menu";
levelBannerTimer = 0;
updateHUD();
resizeCanvas();
let lastFrame = performance.now();
let accumulator = 0;
function frame(now) {
const delta = Math.min(0.05, Math.max(0, (now - lastFrame) / 1000));
lastFrame = now;
accumulator += delta;
let steps = 0;
while (accumulator >= STEP && steps < 10) {
update(STEP);
accumulator -= STEP;
steps++;
}
if (steps >= 10) accumulator = 0;
draw();
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
})();
</script>
</body>
</html>

