Run details
- Model
- amazon/ergo-1.0
- Route
- OpenRouter API
- Served by
- Amazon Bedrock
- Effort
- model default
- Limits
- 60 min · 131,072 output tokens (model max)
- Date
- 2 Dec 2026
- Time
- 1 min 41 s
- Size
- 44 kB
- Tokens
- 144 in, 40,082 out (23,019 thinking)
- List price
- $0.12 at today's price ($1.00 in / $3.00 out per M)
- Paid
- $0.12
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
44 kB 1,691 lines Raw
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="dark">
<title>Neon Breakout</title>
<style>
:root {
--cyan: #43eaff;
--pink: #ff4fd8;
--ink: #050713;
--muted: #8d99ba;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
min-height: 100vh;
display: grid;
place-items: center;
padding: 18px;
overflow-x: hidden;
color: #edf5ff;
background:
radial-gradient(circle at 15% 10%, rgba(73, 44, 150, .24), transparent 38%),
radial-gradient(circle at 85% 90%, rgba(0, 213, 255, .12), transparent 36%),
#03040b;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#app {
width: min(1100px, 96vw);
user-select: none;
}
header {
display: flex;
align-items: center;
gap: 20px;
padding: 0 4px 13px;
}
.brand {
margin-right: auto;
font-weight: 950;
font-size: clamp(17px, 2.2vw, 25px);
letter-spacing: .13em;
font-style: italic;
white-space: nowrap;
text-shadow: 0 0 20px rgba(67, 234, 255, .45);
}
.brand span { color: var(--cyan); }
.stats {
display: flex;
align-items: center;
gap: clamp(12px, 3vw, 32px);
}
.stat {
display: grid;
gap: 1px;
min-width: 58px;
}
.stat label {
color: var(--muted);
font: 700 9px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
letter-spacing: .18em;
text-transform: uppercase;
}
.stat output {
font: 800 16px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
letter-spacing: .04em;
}
#score { color: #fff; }
#lives { color: var(--pink); letter-spacing: .12em; text-shadow: 0 0 12px rgba(255, 79, 216, .6); }
.header-buttons { display: flex; gap: 7px; }
.icon-button {
border: 1px solid rgba(145, 167, 220, .22);
border-radius: 9px;
padding: 8px 10px;
color: #aab8d8;
background: rgba(15, 20, 40, .72);
cursor: pointer;
font: 700 11px ui-monospace, SFMono-Regular, Consolas, monospace;
transition: border-color .15s, color .15s, transform .15s;
}
.icon-button:hover {
color: white;
border-color: rgba(67, 234, 255, .65);
transform: translateY(-1px);
}
#stage {
position: relative;
overflow: hidden;
border: 1px solid rgba(127, 158, 230, .28);
border-radius: 16px;
background: var(--ink);
box-shadow:
0 25px 80px rgba(0, 0, 0, .55),
0 0 45px rgba(55, 94, 190, .11),
inset 0 0 30px rgba(70, 112, 205, .06);
}
#stage::after {
content: "";
position: absolute;
inset: 0;
z-index: 3;
pointer-events: none;
border-radius: inherit;
background: repeating-linear-gradient(
to bottom,
transparent 0,
transparent 3px,
rgba(130, 170, 255, .018) 4px
);
box-shadow: inset 0 0 80px rgba(0, 0, 0, .32);
}
canvas {
display: block;
width: 100%;
height: auto;
aspect-ratio: 8 / 5;
outline: none;
cursor: crosshair;
touch-action: none;
}
#overlay {
position: absolute;
inset: 0;
z-index: 4;
display: grid;
place-items: center;
padding: 20px;
background: rgba(2, 4, 13, .64);
backdrop-filter: blur(5px);
transition: opacity .2s, visibility .2s;
}
#overlay.hidden {
opacity: 0;
visibility: hidden;
pointer-events: none;
}
.panel {
width: min(510px, 92%);
padding: clamp(24px, 5vw, 45px);
text-align: center;
border: 1px solid rgba(119, 224, 255, .25);
border-radius: 20px;
background:
linear-gradient(145deg, rgba(20, 27, 57, .94), rgba(7, 9, 25, .96));
box-shadow:
0 24px 70px rgba(0, 0, 0, .55),
0 0 45px rgba(67, 234, 255, .08),
inset 0 1px rgba(255, 255, 255, .07);
}
#overlayKicker {
margin-bottom: 10px;
color: var(--cyan);
font: 800 10px ui-monospace, SFMono-Regular, Consolas, monospace;
letter-spacing: .25em;
text-transform: uppercase;
}
#overlayTitle {
margin: 0;
font-size: clamp(34px, 6vw, 62px);
line-height: .98;
font-weight: 950;
font-style: italic;
letter-spacing: -.045em;
text-transform: uppercase;
text-wrap: balance;
text-shadow: 0 0 30px rgba(67, 234, 255, .25);
}
#overlayText {
max-width: 380px;
margin: 18px auto;
color: #aab6d3;
font-size: 14px;
line-height: 1.65;
}
#overlayScore {
margin: -4px 0 18px;
color: #fff;
font: 800 13px ui-monospace, SFMono-Regular, Consolas, monospace;
}
#overlayScore:empty { display: none; }
#primary {
min-width: 190px;
border: 0;
border-radius: 999px;
padding: 14px 28px;
color: #031018;
background: linear-gradient(100deg, #43eaff, #8ffff0);
box-shadow: 0 0 28px rgba(67, 234, 255, .3), inset 0 1px white;
cursor: pointer;
font-weight: 950;
font-size: 12px;
letter-spacing: .14em;
text-transform: uppercase;
transition: transform .15s, box-shadow .15s;
}
#primary:hover {
transform: translateY(-2px) scale(1.02);
box-shadow: 0 0 40px rgba(67, 234, 255, .5), inset 0 1px white;
}
#primary:active { transform: translateY(0) scale(.98); }
.controls {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 9px 18px;
margin-top: 23px;
color: #7786aa;
font: 700 10px ui-monospace, SFMono-Regular, Consolas, monospace;
}
kbd {
display: inline-block;
margin-right: 4px;
padding: 3px 6px;
border: 1px solid #36425f;
border-bottom-width: 2px;
border-radius: 5px;
color: #c4d1ed;
background: #151b30;
font: inherit;
}
footer {
padding: 11px 5px 0;
text-align: center;
color: #65718d;
font: 700 10px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
letter-spacing: .04em;
}
footer strong { color: #a6b5d5; font-weight: 800; }
@media (max-width: 760px) {
body { padding: 10px; }
header { flex-wrap: wrap; gap: 10px; }
.brand { width: 100%; text-align: center; }
.stats { margin-right: auto; gap: 15px; }
.stat output { font-size: 13px; }
.panel { padding: 25px 18px; }
.controls { display: none; }
footer { font-size: 9px; }
}
</style>
</head>
<body>
<main id="app">
<header>
<div class="brand">NEON <span>BREAKOUT</span></div>
<div class="stats">
<div class="stat"><label>Score</label><output id="score">000000</output></div>
<div class="stat"><label>Sector</label><output id="level">1 / 5</output></div>
<div class="stat"><label>Balls</label><output id="lives">◆◆◆</output></div>
</div>
<div class="header-buttons">
<button class="icon-button" id="soundButton" type="button" title="Toggle sound (M)">Sound on</button>
<button class="icon-button" id="pauseButton" type="button" title="Pause (P)">Pause</button>
</div>
</header>
<div id="stage">
<canvas id="game" width="960" height="600" tabindex="0" aria-label="Neon Breakout game. Move with the mouse or arrow keys. Press Space to launch the ball.">
Your browser needs Canvas support to play Neon Breakout.
</canvas>
<div id="overlay" role="dialog" aria-live="polite">
<div class="panel">
<div id="overlayKicker">A tiny arcade odyssey</div>
<h1 id="overlayTitle">Neon Breakout</h1>
<p id="overlayText">Shatter five sectors, chain hits for combo points, and catch falling power cores.</p>
<div id="overlayScore"></div>
<button id="primary" type="button">Start game</button>
<div class="controls">
<span><kbd>← →</kbd> / <kbd>A D</kbd> Move</span>
<span><kbd>Space</kbd> Launch</span>
<span><kbd>P</kbd> Pause</span>
</div>
</div>
</div>
</div>
<footer>
<strong>MOUSE / ← → / A D</strong> to move ·
<strong>CLICK / SPACE</strong> to launch ·
<strong>P</strong> to pause ·
<strong>M</strong> for sound
</footer>
</main>
<script>
(() => {
"use strict";
const canvas = document.getElementById("game");
const ctx = canvas.getContext("2d");
const W = 960;
const H = 600;
const STEP = 1 / 120;
const ui = {
score: document.getElementById("score"),
level: document.getElementById("level"),
lives: document.getElementById("lives"),
overlay: document.getElementById("overlay"),
kicker: document.getElementById("overlayKicker"),
title: document.getElementById("overlayTitle"),
text: document.getElementById("overlayText"),
overlayScore: document.getElementById("overlayScore"),
primary: document.getElementById("primary"),
sound: document.getElementById("soundButton"),
pause: document.getElementById("pauseButton")
};
const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
const rand = (lo, hi) => lo + Math.random() * (hi - lo);
const choose = arr => arr[(Math.random() * arr.length) | 0];
const HP_COLORS = {
1: "#27dff5",
2: "#8b68ff",
3: "#ff4fd8",
4: "#ffad38"
};
const POWER = {
wide: { color: "#43eaff", letter: "W", name: "WIDE PADDLE" },
multi: { color: "#ff4fd8", letter: "M", name: "MULTIBALL" },
slow: { color: "#7dffb2", letter: "S", name: "SLOW MOTION" },
life: { color: "#ffcf4a", letter: "+", name: "EXTRA BALL" }
};
const LEVELS = [
{
name: "First Light",
subtitle: "Warm up the photons.",
speed: 390,
hue: 190,
layout: [
"....1111....",
"...111111...",
"..11222211..",
".1111111111.",
"111111111111"
]
},
{
name: "Crossfire",
subtitle: "Find the gaps. Work the angles.",
speed: 410,
hue: 265,
layout: [
"1..222222..1",
"11..2222..11",
"111..22..111",
"1111.22.1111",
"11111..11111",
"11111..11111"
]
},
{
name: "Pixel Invader",
subtitle: "A visitor from another galaxy.",
speed: 430,
hue: 320,
layout: [
"..1......1..",
"...1....1...",
"..11111111..",
".11.1111.11.",
"111111111111",
"1.11111111.1",
"1.1......1.1",
"...11..11..."
]
},
{
name: "The Fortress",
subtitle: "Armored walls. No mercy.",
speed: 450,
hue: 28,
layout: [
"333333333333",
"3..........3",
"3.22222222.3",
"3.2......2.3",
"3.2.1111.2.3",
"3.2.1111.2.3",
"3.2......2.3",
"3.22222222.3",
"3..........3"
]
},
{
name: "Neon Core",
subtitle: "Break the heart of the machine.",
speed: 470,
hue: 335,
layout: [
".....44.....",
"..33344333..",
".3333333333.",
"332222222233",
"322211112223",
"322111111123",
".2222222222.",
"..22222222..",
"...222222..."
]
}
];
const COLS = 12;
const BRICK_GAP = 8;
const BRICK_MARGIN = 48;
const BRICK_TOP = 78;
const BRICK_W = (W - BRICK_MARGIN * 2 - BRICK_GAP * (COLS - 1)) / COLS;
const BRICK_H = 26;
const ROW_H = 34;
let state = "menu";
let score = 0;
let lives = 3;
let levelIndex = 0;
let combo = 0;
let bricksLeft = 0;
let serve = true;
let wideTimer = 0;
let shake = 0;
let flash = 0;
let elapsed = 0;
let banner = null;
let overlayAction = null;
let controlMode = "keyboard";
let pointerX = W / 2;
let balls = [];
let bricks = [];
let particles = [];
let powerups = [];
let waves = [];
let floaters = [];
const keys = { left: false, right: false };
const paddle = {
x: W / 2 - 65,
y: H - 44,
w: 130,
targetW: 130,
h: 14,
vx: 0,
pulse: 0
};
const stars = Array.from({ length: 85 }, () => ({
x: Math.random() * W,
y: Math.random() * H,
size: rand(.4, 1.7),
phase: rand(0, Math.PI * 2)
}));
class SoundSystem {
constructor() {
this.enabled = true;
this.context = null;
this.master = null;
}
init() {
if (!this.enabled) return;
if (!this.context) {
const AudioContext = window.AudioContext || window.webkitAudioContext;
if (!AudioContext) {
this.enabled = false;
updateSoundButton();
return;
}
this.context = new AudioContext();
this.master = this.context.createGain();
this.master.gain.value = 0.2;
this.master.connect(this.context.destination);
}
if (this.context.state === "suspended") this.context.resume();
}
tone(freq, duration = .08, type = "square", volume = .16, slide = 1) {
if (!this.enabled) return;
this.init();
if (!this.context || !this.master) return;
const t = this.context.currentTime;
const oscillator = this.context.createOscillator();
const gain = this.context.createGain();
oscillator.type = type;
oscillator.frequency.setValueAtTime(Math.max(30, freq), t);
if (slide !== 1) {
oscillator.frequency.exponentialRampToValueAtTime(
Math.max(30, freq * slide),
t + duration
);
}
gain.gain.setValueAtTime(volume, t);
gain.gain.exponentialRampToValueAtTime(.0001, t + duration);
oscillator.connect(gain);
gain.connect(this.master);
oscillator.start(t);
oscillator.stop(t + duration + .02);
}
wall() { this.tone(185, .045, "square", .09, 1.15); }
paddle() { this.tone(260, .075, "square", .14, 1.65); }
launch() { this.tone(310, .13, "sawtooth", .13, 2.1); }
power() {
this.tone(440, .16, "sine", .2, 2);
setTimeout(() => this.tone(660, .15, "sine", .15, 1.5), 70);
}
lose() { this.tone(250, .5, "sawtooth", .18, .22); }
brick(hp) {
this.tone(270 + hp * 85 + Math.min(combo, 12) * 9, .07, "square", .14, 1.3);
}
level() {
[440, 554, 659, 880].forEach((note, i) => {
setTimeout(() => this.tone(note, .28, "triangle", .19, 1.03), i * 105);
});
}
}
const sound = new SoundSystem();
function updateSoundButton() {
ui.sound.textContent = sound.enabled ? "Sound on" : "Sound off";
}
function toggleSound() {
sound.enabled = !sound.enabled;
if (sound.enabled) {
sound.init();
sound.tone(520, .08, "sine", .15, 1.3);
}
updateSoundButton();
}
function updateHUD() {
ui.score.textContent = String(score).padStart(6, "0");
ui.level.textContent = `${levelIndex + 1} / ${LEVELS.length}`;
ui.lives.textContent = lives > 0 ? "◆".repeat(lives) : "—";
}
function popScore() {
if (!ui.score.animate) return;
ui.score.animate(
[
{ transform: "scale(1.28)", color: "#43eaff" },
{ transform: "scale(1)", color: "#ffffff" }
],
{ duration: 190, easing: "ease-out" }
);
}
function showOverlay({ kicker, title, text, button, detail = "", action }) {
ui.kicker.textContent = kicker;
ui.title.textContent = title;
ui.text.textContent = text;
ui.primary.textContent = button;
ui.overlayScore.textContent = detail;
overlayAction = action;
ui.overlay.classList.remove("hidden");
}
function hideOverlay() {
ui.overlay.classList.add("hidden");
canvas.focus({ preventScroll: true });
}
function roundedPath(x, y, w, h, r) {
r = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function announce(title, subtitle, duration = 2.2) {
banner = { title, subtitle, duration, time: duration };
}
function makeStuckBall() {
return {
x: paddle.x + paddle.w / 2,
y: paddle.y - 9,
prevX: paddle.x + paddle.w / 2,
prevY: paddle.y - 9,
vx: 0,
vy: 0,
r: 7,
speed: LEVELS[levelIndex].speed,
trail: []
};
}
function setupLevel() {
const level = LEVELS[levelIndex];
bricks = [];
level.layout.forEach((sourceRow, row) => {
const line = sourceRow.padEnd(COLS, ".").slice(0, COLS);
[...line].forEach((cell, col) => {
if (cell === ".") return;
const hp = clamp(parseInt(cell, 10) || 1, 1, 4);
bricks.push({
x: BRICK_MARGIN + col * (BRICK_W + BRICK_GAP),
y: BRICK_TOP + row * ROW_H,
w: BRICK_W,
h: BRICK_H,
hp,
maxHp: hp,
color: HP_COLORS[hp],
alive: true,
flash: 0
});
});
});
bricksLeft = bricks.length;
balls = [];
particles = [];
powerups = [];
waves = [];
floaters = [];
combo = 0;
wideTimer = 0;
serve = true;
paddle.w = 130;
paddle.targetW = 130;
paddle.x = W / 2 - 65;
paddle.vx = 0;
paddle.pulse = 0;
balls.push(makeStuckBall());
updateHUD();
announce(level.name, level.subtitle, 2.5);
}
function startGame() {
score = 0;
lives = 3;
levelIndex = 0;
combo = 0;
setupLevel();
state = "playing";
hideOverlay();
sound.init();
sound.tone(330, .16, "triangle", .16, 1.8);
}
function nextLevel() {
levelIndex++;
setupLevel();
state = "playing";
hideOverlay();
sound.tone(380, .15, "triangle", .15, 1.7);
}
function pauseGame() {
if (state !== "playing") return;
state = "paused";
showOverlay({
kicker: "Systems on standby",
title: "Paused",
text: "Take a breath. The neon will wait for you.",
button: "Resume",
detail: `Score ${score.toLocaleString()}`,
action: resumeGame
});
}
function resumeGame() {
if (state !== "paused") return;
state = "playing";
hideOverlay();
}
function togglePause() {
if (state === "playing") pauseGame();
else if (state === "paused") resumeGame();
}
function launchBall() {
if (!serve || state !== "playing") return;
serve = false;
let angle = rand(-.055, .055) + clamp(paddle.vx / 2200, -.35, .35);
if (keys.left) angle -= .28;
if (keys.right) angle += .28;
angle = clamp(angle, -.65, .65);
for (const ball of balls) {
ball.speed = LEVELS[levelIndex].speed;
ball.vx = ball.speed * Math.sin(angle);
ball.vy = -Math.abs(ball.speed * Math.cos(angle));
}
burst(
paddle.x + paddle.w / 2,
paddle.y - 8,
"#8fffff",
12,
150
);
sound.launch();
}
function resetServe() {
serve = true;
wideTimer = 0;
paddle.targetW = 130;
powerups = [];
balls = [makeStuckBall()];
}
function loseLife(x) {
lives--;
combo = 0;
shake = 15;
flash = .17;
burst(clamp(x, 20, W - 20), H - 18, "#ff4f88", 34, 310);
waves.push({ x: clamp(x, 20, W - 20), y: H - 15, r: 8, life: .6, max: .6, color: "#ff4f88" });
sound.lose();
updateHUD();
if (lives <= 0) {
state = "gameover";
showOverlay({
kicker: "Signal terminated",
title: "Game Over",
text: `The machine held sector ${levelIndex + 1}. Recalibrate, relaunch, and break through.`,
button: "Try again",
detail: `Final score ${score.toLocaleString()}`,
action: startGame
});
} else {
resetServe();
announce(
"Ball lost",
lives === 1 ? "Last ball. Make it count." : `${lives} balls remaining`,
1.8
);
}
}
function completeLevel() {
if (state !== "playing") return;
const bonus = 500 * (levelIndex + 1) + lives * 150;
score += bonus;
updateHUD();
popScore();
shake = 10;
flash = .22;
sound.level();
spawnConfetti();
for (let i = 0; i < 4; i++) {
waves.push({
x: W / 2,
y: H / 2,
r: 15 + i * 20,
life: .8 + i * .12,
max: .8 + i * .12,
color: i % 2 ? "#ff4fd8" : "#43eaff"
});
}
if (levelIndex === LEVELS.length - 1) {
state = "victory";
showOverlay({
kicker: "All five sectors cleared",
title: "Core Broken",
text: "The grid is quiet. You turned the machine's own light against it and painted the void neon.",
button: "Play again",
detail: `Final score ${score.toLocaleString()} · Clear bonus +${bonus.toLocaleString()}`,
action: startGame
});
} else {
state = "levelclear";
showOverlay({
kicker: `Sector ${levelIndex + 1} cleared`,
title: LEVELS[levelIndex].name,
text: `${LEVELS[levelIndex + 1].subtitle} Next stop: ${LEVELS[levelIndex + 1].name}.`,
button: "Next sector",
detail: `Clear bonus +${bonus.toLocaleString()} · Score ${score.toLocaleString()}`,
action: nextLevel
});
}
}
function updatePaddle(dt) {
const oldCenter = paddle.x + paddle.w / 2;
paddle.w += (paddle.targetW - paddle.w) * Math.min(1, dt * 9);
const direction = (keys.right ? 1 : 0) - (keys.left ? 1 : 0);
if (direction !== 0) {
controlMode = "keyboard";
const oldX = paddle.x;
paddle.x += direction * 650 * dt;
paddle.vx = (paddle.x - oldX) / Math.max(dt, .001);
} else if (controlMode === "pointer") {
const desired = pointerX - paddle.w / 2;
const oldX = paddle.x;
paddle.x += (desired - paddle.x) * Math.min(1, dt * 22);
paddle.vx = (paddle.x - oldX) / Math.max(dt, .001);
} else {
paddle.x = oldCenter - paddle.w / 2;
paddle.vx *= Math.pow(.05, dt);
}
paddle.x = clamp(paddle.x, 16, W - 16 - paddle.w);
paddle.pulse = Math.max(0, paddle.pulse - dt * 5);
}
function circleHitsRect(ball, rect) {
const nx = clamp(ball.x, rect.x, rect.x + rect.w);
const ny = clamp(ball.y, rect.y, rect.y + rect.h);
const dx = ball.x - nx;
const dy = ball.y - ny;
return dx * dx + dy * dy <= ball.r * ball.r;
}
function resolveBallBrick(ball, brick) {
const r = ball.r;
if (ball.prevY + r <= brick.y) {
ball.y = brick.y - r - .1;
ball.vy = -Math.abs(ball.vy);
} else if (ball.prevY - r >= brick.y + brick.h) {
ball.y = brick.y + brick.h + r + .1;
ball.vy = Math.abs(ball.vy);
} else if (ball.prevX + r <= brick.x) {
ball.x = brick.x - r - .1;
ball.vx = -Math.abs(ball.vx);
} else if (ball.prevX - r >= brick.x + brick.w) {
ball.x = brick.x + brick.w + r + .1;
ball.vx = Math.abs(ball.vx);
} else {
const choices = [
{ d: Math.abs(ball.x - (brick.x - r)), side: "left" },
{ d: Math.abs(ball.x - (brick.x + brick.w + r)), side: "right" },
{ d: Math.abs(ball.y - (brick.y - r)), side: "top" },
{ d: Math.abs(ball.y - (brick.y + brick.h + r)), side: "bottom" }
].sort((a, b) => a.d - b.d);
switch (choices[0].side) {
case "left":
ball.x = brick.x - r - .1;
ball.vx = -Math.abs(ball.vx);
break;
case "right":
ball.x = brick.x + brick.w + r + .1;
ball.vx = Math.abs(ball.vx);
break;
case "top":
ball.y = brick.y - r - .1;
ball.vy = -Math.abs(ball.vy);
break;
default:
ball.y = brick.y + brick.h + r + .1;
ball.vy = Math.abs(ball.vy);
}
}
}
function damageBrick(brick) {
brick.hp--;
brick.flash = 1;
if (brick.hp > 0) {
score += 25;
burst(brick.x + brick.w / 2, brick.y + brick.h / 2, brick.color, 5, 100);
addFloater(brick.x + brick.w / 2, brick.y, "+25", "#d8e4ff", 12);
shake = Math.max(shake, 1.8);
sound.brick(brick.hp);
updateHUD();
return;
}
brick.alive = false;
bricksLeft--;
combo++;
const base = 100 + (brick.maxHp - 1) * 40;
const multiplier = 1 + Math.min(combo, 20) * .05;
const points = Math.round(base * multiplier / 10) * 10;
score += points;
const cx = brick.x + brick.w / 2;
const cy = brick.y + brick.h / 2;
burst(cx, cy, brick.color, 12 + brick.maxHp * 4, 180 + brick.maxHp * 25);
waves.push({ x: cx, y: cy, r: 4, life: .32, max: .32, color: brick.color });
addFloater(cx, brick.y - 2, `+${points}`, "#ffffff", 15);
if (combo > 1 && combo % 5 === 0) {
addFloater(cx, cy - 22, `${combo} HIT COMBO!`, "#43eaff", 18);
sound.power();
}
if (Math.random() < .16) dropPowerup(cx, cy);
shake = Math.max(shake, 3.5 + brick.maxHp);
flash = Math.min(.16, flash + .035);
sound.brick(brick.maxHp);
updateHUD();
popScore();
}
function collideWithBricks(ball) {
for (const brick of bricks) {
if (!brick.alive || !circleHitsRect(ball, brick)) continue;
resolveBallBrick(ball, brick);
damageBrick(brick);
break;
}
}
function dropPowerup(x, y) {
const roll = Math.random();
let type;
if (roll < .34) type = "wide";
else if (roll < .65) type = "multi";
else if (roll < .95) type = "slow";
else type = "life";
powerups.push({ x, y, type, vy: 145, phase: rand(0, Math.PI * 2) });
}
function applyPowerup(type) {
const config = POWER[type];
if (type === "wide") {
wideTimer = 15;
paddle.targetW = 178;
} else if (type === "multi") {
const source = balls[0];
if (source && balls.length < 6) {
const speed = Math.max(330, Math.hypot(source.vx, source.vy));
for (const angle of [-.68, .68]) {
if (balls.length >= 6) break;
balls.push({
x: source.x,
y: source.y,
prevX: source.x,
prevY: source.y,
vx: speed * Math.sin(angle),
vy: -Math.abs(speed * Math.cos(angle)),
r: 7,
speed,
trail: []
});
}
} else {
score += 500;
}
} else if (type === "slow") {
for (const ball of balls) {
ball.speed = Math.max(285, ball.speed - 55);
const current = Math.max(1, Math.hypot(ball.vx, ball.vy));
ball.vx = ball.vx / current * ball.speed;
ball.vy = ball.vy / current * ball.speed;
}
} else if (type === "life") {
if (lives < 6) lives++;
else score += 1000;
}
score += 100;
addFloater(
paddle.x + paddle.w / 2,
paddle.y - 24,
config.name,
config.color,
18
);
burst(
paddle.x + paddle.w / 2,
paddle.y,
config.color,
20,
210
);
sound.power();
updateHUD();
popScore();
}
function updatePowerups(dt) {
for (let i = powerups.length - 1; i >= 0; i--) {
const p = powerups[i];
p.y += p.vy * dt;
p.phase += dt * 4;
const caught =
p.y + 12 >= paddle.y &&
p.y - 12 <= paddle.y + paddle.h &&
p.x + 18 >= paddle.x &&
p.x - 18 <= paddle.x + paddle.w;
if (caught) {
applyPowerup(p.type);
powerups.splice(i, 1);
} else if (p.y > H + 30) {
powerups.splice(i, 1);
}
}
}
function burst(x, y, color, count = 12, power = 180) {
for (let i = 0; i < count; i++) {
const angle = rand(0, Math.PI * 2);
const speed = rand(power * .25, power);
const life = rand(.28, .75);
particles.push({
x, y,
vx: Math.cos(angle) * speed,
vy: Math.sin(angle) * speed,
gravity: 130,
drag: .975,
size: rand(1, 3.3),
color,
life,
max: life,
spark: Math.random() < .7
});
}
if (particles.length > 850) particles.splice(0, particles.length - 850);
}
function spawnConfetti() {
const colors = ["#43eaff", "#ff4fd8", "#ffcf4a", "#8b68ff", "#7dffb2"];
for (let i = 0; i < 130; i++) {
const life = rand(1.1, 2.5);
particles.push({
x: rand(30, W - 30),
y: rand(-100, 80),
vx: rand(-150, 150),
vy: rand(-40, 130),
gravity: 120,
drag: .992,
size: rand(3, 7),
color: choose(colors),
life,
max: life,
confetti: true,
rotation: rand(0, Math.PI * 2),
spin: rand(-8, 8)
});
}
}
function addFloater(x, y, text, color, size = 15) {
floaters.push({ x, y, text, color, size, life: .9, max: .9 });
}
function updateFX(dt) {
for (const brick of bricks) brick.flash = Math.max(0, brick.flash - dt * 4.5);
for (let i = particles.length - 1; i >= 0; i--) {
const p = particles[i];
p.life -= dt;
if (p.life <= 0) {
particles.splice(i, 1);
continue;
}
p.vy += p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
const drag = Math.pow(p.drag, dt * 60);
p.vx *= drag;
p.vy *= Math.pow(p.drag, dt * 30);
if (p.confetti) p.rotation += p.spin * dt;
}
for (let i = waves.length - 1; i >= 0; i--) {
const wave = waves[i];
wave.life -= dt;
wave.r += 190 * dt;
if (wave.life <= 0) waves.splice(i, 1);
}
for (let i = floaters.length - 1; i >= 0; i--) {
const floater = floaters[i];
floater.life -= dt;
floater.y -= 35 * dt;
if (floater.life <= 0) floaters.splice(i, 1);
}
shake = Math.max(0, shake - dt * 28);
flash = Math.max(0, flash - dt * 1.25);
}
function update(dt) {
if (banner) {
banner.time -= dt;
if (banner.time <= 0) banner = null;
}
if (wideTimer > 0) {
wideTimer -= dt;
if (wideTimer <= 0) {
wideTimer = 0;
paddle.targetW = 130;
}
}
updatePaddle(dt);
if (serve) {
for (const ball of balls) {
ball.x = paddle.x + paddle.w / 2;
ball.y = paddle.y - 9;
ball.prevX = ball.x;
ball.prevY = ball.y;
ball.trail.length = 0;
}
updateFX(dt);
return;
}
let lostX = W / 2;
for (const ball of balls) {
ball.prevX = ball.x;
ball.prevY = ball.y;
ball.trail.push({ x: ball.x, y: ball.y });
if (ball.trail.length > 13) ball.trail.shift();
ball.x += ball.vx * dt;
ball.y += ball.vy * dt;
if (ball.x - ball.r < 16) {
ball.x = 16 + ball.r;
ball.vx = Math.abs(ball.vx);
sound.wall();
} else if (ball.x + ball.r > W - 16) {
ball.x = W - 16 - ball.r;
ball.vx = -Math.abs(ball.vx);
sound.wall();
}
if (ball.y - ball.r < 16) {
ball.y = 16 + ball.r;
ball.vy = Math.abs(ball.vy);
sound.wall();
}
const overPaddle =
ball.x + ball.r >= paddle.x &&
ball.x - ball.r <= paddle.x + paddle.w;
if (
ball.vy > 0 &&
overPaddle &&
ball.y + ball.r >= paddle.y &&
ball.prevY + ball.r <= paddle.y + 7
) {
ball.y = paddle.y - ball.r - .2;
const offset = clamp(
(ball.x - (paddle.x + paddle.w / 2)) / (paddle.w / 2),
-1,
1
);
const angle = clamp(
offset * 1.02 + paddle.vx / 5000,
-1.13,
1.13
);
ball.speed = Math.min(650, Math.max(285, ball.speed + 2.5));
ball.vx = ball.speed * Math.sin(angle);
ball.vy = -Math.abs(ball.speed * Math.cos(angle));
paddle.pulse = 1;
burst(ball.x, paddle.y, "#74f5ff", 4, 85);
sound.paddle();
}
collideWithBricks(ball);
}
balls = balls.filter(ball => {
if (ball.y - ball.r > H + 24) {
lostX = ball.x;
return false;
}
return true;
});
if (balls.length === 0) {
loseLife(lostX);
updateFX(dt);
return;
}
updatePowerups(dt);
if (bricksLeft <= 0) completeLevel();
updateFX(dt);
}
function drawBackground() {
const hue = LEVELS[levelIndex].hue;
ctx.fillStyle = "#040611";
ctx.fillRect(0, 0, W, H);
const glow = ctx.createRadialGradient(W / 2, H * .38, 20, W / 2, H * .38, 520);
glow.addColorStop(0, `hsla(${hue}, 90%, 55%, .105)`);
glow.addColorStop(.55, `hsla(${hue}, 80%, 35%, .035)`);
glow.addColorStop(1, "rgba(0,0,0,0)");
ctx.fillStyle = glow;
ctx.fillRect(0, 0, W, H);
for (const star of stars) {
const alpha = .16 + .25 * (Math.sin(elapsed * 1.7 + star.phase) * .5 + .5);
ctx.globalAlpha = alpha;
ctx.fillStyle = "#c4dcff";
ctx.fillRect(star.x, star.y, star.size, star.size);
}
ctx.globalAlpha = 1;
ctx.strokeStyle = "rgba(116, 148, 225, .04)";
ctx.lineWidth = 1;
ctx.beginPath();
for (let x = 0; x <= W; x += 48) {
ctx.moveTo(x + .5, 0);
ctx.lineTo(x + .5, H);
}
const offset = (elapsed * 9) % 48;
for (let y = offset; y <= H; y += 48) {
ctx.moveTo(0, y + .5);
ctx.lineTo(W, y + .5);
}
ctx.stroke();
const danger = ctx.createLinearGradient(0, H - 90, 0, H);
danger.addColorStop(0, "rgba(255,50,120,0)");
danger.addColorStop(1, "rgba(255,50,120,.035)");
ctx.fillStyle = danger;
ctx.fillRect(0, H - 90, W, 90);
}
function drawBricks() {
for (const brick of bricks) {
if (!brick.alive) continue;
const scale = 1 + brick.flash * .065;
const cx = brick.x + brick.w / 2;
const cy = brick.y + brick.h / 2;
ctx.save();
ctx.translate(cx, cy);
ctx.scale(scale, scale);
ctx.translate(-cx, -cy);
ctx.shadowColor = brick.color;
ctx.shadowBlur = 5 + brick.flash * 17;
roundedPath(brick.x, brick.y, brick.w, brick.h, 6);
ctx.globalAlpha = .82;
ctx.fillStyle = brick.color;
ctx.fill();
ctx.shadowBlur = 0;
ctx.globalAlpha = 1;
const shade = ctx.createLinearGradient(0, brick.y, 0, brick.y + brick.h);
shade.addColorStop(0, "rgba(255,255,255,.34)");
shade.addColorStop(.35, "rgba(255,255,255,0)");
shade.addColorStop(1, "rgba(3,5,20,.42)");
roundedPath(brick.x, brick.y, brick.w, brick.h, 6);
ctx.fillStyle = shade;
ctx.fill();
ctx.strokeStyle = `rgba(255,255,255,${.2 + brick.flash * .65})`;
ctx.lineWidth = 1;
ctx.stroke();
if (brick.maxHp > 1) {
const pipGap = 5;
const startX = cx - ((brick.maxHp - 1) * pipGap) / 2;
for (let i = 0; i < brick.maxHp; i++) {
ctx.beginPath();
ctx.arc(startX + i * pipGap, brick.y + brick.h - 6, 1.35, 0, Math.PI * 2);
ctx.fillStyle = i < brick.hp ? "rgba(255,255,255,.9)" : "rgba(5,8,25,.45)";
ctx.fill();
}
}
if (brick.hp < brick.maxHp) {
ctx.strokeStyle = "rgba(5,8,25,.52)";
ctx.lineWidth = 1.3;
ctx.beginPath();
ctx.moveTo(cx - 3, brick.y + 2);
ctx.lineTo(cx + 1, cy - 2);
ctx.lineTo(cx - 4, cy + 3);
ctx.lineTo(cx + 3, brick.y + brick.h - 3);
ctx.stroke();
}
ctx.restore();
}
}
function drawPaddle() {
const cx = paddle.x + paddle.w / 2;
const cy = paddle.y + paddle.h / 2;
ctx.save();
ctx.translate(cx, cy);
ctx.scale(1 + paddle.pulse * .07, 1 - paddle.pulse * .16);
ctx.translate(-cx, -cy);
ctx.shadowColor = "#43eaff";
ctx.shadowBlur = 20 + paddle.pulse * 16;
const gradient = ctx.createLinearGradient(paddle.x, 0, paddle.x + paddle.w, 0);
gradient.addColorStop(0, "#5176ff");
gradient.addColorStop(.22, "#43eaff");
gradient.addColorStop(.5, "#e5ffff");
gradient.addColorStop(.78, "#43eaff");
gradient.addColorStop(1, "#a664ff");
roundedPath(paddle.x, paddle.y, paddle.w, paddle.h, 7);
ctx.fillStyle = gradient;
ctx.fill();
ctx.shadowBlur = 0;
roundedPath(paddle.x + 5, paddle.y + 2, paddle.w - 10, 3, 2);
ctx.fillStyle = "rgba(255,255,255,.68)";
ctx.fill();
ctx.fillStyle = "#071222";
ctx.fillRect(cx - 13, paddle.y + 7, 26, 2);
ctx.restore();
}
function drawBalls() {
ctx.save();
ctx.globalCompositeOperation = "lighter";
for (const ball of balls) {
for (let i = 0; i < ball.trail.length; i++) {
const point = ball.trail[i];
const t = (i + 1) / ball.trail.length;
ctx.globalAlpha = t * .22;
ctx.fillStyle = "#43dfff";
ctx.beginPath();
ctx.arc(point.x, point.y, ball.r * t * .9, 0, Math.PI * 2);
ctx.fill();
}
}
ctx.globalCompositeOperation = "source-over";
for (const ball of balls) {
ctx.globalAlpha = 1;
ctx.shadowColor = "#77efff";
ctx.shadowBlur = 23;
const gradient = ctx.createRadialGradient(
ball.x - 2, ball.y - 2, 0,
ball.x, ball.y, ball.r
);
gradient.addColorStop(0, "#ffffff");
gradient.addColorStop(.45, "#c9ffff");
gradient.addColorStop(1, "#48cbff");
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.arc(ball.x, ball.y, ball.r, 0, Math.PI * 2);
ctx.fill();
}
ctx.restore();
}
function drawPowerups() {
for (const p of powerups) {
const config = POWER[p.type];
const bob = Math.sin(p.phase) * 2;
ctx.save();
ctx.translate(p.x, p.y + bob);
ctx.rotate(Math.sin(p.phase * .7) * .08);
ctx.shadowColor = config.color;
ctx.shadowBlur = 18;
roundedPath(-18, -12, 36, 24, 8);
ctx.fillStyle = "rgba(8,13,31,.94)";
ctx.fill();
ctx.strokeStyle = config.color;
ctx.lineWidth = 1.5;
ctx.stroke();
ctx.shadowBlur = 8;
ctx.fillStyle = config.color;
ctx.font = "900 14px ui-monospace, Consolas, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(config.letter, 0, 1);
ctx.restore();
}
}
function drawFX() {
for (const wave of waves) {
ctx.save();
ctx.globalAlpha = Math.max(0, wave.life / wave.max);
ctx.strokeStyle = wave.color;
ctx.lineWidth = 2;
ctx.shadowColor = wave.color;
ctx.shadowBlur = 10;
ctx.beginPath();
ctx.arc(wave.x, wave.y, wave.r, 0, Math.PI * 2);
ctx.stroke();
ctx.restore();
}
ctx.save();
ctx.globalCompositeOperation = "lighter";
for (const p of particles) {
const alpha = Math.max(0, p.life / p.max);
ctx.globalAlpha = alpha;
ctx.fillStyle = p.color;
ctx.strokeStyle = p.color;
if (p.confetti) {
ctx.save();
ctx.globalCompositeOperation = "source-over";
ctx.translate(p.x, p.y);
ctx.rotate(p.rotation);
ctx.fillRect(-p.size / 2, -p.size / 3, p.size, p.size * .66);
ctx.restore();
} else if (p.spark) {
ctx.lineWidth = Math.max(1, p.size * .55);
ctx.beginPath();
ctx.moveTo(p.x, p.y);
ctx.lineTo(p.x - p.vx * .027, p.y - p.vy * .027);
ctx.stroke();
} else {
ctx.beginPath();
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
ctx.fill();
}
}
ctx.restore();
for (const floater of floaters) {
ctx.save();
ctx.globalAlpha = Math.min(1, floater.life * 2.5);
ctx.fillStyle = floater.color;
ctx.shadowColor = floater.color;
ctx.shadowBlur = 10;
ctx.textAlign = "center";
ctx.font = `900 ${floater.size}px ui-monospace, Consolas, monospace`;
ctx.fillText(floater.text, floater.x, floater.y);
ctx.restore();
}
}
function drawCanvasHUD() {
ctx.save();
ctx.strokeStyle = "rgba(104,213,255,.25)";
ctx.lineWidth = 2;
ctx.shadowColor = "#43eaff";
ctx.shadowBlur = 8;
ctx.beginPath();
ctx.moveTo(8, H - 8);
ctx.lineTo(8, 8);
ctx.lineTo(W - 8, 8);
ctx.lineTo(W - 8, H - 8);
ctx.stroke();
ctx.shadowBlur = 0;
ctx.textAlign = "left";
ctx.fillStyle = "rgba(197,218,255,.62)";
ctx.font = "800 11px ui-monospace, Consolas, monospace";
ctx.fillText(
`SECTOR ${String(levelIndex + 1).padStart(2, "0")} // ${LEVELS[levelIndex].name.toUpperCase()}`,
26,
44
);
ctx.textAlign = "right";
if (wideTimer > 0) {
ctx.fillStyle = "#43eaff";
ctx.fillText(`WIDE ${wideTimer.toFixed(1)}s`, W - 26, 44);
} else if (combo >= 2) {
const multiplier = 1 + Math.min(combo, 20) * .05;
ctx.fillStyle = combo >= 10 ? "#ff77df" : "rgba(164,197,255,.72)";
ctx.fillText(`${combo} HIT COMBO ×${multiplier.toFixed(2)}`, W - 26, 44);
}
if (state === "playing" && serve) {
ctx.globalAlpha = .7 + Math.sin(elapsed * 5) * .25;
ctx.textAlign = "center";
ctx.fillStyle = "#d9ffff";
ctx.shadowColor = "#43eaff";
ctx.shadowBlur = 12;
ctx.font = "800 13px ui-monospace, Consolas, monospace";
ctx.fillText("CLICK OR PRESS SPACE TO LAUNCH", W / 2, H - 98);
}
if (banner && state === "playing") {
const age = banner.duration - banner.time;
const alpha = clamp(Math.min(age * 2.5, banner.time * 1.8), 0, 1);
ctx.globalAlpha = alpha;
ctx.textAlign = "center";
ctx.shadowColor = LEVELS[levelIndex].hue === 28 ? "#ffad38" : "#8b68ff";
ctx.shadowBlur = 22;
ctx.fillStyle = "#f3f5ff";
ctx.font = "950 31px system-ui, sans-serif";
ctx.fillText(banner.title.toUpperCase(), W / 2, 423);
ctx.shadowBlur = 0;
ctx.fillStyle = "#9cadd2";
ctx.font = "700 12px ui-monospace, Consolas, monospace";
ctx.fillText(banner.subtitle, W / 2, 448);
}
ctx.restore();
}
function render() {
drawBackground();
ctx.save();
if (shake > 0) ctx.translate(rand(-shake, shake), rand(-shake, shake));
drawBricks();
drawPowerups();
drawPaddle();
drawBalls();
drawFX();
ctx.restore();
drawCanvasHUD();
if (flash > 0) {
ctx.fillStyle = `rgba(255,255,255,${Math.min(.24, flash)})`;
ctx.fillRect(0, 0, W, H);
}
}
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointerX = clamp((event.clientX - rect.left) * W / rect.width, 0, W);
controlMode = "pointer";
}
canvas.addEventListener("pointermove", setPointer);
canvas.addEventListener("pointerdown", event => {
event.preventDefault();
sound.init();
setPointer(event);
canvas.focus({ preventScroll: true });
if (state === "playing" && serve) launchBall();
});
canvas.addEventListener("contextmenu", event => event.preventDefault());
window.addEventListener("keydown", event => {
if (["ArrowLeft", "ArrowRight", "Space"].includes(event.code)) {
event.preventDefault();
}
sound.init();
if (event.code === "ArrowLeft" || event.code === "KeyA") keys.left = true;
if (event.code === "ArrowRight" || event.code === "KeyD") keys.right = true;
if (event.code === "KeyM" && !event.repeat) toggleSound();
if ((event.code === "KeyP" || event.code === "Escape") && !event.repeat) {
togglePause();
}
if ((event.code === "Space" || event.code === "Enter") && !event.repeat) {
if (!ui.overlay.classList.contains("hidden")) {
if (overlayAction) overlayAction();
} else if (state === "playing" && serve) {
launchBall();
}
}
}, { passive: false });
window.addEventListener("keyup", event => {
if (event.code === "ArrowLeft" || event.code === "KeyA") keys.left = false;
if (event.code === "ArrowRight" || event.code === "KeyD") keys.right = false;
});
window.addEventListener("blur", () => {
keys.left = false;
keys.right = false;
if (state === "playing") pauseGame();
});
document.addEventListener("visibilitychange", () => {
if (document.hidden && state === "playing") pauseGame();
});
ui.primary.addEventListener("click", () => {
sound.init();
if (overlayAction) overlayAction();
});
ui.sound.addEventListener("click", () => {
sound.init();
toggleSound();
});
ui.pause.addEventListener("click", () => {
sound.init();
togglePause();
});
let last = performance.now();
let accumulator = 0;
function frame(now) {
const dt = Math.min(.05, Math.max(0, (now - last) / 1000));
last = now;
elapsed += dt;
if (state === "playing") {
accumulator = Math.min(accumulator + dt, .1);
while (accumulator >= STEP) {
update(STEP);
accumulator -= STEP;
if (state !== "playing") {
accumulator = 0;
break;
}
}
} else {
updateFX(dt);
}
render();
requestAnimationFrame(frame);
}
setupLevel();
state = "menu";
updateSoundButton();
updateHUD();
showOverlay({
kicker: "A tiny arcade odyssey",
title: "Neon Breakout",
text: "Shatter five sectors, chain hits for combo points, and catch falling power cores. Wide paddle, multiball, slow motion, and extra balls await.",
button: "Start game",
action: startGame
});
requestAnimationFrame(frame);
})();
</script>
</body>
</html>

