Run details
- Model
- deepseek/deepseek-v4.1-flash
- Route
- OpenRouter API
- Served by
- CoreWeave
- Effort
- high (OpenRouter default)
- Limits
- 60 min · 943,718 output tokens (model max)
- Date
- 24 Oct 2026
- Time
- 2 min 25 s
- Size
- 31 kB
- Tokens
- 106 in, 31,049 out (19,860 thinking)
- List price
- $0.015 at today's price ($0.05 in / $0.48 out per M)
- Paid
- $0.020
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
31 kB 1,103 lines Raw
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Neon Breakout</title>
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
background: #05070f;
overflow: hidden;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
body {
display: flex;
align-items: center;
justify-content: center;
}
canvas {
display: block;
touch-action: none;
cursor: none;
border-radius: 10px;
box-shadow: 0 0 60px rgba(60, 190, 255, 0.18), 0 0 140px rgba(120, 40, 200, 0.14);
}
</style>
</head>
<body>
<canvas id="game"></canvas>
<script>
(function () {
'use strict';
// ------------------------------------------------------------------
// Canvas setup
// ------------------------------------------------------------------
const W = 900, H = 640;
const FONT = 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace';
const TITLE_FONT = 'system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
const cvs = document.getElementById('game');
const ctx = cvs.getContext('2d');
let DPR = 1;
function resize() {
DPR = Math.min(window.devicePixelRatio || 1, 2);
const scale = Math.min(window.innerWidth / W, window.innerHeight / H);
cvs.style.width = Math.floor(W * scale) + 'px';
cvs.style.height = Math.floor(H * scale) + 'px';
cvs.width = Math.round(W * DPR);
cvs.height = Math.round(H * DPR);
}
resize();
window.addEventListener('resize', resize);
function toLogicalX(clientX) {
const r = cvs.getBoundingClientRect();
return (clientX - r.left) / r.width * W;
}
// ------------------------------------------------------------------
// Audio (WebAudio, no external files)
// ------------------------------------------------------------------
let actx = null;
function initAudio() {
if (!actx) {
try {
actx = new (window.AudioContext || window.webkitAudioContext)();
} catch (e) {
actx = null;
}
}
if (actx && actx.state === 'suspended') actx.resume();
}
function tone(freq, dur, type, vol, slideTo) {
if (!actx || actx.state !== 'running') return;
const t = actx.currentTime;
const o = actx.createOscillator();
const g = actx.createGain();
o.type = type || 'square';
o.frequency.setValueAtTime(freq, t);
if (slideTo) o.frequency.exponentialRampToValueAtTime(Math.max(20, slideTo), t + dur);
g.gain.setValueAtTime(0.0001, t);
g.gain.exponentialRampToValueAtTime(vol || 0.06, t + 0.012);
g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
o.connect(g);
g.connect(actx.destination);
o.start(t);
o.stop(t + dur + 0.03);
}
// ------------------------------------------------------------------
// Layout constants
// ------------------------------------------------------------------
const COLS = 11;
const FIELD_MARGIN = 48;
const BRICK_TOP = 96;
const BRICK_H = 26;
const BRICK_GAP = 6;
const BRICK_W = (W - FIELD_MARGIN * 2 - BRICK_GAP * (COLS - 1)) / COLS;
const BRICK_COLORS = {
'1': { a: '#7df9ff', b: '#0d8fb5' },
'2': { a: '#ff8ad8', b: '#b0197f' },
'3': { a: '#ffcf6b', b: '#d97300' },
'X': { a: '#a9bbd4', b: '#46536c' }
};
const POWER_COLORS = {
wide: '#4ade80',
multi: '#c084fc',
fire: '#fb923c',
life: '#f472b6'
};
const POWER_LETTERS = { wide: 'W', multi: 'M', fire: 'F', life: '+' };
// ------------------------------------------------------------------
// Levels
// ------------------------------------------------------------------
const LEVELS = [
{ speed: 340, rows: [
'11111111111',
'11111111111',
'22222222222'
]},
{ speed: 356, rows: [
'.....1.....',
'....121....',
'...12221...',
'..1222221..',
'.122222221.'
]},
{ speed: 372, rows: [
'1.1.1.1.1.1',
'.2.2.2.2.2.',
'1.1.1.1.1.1',
'.3.3.3.3.3.',
'1.1.1.1.1.1'
]},
{ speed: 390, rows: [
'XX1111111XX',
'3.........3',
'3.2222222.3',
'3.2.....2.3',
'3.2222222.3'
]},
{ speed: 408, rows: [
'33333333333',
'32222222223',
'32111111123',
'32222222223',
'33333333333'
]},
{ speed: 426, rows: [
'..2222222..',
'.22.....22.',
'22.11111.22',
'22.1...1.22',
'22.11111.22',
'.22.....22.',
'..2222222..'
]}
];
// ------------------------------------------------------------------
// Game state
// ------------------------------------------------------------------
let bricks = [], balls = [], particles = [], floaters = [], powerups = [];
let bricksRemaining = 0;
const paddle = {
x: W / 2 - 65, y: H - 52, w: 130, h: 16,
targetW: 130, speed: 760, squash: 0
};
const effects = { wide: 0, fire: 0 };
const state = {
mode: 'menu',
score: 0,
lives: 3,
levelIndex: 0,
combo: 0,
shake: 0,
timer: 0,
time: 0,
clearBonus: 0
};
const input = { left: false, right: false, mouseX: W / 2, mode: 'key' };
// ------------------------------------------------------------------
// Helpers
// ------------------------------------------------------------------
function clamp(v, a, b) { return v < a ? a : (v > b ? b : v); }
function rr(x, y, w, h, r) {
r = Math.min(r, Math.abs(w) / 2, Math.abs(h) / 2);
if (r < 0) r = 0;
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 comboMult() { return Math.min(Math.max(state.combo, 1), 5); }
// ------------------------------------------------------------------
// Level building
// ------------------------------------------------------------------
function buildBricks(rows) {
bricks = [];
bricksRemaining = 0;
for (let r = 0; r < rows.length; r++) {
const row = rows[r];
for (let c = 0; c < COLS; c++) {
const ch = row[c];
if (!ch || ch === '.') continue;
const x = FIELD_MARGIN + c * (BRICK_W + BRICK_GAP);
const y = BRICK_TOP + r * (BRICK_H + BRICK_GAP);
const indestructible = ch === 'X';
const hp = indestructible ? Infinity : parseInt(ch, 10);
bricks.push({
x: x, y: y, w: BRICK_W, h: BRICK_H,
hp: hp, maxHp: indestructible ? 0 : hp,
key: ch, indestructible: indestructible,
flash: 0, alive: true
});
if (!indestructible) bricksRemaining++;
}
}
}
function makeBall(x, y, vx, vy) {
return { x: x, y: y, vx: vx, vy: vy, r: 9, offset: 0, trail: [] };
}
function resetBall() {
const lv = LEVELS[state.levelIndex];
balls = [makeBall(paddle.x + paddle.w / 2, paddle.y - 14, 0, 0)];
balls[0].levelSpeed = lv.speed;
}
function loadLevel(i) {
state.levelIndex = i;
buildBricks(LEVELS[i].rows);
balls = [];
powerups = [];
particles = [];
floaters = [];
effects.wide = 0;
effects.fire = 0;
paddle.targetW = 130;
paddle.w = 130;
paddle.x = W / 2 - paddle.w / 2;
paddle.squash = 0;
state.combo = 0;
state.clearBonus = 0;
resetBall();
}
function startGame() {
state.score = 0;
state.lives = 3;
state.shake = 0;
loadLevel(0);
state.mode = 'serve';
tone(440, 0.09, 'triangle', 0.05, 660);
}
function nextLevel() {
if (state.levelIndex + 1 >= LEVELS.length) {
state.mode = 'win';
state.timer = 1.0;
} else {
loadLevel(state.levelIndex + 1);
state.mode = 'serve';
}
}
function loseLife() {
state.lives--;
state.combo = 0;
state.shake = 0.9;
powerups = [];
effects.wide = 0;
effects.fire = 0;
paddle.targetW = 130;
tone(320, 0.35, 'sawtooth', 0.07, 70);
if (state.lives <= 0) {
state.mode = 'over';
state.timer = 1.1;
} else {
resetBall();
state.mode = 'serve';
}
}
function levelClear() {
state.mode = 'clear';
state.timer = 2.2;
state.clearBonus = 250 + state.lives * 150;
state.score += state.clearBonus;
state.shake = 0.7;
for (let i = 0; i < 70; i++) {
spawnParticles(
Math.random() * W,
Math.random() * H * 0.6,
['#4fe3ff', '#ff6ec7', '#ffc247', '#8affc1'][i % 4],
1
);
}
tone(523, 0.12, 'triangle', 0.07);
setTimeout(function () { tone(659, 0.12, 'triangle', 0.07); }, 100);
setTimeout(function () { tone(784, 0.22, 'triangle', 0.07); }, 200);
}
// ------------------------------------------------------------------
// Particles & floating text
// ------------------------------------------------------------------
function spawnParticles(x, y, color, n) {
for (let i = 0; i < n; i++) {
const a = Math.random() * Math.PI * 2;
const sp = 50 + Math.random() * 230;
const life = 0.35 + Math.random() * 0.5;
particles.push({
x: x, y: y,
vx: Math.cos(a) * sp,
vy: Math.sin(a) * sp - 60,
life: life, maxLife: life,
color: color,
size: 1.8 + Math.random() * 3.2
});
}
}
function addFloater(text, x, y, color) {
floaters.push({ text: text, x: x, y: y, life: 1.0, maxLife: 1.0, color: color || '#eafcff' });
}
function updateParticles(dt) {
for (let i = particles.length - 1; i >= 0; i--) {
const p = particles[i];
p.vy += 760 * dt;
p.vx *= 0.985;
p.x += p.vx * dt;
p.y += p.vy * dt;
p.life -= dt;
if (p.life <= 0) particles.splice(i, 1);
}
}
function updateFloaters(dt) {
for (let i = floaters.length - 1; i >= 0; i--) {
const f = floaters[i];
f.y -= 46 * dt;
f.life -= dt;
if (f.life <= 0) floaters.splice(i, 1);
}
}
// ------------------------------------------------------------------
// Power-ups
// ------------------------------------------------------------------
function maybeDropPowerup(br) {
if (Math.random() > 0.14) return;
const table = ['wide', 'wide', 'multi', 'multi', 'fire', 'life'];
const t = table[Math.floor(Math.random() * table.length)];
powerups.push({
x: br.x + br.w / 2,
y: br.y + br.h / 2,
vy: 135,
type: t,
r: 15
});
}
function applyPowerup(type, x, y) {
if (type === 'wide') {
effects.wide = 16;
paddle.targetW = 185;
addFloater('WIDE PADDLE', x, y, POWER_COLORS.wide);
tone(660, 0.09, 'square', 0.06, 990);
} else if (type === 'multi') {
multiBall();
addFloater('MULTIBALL', x, y, POWER_COLORS.multi);
tone(520, 0.09, 'square', 0.06, 880);
} else if (type === 'fire') {
effects.fire = 7;
addFloater('FIREBALL', x, y, POWER_COLORS.fire);
tone(300, 0.16, 'sawtooth', 0.06, 900);
} else if (type === 'life') {
state.lives++;
addFloater('+1 LIFE', x, y, POWER_COLORS.life);
tone(880, 0.12, 'triangle', 0.07, 1320);
}
spawnParticles(x, y, POWER_COLORS[type], 14);
}
function multiBall() {
const cur = balls.slice();
for (let i = 0; i < cur.length; i++) {
const b = cur[i];
const sp = Math.hypot(b.vx, b.vy) || 300;
const ang = Math.atan2(b.vy, b.vx);
const deltas = [-0.42, 0.42];
for (let d = 0; d < deltas.length; d++) {
if (balls.length >= 9) return;
const na = ang + deltas[d];
balls.push(makeBall(b.x, b.y, Math.cos(na) * sp, Math.sin(na) * sp));
}
}
}
function updatePowerups(dt) {
for (let i = powerups.length - 1; i >= 0; i--) {
const p = powerups[i];
p.y += p.vy * dt;
if (p.y - p.r > H + 20) { powerups.splice(i, 1); continue; }
if (p.y + p.r > paddle.y && p.y - p.r < paddle.y + paddle.h &&
p.x > paddle.x - 10 && p.x < paddle.x + paddle.w + 10) {
applyPowerup(p.type, p.x, paddle.y - 10);
powerups.splice(i, 1);
}
}
}
// ------------------------------------------------------------------
// Physics
// ------------------------------------------------------------------
function bounceOffBrick(b, br) {
const bcx = br.x + br.w / 2;
const bcy = br.y + br.h / 2;
const dx = b.x - bcx;
const dy = b.y - bcy;
const ox = (br.w / 2 + b.r) - Math.abs(dx);
const oy = (br.h / 2 + b.r) - Math.abs(dy);
if (ox < oy) {
b.vx = Math.abs(b.vx) * (dx >= 0 ? 1 : -1);
b.x += dx >= 0 ? ox : -ox;
} else {
b.vy = Math.abs(b.vy) * (dy >= 0 ? 1 : -1);
b.y += dy >= 0 ? oy : -oy;
}
}
function normalizeVelocity(b) {
const sp = Math.hypot(b.vx, b.vy) || 1;
const minVy = 0.24 * sp;
if (Math.abs(b.vy) < minVy) {
b.vy = (b.vy >= 0 ? 1 : -1) * minVy;
const nx = Math.sqrt(Math.max(0, sp * sp - b.vy * b.vy));
b.vx = (b.vx >= 0 ? 1 : -1) * nx;
}
}
function collideWalls(b) {
if (b.x - b.r < 0) {
b.x = b.r;
b.vx = Math.abs(b.vx);
tone(200, 0.05, 'square', 0.03);
} else if (b.x + b.r > W) {
b.x = W - b.r;
b.vx = -Math.abs(b.vx);
tone(200, 0.05, 'square', 0.03);
}
if (b.y - b.r < 0) {
b.y = b.r;
b.vy = Math.abs(b.vy);
tone(240, 0.05, 'square', 0.03);
}
}
function damageBrick(br) {
br.flash = 1;
if (br.indestructible) {
tone(90, 0.08, 'square', 0.05);
spawnParticles(br.x + br.w / 2, br.y + br.h / 2, '#a9bbd4', 4);
return;
}
br.hp--;
if (br.hp > 0) {
tone(360 + br.hp * 90, 0.06, 'square', 0.045, 260);
spawnParticles(br.x + br.w / 2, br.y + br.h / 2, BRICK_COLORS[br.key].a, 5);
return;
}
br.alive = false;
bricksRemaining--;
state.combo++;
const mult = comboMult();
const pts = 10 * br.maxHp * mult;
state.score += pts;
addFloater('+' + pts, br.x + br.w / 2, br.y + br.h / 2, BRICK_COLORS[br.key].a);
spawnParticles(br.x + br.w / 2, br.y + br.h / 2, BRICK_COLORS[br.key].a, 14);
state.shake = Math.min(0.85, state.shake + 0.22);
tone(620 + br.maxHp * 120, 0.12, 'triangle', 0.06, 240);
maybeDropPowerup(br);
if (bricksRemaining <= 0) levelClear();
}
function collideBricks(b) {
for (let i = 0; i < bricks.length; i++) {
const br = bricks[i];
if (!br.alive) continue;
if (b.x + b.r < br.x || b.x - b.r > br.x + br.w ||
b.y + b.r < br.y || b.y - b.r > br.y + br.h) continue;
const cx = clamp(b.x, br.x, br.x + br.w);
const cy = clamp(b.y, br.y, br.y + br.h);
const dx = b.x - cx, dy = b.y - cy;
if (dx * dx + dy * dy > b.r * b.r) continue;
if (effects.fire > 0) {
if (br.indestructible) {
bounceOffBrick(b, br);
damageBrick(br);
} else {
damageBrick(br);
}
} else {
bounceOffBrick(b, br);
damageBrick(br);
normalizeVelocity(b);
}
return;
}
}
function collidePaddle(b) {
if (b.vy <= 0) return;
if (b.x + b.r < paddle.x || b.x - b.r > paddle.x + paddle.w) return;
if (b.y + b.r < paddle.y || b.y - b.r > paddle.y + paddle.h) return;
const rel = clamp((b.x - (paddle.x + paddle.w / 2)) / (paddle.w / 2), -1, 1);
const sp = Math.hypot(b.vx, b.vy) || 300;
const angle = rel * (Math.PI * 0.42);
b.vx = Math.sin(angle) * sp;
b.vy = -Math.cos(angle) * sp;
b.y = paddle.y - b.r - 0.5;
state.combo = 0;
paddle.squash = 1;
tone(300 + rel * 140, 0.07, 'square', 0.05, 420);
spawnParticles(b.x, paddle.y, '#7dd3fc', 6);
}
function stepBall(b, dt) {
const speed = Math.hypot(b.vx, b.vy);
const steps = Math.max(1, Math.ceil((speed * dt) / (b.r * 0.7)));
const sdt = dt / steps;
for (let s = 0; s < steps; s++) {
if (state.mode !== 'play') return;
b.x += b.vx * sdt;
b.y += b.vy * sdt;
collideWalls(b);
collideBricks(b);
collidePaddle(b);
}
}
function updateBalls(dt) {
for (let i = balls.length - 1; i >= 0; i--) {
const b = balls[i];
stepBall(b, dt);
b.trail.push({ x: b.x, y: b.y });
if (b.trail.length > 11) b.trail.shift();
if (b.y - b.r > H + 25) balls.splice(i, 1);
if (state.mode !== 'play') return;
}
if (balls.length === 0 && state.mode === 'play') loseLife();
}
// ------------------------------------------------------------------
// Update
// ------------------------------------------------------------------
function updatePaddle(dt) {
if (input.mode === 'mouse') {
const target = input.mouseX - paddle.w / 2;
paddle.x += (target - paddle.x) * Math.min(1, dt * 22);
} else {
const dir = (input.right ? 1 : 0) - (input.left ? 1 : 0);
if (dir !== 0) paddle.x += dir * paddle.speed * dt;
}
const nw = paddle.w + (paddle.targetW - paddle.w) * Math.min(1, dt * 12);
paddle.x += (paddle.w - nw) / 2;
paddle.w = nw;
paddle.x = clamp(paddle.x, 0, W - paddle.w);
if (paddle.squash > 0) paddle.squash = Math.max(0, paddle.squash - dt * 5);
}
function updateEffects(dt) {
if (effects.wide > 0) {
effects.wide -= dt;
if (effects.wide <= 0) { effects.wide = 0; paddle.targetW = 130; }
}
if (effects.fire > 0) {
effects.fire -= dt;
if (effects.fire <= 0) effects.fire = 0;
}
}
function update(dt) {
state.time += dt;
if (state.shake > 0) state.shake = Math.max(0, state.shake - dt * 3.2);
updatePaddle(dt);
updateEffects(dt);
if (state.mode === 'serve') {
for (let i = 0; i < balls.length; i++) {
const b = balls[i];
b.x = paddle.x + paddle.w / 2 + b.offset;
b.y = paddle.y - b.r - 2;
b.trail.length = 0;
}
} else if (state.mode === 'play') {
updateBalls(dt);
}
updatePowerups(dt);
updateParticles(dt);
updateFloaters(dt);
for (let i = 0; i < bricks.length; i++) {
if (bricks[i].flash > 0) bricks[i].flash = Math.max(0, bricks[i].flash - dt * 5);
}
if (state.mode === 'clear') {
state.timer -= dt;
if (state.timer <= 0) nextLevel();
} else if (state.mode === 'over' || state.mode === 'win') {
state.timer -= dt;
}
}
// ------------------------------------------------------------------
// Input
// ------------------------------------------------------------------
function launch() {
if (state.mode !== 'serve') return;
state.mode = 'play';
state.combo = 0;
for (let i = 0; i < balls.length; i++) {
const b = balls[i];
const ang = -Math.PI / 2 + (Math.random() - 0.5) * 0.16;
const sp = b.levelSpeed || LEVELS[state.levelIndex].speed;
b.vx = Math.cos(ang) * sp;
b.vy = Math.sin(ang) * sp;
}
tone(660, 0.08, 'triangle', 0.06, 320);
}
function primaryAction() {
initAudio();
if (state.mode === 'menu') {
startGame();
} else if (state.mode === 'serve') {
launch();
} else if (state.mode === 'clear') {
if (state.timer <= 0) nextLevel();
} else if (state.mode === 'over' || state.mode === 'win') {
if (state.timer <= 0) startGame();
}
}
window.addEventListener('keydown', function (e) {
if (e.code === 'ArrowLeft' || e.code === 'KeyA') {
input.left = true;
input.mode = 'key';
e.preventDefault();
} else if (e.code === 'ArrowRight' || e.code === 'KeyD') {
input.right = true;
input.mode = 'key';
e.preventDefault();
} else if (e.code === 'Space' || e.code === 'Enter' || e.code === 'NumpadEnter') {
e.preventDefault();
primaryAction();
}
});
window.addEventListener('keyup', function (e) {
if (e.code === 'ArrowLeft' || e.code === 'KeyA') input.left = false;
if (e.code === 'ArrowRight' || e.code === 'KeyD') input.right = false;
});
cvs.addEventListener('pointermove', function (e) {
input.mouseX = toLogicalX(e.clientX);
input.mode = 'mouse';
});
cvs.addEventListener('pointerdown', function (e) {
e.preventDefault();
input.mouseX = toLogicalX(e.clientX);
input.mode = 'mouse';
primaryAction();
});
cvs.addEventListener('contextmenu', function (e) { e.preventDefault(); });
// ------------------------------------------------------------------
// Drawing
// ------------------------------------------------------------------
function drawBackground() {
const g = ctx.createLinearGradient(0, 0, 0, H);
g.addColorStop(0, '#070a14');
g.addColorStop(0.55, '#0c1322');
g.addColorStop(1, '#131b30');
ctx.fillStyle = g;
ctx.fillRect(0, 0, W, H);
ctx.strokeStyle = 'rgba(90, 160, 255, 0.055)';
ctx.lineWidth = 1;
ctx.beginPath();
for (let x = 0; x <= W; x += 45) {
ctx.moveTo(Math.floor(x) + 0.5, 0);
ctx.lineTo(Math.floor(x) + 0.5, H);
}
for (let y = 0; y <= H; y += 45) {
ctx.moveTo(0, Math.floor(y) + 0.5);
ctx.lineTo(W, Math.floor(y) + 0.5);
}
ctx.stroke();
// top glow bar
const tg = ctx.createLinearGradient(0, 0, 0, 90);
tg.addColorStop(0, 'rgba(70, 190, 255, 0.10)');
tg.addColorStop(1, 'rgba(70, 190, 255, 0)');
ctx.fillStyle = tg;
ctx.fillRect(0, 0, W, 90);
}
function drawBricks() {
for (let i = 0; i < bricks.length; i++) {
const br = bricks[i];
if (!br.alive) continue;
const col = BRICK_COLORS[br.key] || BRICK_COLORS['1'];
const dmg = br.indestructible ? 0 : (br.maxHp - br.hp) / br.maxHp;
ctx.fillStyle = col.b;
rr(br.x, br.y, br.w, br.h, 7);
ctx.fill();
ctx.globalAlpha = 0.92 - dmg * 0.62;
ctx.fillStyle = col.a;
rr(br.x + 2.5, br.y + 2.5, br.w - 5, br.h - 5, 5);
ctx.fill();
ctx.globalAlpha = 1;
ctx.globalAlpha = 0.3;
ctx.fillStyle = '#ffffff';
rr(br.x + 6, br.y + 4.5, br.w - 12, 3.5, 2);
ctx.fill();
ctx.globalAlpha = 1;
if (br.indestructible) {
ctx.strokeStyle = 'rgba(20, 28, 42, 0.7)';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(br.x + 10, br.y + br.h - 6);
ctx.lineTo(br.x + br.w - 10, br.y + 6);
ctx.moveTo(br.x + 10, br.y + 6);
ctx.lineTo(br.x + br.w - 10, br.y + br.h - 6);
ctx.stroke();
}
if (br.flash > 0) {
ctx.globalAlpha = br.flash * 0.85;
ctx.fillStyle = '#ffffff';
rr(br.x, br.y, br.w, br.h, 7);
ctx.fill();
ctx.globalAlpha = 1;
}
}
}
function drawPowerups() {
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
for (let i = 0; i < powerups.length; i++) {
const p = powerups[i];
const col = POWER_COLORS[p.type];
ctx.save();
ctx.translate(p.x, p.y);
ctx.shadowColor = col;
ctx.shadowBlur = 16;
ctx.fillStyle = col;
rr(-p.r, -p.r * 0.78, p.r * 2, p.r * 1.56, 7);
ctx.fill();
ctx.shadowBlur = 0;
ctx.fillStyle = '#07101d';
ctx.font = '900 16px ' + FONT;
ctx.fillText(POWER_LETTERS[p.type], 0, 1);
ctx.restore();
}
}
function drawPaddle() {
const sq = paddle.squash;
const py = paddle.y + sq * 4;
const ph = Math.max(4, paddle.h - sq * 5);
ctx.shadowColor = '#31d6ff';
ctx.shadowBlur = 20;
const g = ctx.createLinearGradient(0, py, 0, py + ph);
g.addColorStop(0, '#e6ffff');
g.addColorStop(0.45, '#4fd8ff');
g.addColorStop(1, '#0a6f96');
ctx.fillStyle = g;
rr(paddle.x, py, paddle.w, ph, ph / 2);
ctx.fill();
ctx.shadowBlur = 0;
if (effects.wide > 0) {
ctx.globalAlpha = 0.35 + 0.25 * Math.sin(state.time * 10);
ctx.strokeStyle = POWER_COLORS.wide;
ctx.lineWidth = 2;
rr(paddle.x - 3, py - 3, paddle.w + 6, ph + 6, (ph + 6) / 2);
ctx.stroke();
ctx.globalAlpha = 1;
}
}
function drawBalls() {
for (let i = 0; i < balls.length; i++) {
const b = balls[i];
const fire = effects.fire > 0;
for (let t = 0; t < b.trail.length; t++) {
const tr = b.trail[t];
const f = (t + 1) / b.trail.length;
ctx.globalAlpha = f * 0.3;
ctx.fillStyle = fire ? '#ff9d3a' : '#5ee7ff';
ctx.beginPath();
ctx.arc(tr.x, tr.y, b.r * (0.25 + 0.65 * f), 0, Math.PI * 2);
ctx.fill();
}
ctx.globalAlpha = 1;
ctx.shadowColor = fire ? '#ff7a18' : '#39d7ff';
ctx.shadowBlur = 24;
ctx.fillStyle = fire ? '#ffd9a3' : '#eafcff';
ctx.beginPath();
ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2);
ctx.fill();
ctx.shadowBlur = 0;
ctx.fillStyle = fire ? '#ff8c2b' : '#7fe9ff';
ctx.beginPath();
ctx.arc(b.x - b.r * 0.25, b.y - b.r * 0.25, b.r * 0.45, 0, Math.PI * 2);
ctx.fill();
}
}
function drawParticles() {
for (let i = 0; i < particles.length; i++) {
const p = particles[i];
const a = Math.max(0, p.life / p.maxLife);
ctx.globalAlpha = a;
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size * a + 0.6, 0, Math.PI * 2);
ctx.fill();
}
ctx.globalAlpha = 1;
}
function drawFloaters() {
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.font = '800 18px ' + FONT;
for (let i = 0; i < floaters.length; i++) {
const f = floaters[i];
const a = Math.max(0, f.life / f.maxLife);
ctx.globalAlpha = a;
ctx.fillStyle = f.color;
ctx.fillText(f.text, f.x, f.y);
}
ctx.globalAlpha = 1;
}
function drawHUD() {
ctx.textBaseline = 'middle';
ctx.textAlign = 'left';
ctx.font = '700 20px ' + FONT;
ctx.fillStyle = 'rgba(140, 200, 255, 0.55)';
ctx.fillText('SCORE', 30, 36);
ctx.font = '700 26px ' + FONT;
ctx.fillStyle = '#eafcff';
ctx.fillText(String(state.score).padStart(6, '0'), 112, 36);
ctx.textAlign = 'center';
ctx.font = '700 20px ' + FONT;
ctx.fillStyle = 'rgba(140, 200, 255, 0.55)';
ctx.fillText('LEVEL ' + (state.levelIndex + 1) + ' / ' + LEVELS.length, W / 2, 36);
for (let i = 0; i < state.lives; i++) {
const x = W - 34 - i * 26;
ctx.beginPath();
ctx.arc(x, 34, 8, 0, Math.PI * 2);
ctx.fillStyle = '#4fd8ff';
ctx.fill();
ctx.beginPath();
ctx.arc(x - 2.5, 31, 3, 0, Math.PI * 2);
ctx.fillStyle = '#eafcff';
ctx.fill();
}
// status
const statuses = [];
if (effects.wide > 0) statuses.push({ t: 'WIDE ' + Math.ceil(effects.wide) + 's', c: POWER_COLORS.wide });
if (effects.fire > 0) statuses.push({ t: 'FIRE ' + Math.ceil(effects.fire) + 's', c: POWER_COLORS.fire });
ctx.textAlign = 'left';
ctx.font = '700 15px ' + FONT;
let sx = 30;
for (let i = 0; i < statuses.length; i++) {
ctx.fillStyle = statuses[i].c;
ctx.fillText(statuses[i].t, sx, 70);
sx += ctx.measureText(statuses[i].t).width + 18;
}
if (state.combo >= 2) {
const m = comboMult();
ctx.textAlign = 'center';
ctx.font = '800 18px ' + FONT;
ctx.fillStyle = m >= 5 ? '#ffcf6b' : '#9fb6ff';
ctx.fillText('COMBO x' + m, W / 2, 72);
}
}
function dim(alpha) {
ctx.fillStyle = 'rgba(5, 8, 16, ' + alpha + ')';
ctx.fillRect(0, 0, W, H);
}
function drawOverlays() {
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
if (state.mode === 'menu') {
dim(0.78);
ctx.shadowColor = '#39d7ff';
ctx.shadowBlur = 34;
ctx.fillStyle = '#eafcff';
ctx.font = '900 76px ' + TITLE_FONT;
ctx.fillText('NEON BREAKOUT', W / 2, H / 2 - 110);
ctx.shadowBlur = 0;
ctx.font = '700 20px ' + FONT;
ctx.fillStyle = 'rgba(150, 210, 255, 0.8)';
ctx.fillText('6 LEVELS · POWER-UPS · COMBOS', W / 2, H / 2 - 46);
const pulse = 0.6 + 0.4 * Math.sin(state.time * 4);
ctx.globalAlpha = pulse;
ctx.font = '800 26px ' + FONT;
ctx.fillStyle = '#7df9ff';
ctx.fillText('CLICK OR PRESS SPACE TO START', W / 2, H / 2 + 40);
ctx.globalAlpha = 1;
ctx.font = '600 17px ' + FONT;
ctx.fillStyle = 'rgba(150, 190, 230, 0.65)';
ctx.fillText('MOVE: MOUSE · or ← → / A D', W / 2, H / 2 + 108);
ctx.fillText('LAUNCH: CLICK OR SPACE', W / 2, H / 2 + 138);
} else if (state.mode === 'serve') {
const a = 0.5 + 0.45 * Math.sin(state.time * 5);
ctx.globalAlpha = a;
ctx.font = '800 19px ' + FONT;
ctx.fillStyle = '#9fe9ff';
ctx.fillText('CLICK OR PRESS SPACE TO LAUNCH', W / 2, paddle.y - 78);
ctx.globalAlpha = 1;
} else if (state.mode === 'clear') {
dim(0.55);
ctx.shadowColor = '#7dffc4';
ctx.shadowBlur = 26;
ctx.fillStyle = '#d8fff0';
ctx.font = '900 62px ' + TITLE_FONT;
ctx.fillText('LEVEL CLEAR', W / 2, H / 2 - 40);
ctx.shadowBlur = 0;
ctx.font = '800 26px ' + FONT;
ctx.fillStyle = '#8affc1';
ctx.fillText('BONUS +' + state.clearBonus, W / 2, H / 2 + 34);
ctx.font = '700 18px ' + FONT;
ctx.fillStyle = 'rgba(180, 235, 255, 0.7)';
ctx.fillText('NEXT LEVEL INCOMING…', W / 2, H / 2 + 82);
} else if (state.mode === 'over') {
dim(0.72);
ctx.shadowColor = '#ff5e8a';
ctx.shadowBlur = 26;
ctx.fillStyle = '#ffd9e3';
ctx.font = '900 66px ' + TITLE_FONT;
ctx.fillText('GAME OVER', W / 2, H / 2 - 50);
ctx.shadowBlur = 0;
ctx.font = '800 28px ' + FONT;
ctx.fillStyle = '#eafcff';
ctx.fillText('SCORE ' + state.score, W / 2, H / 2 + 26);
if (state.timer <= 0) {
const a = 0.55 + 0.45 * Math.sin(state.time * 5);
ctx.globalAlpha = a;
ctx.font = '800 22px ' + FONT;
ctx.fillStyle = '#7df9ff';
ctx.fillText('CLICK OR PRESS SPACE TO PLAY AGAIN', W / 2, H / 2 + 96);
ctx.globalAlpha = 1;
}
} else if (state.mode === 'win') {
dim(0.72);
ctx.shadowColor = '#ffd166';
ctx.shadowBlur = 30;
ctx.fillStyle = '#fff4d6';
ctx.font = '900 70px ' + TITLE_FONT;
ctx.fillText('YOU WIN!', W / 2, H / 2 - 60);
ctx.shadowBlur = 0;
ctx.font = '800 28px ' + FONT;
ctx.fillStyle = '#eafcff';
ctx.fillText('FINAL SCORE ' + state.score, W / 2, H / 2 + 18);
if (state.timer <= 0) {
const a = 0.55 + 0.45 * Math.sin(state.time * 5);
ctx.globalAlpha = a;
ctx.font = '800 22px ' + FONT;
ctx.fillStyle = '#7df9ff';
ctx.fillText('CLICK OR PRESS SPACE TO PLAY AGAIN', W / 2, H / 2 + 92);
ctx.globalAlpha = 1;
}
}
}
function render() {
ctx.setTransform(DPR, 0, 0, DPR, 0, 0);
drawBackground();
ctx.save();
if (state.shake > 0.001) {
const s = state.shake * 13;
ctx.translate((Math.random() - 0.5) * s, (Math.random() - 0.5) * s);
}
drawBricks();
drawPowerups();
drawPaddle();
drawBalls();
drawParticles();
drawFloaters();
ctx.restore();
drawHUD();
drawOverlays();
}
// ------------------------------------------------------------------
// Main loop
// ------------------------------------------------------------------
let last = performance.now();
function loop(now) {
let dt = (now - last) / 1000;
last = now;
if (!isFinite(dt) || dt < 0) dt = 0;
dt = Math.min(dt, 0.033);
update(dt);
render();
requestAnimationFrame(loop);
}
// Boot: preload level 1 as a backdrop for the menu
loadLevel(0);
state.mode = 'menu';
requestAnimationFrame(loop);
})();
</script>
</body>
</html>

