Run details
- Model
- xiaomi/mimo-v2.6-pro
- Route
- OpenRouter API
- Served by
- Novita
- Effort
- model default
- Limits
- 60 min · 131,072 output tokens (model max)
- Date
- 24 Oct 2026
- Time
- 7 min 3 s
- Size
- 41 kB
- Tokens
- 83 in, 30,540 out (13,994 thinking)
- List price
- $0.027 at today's price ($0.435 in / $0.87 out per M)
- Paid
- $0.027
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
41 kB 1,314 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%; overflow: hidden;
background: #04060f;
}
body {
display: flex; align-items: center; justify-content: center;
font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
background: radial-gradient(ellipse at 50% 18%, #131b46 0%, #070a1c 55%, #03040b 100%);
user-select: none; -webkit-user-select: none; touch-action: none;
}
canvas {
display: block;
border-radius: 16px;
cursor: none;
box-shadow: 0 30px 90px rgba(0,0,0,0.85), 0 0 70px rgba(70,130,255,0.22), 0 0 0 1px rgba(120,170,255,0.18);
}
</style>
</head>
<body>
<canvas id="game"></canvas>
<script>
(function () {
'use strict';
// ---------------------------------------------------------------- basics
var canvas = document.getElementById('game');
var ctx = canvas.getContext('2d');
var W = 900, H = 600;
var dpr = 1;
function clamp(v, a, b) { return v < a ? a : (v > b ? b : v); }
function rand(a, b) { return a + Math.random() * (b - a); }
function lerp(a, b, t) { return a + (b - a) * t; }
function hexA(hex, a) {
var n = parseInt(hex.slice(1), 16);
return 'rgba(' + ((n >> 16) & 255) + ',' + ((n >> 8) & 255) + ',' + (n & 255) + ',' + a + ')';
}
function roundRect(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 resize() {
dpr = Math.min(window.devicePixelRatio || 1, 2);
canvas.width = Math.floor(W * dpr);
canvas.height = Math.floor(H * dpr);
var m = 14;
var s = Math.min((window.innerWidth - m) / W, (window.innerHeight - m) / H);
canvas.style.width = Math.floor(W * s) + 'px';
canvas.style.height = Math.floor(H * s) + 'px';
}
window.addEventListener('resize', resize);
resize();
// ---------------------------------------------------------------- audio
var actx = null, master = null;
function initAudio() {
try {
if (!actx) {
var AC = window.AudioContext || window.webkitAudioContext;
if (!AC) return;
actx = new AC();
master = actx.createGain();
master.gain.value = 0.22;
master.connect(actx.destination);
}
if (actx.state === 'suspended') actx.resume();
} catch (e) { actx = null; }
}
function tone(freq, dur, type, vol, slideTo, delay) {
if (!actx || G.muted) return;
try {
var t0 = actx.currentTime + (delay || 0);
var o = actx.createOscillator(), g = actx.createGain();
o.type = type || 'square';
o.frequency.setValueAtTime(freq, t0);
if (slideTo) o.frequency.exponentialRampToValueAtTime(Math.max(25, slideTo), t0 + dur);
g.gain.setValueAtTime(0.0001, t0);
g.gain.exponentialRampToValueAtTime(vol || 0.3, t0 + 0.008);
g.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
o.connect(g); g.connect(master);
o.start(t0); o.stop(t0 + dur + 0.03);
} catch (e) {}
}
function noiseBurst(dur, vol, freq) {
if (!actx || G.muted) return;
try {
var len = Math.floor(actx.sampleRate * dur);
var buf = actx.createBuffer(1, len, actx.sampleRate);
var d = buf.getChannelData(0);
for (var i = 0; i < len; i++) d[i] = (Math.random() * 2 - 1) * (1 - i / len);
var src = actx.createBufferSource(); src.buffer = buf;
var f = actx.createBiquadFilter(); f.type = 'lowpass'; f.frequency.value = freq || 900;
var g = actx.createGain(); g.gain.value = vol || 0.2;
src.connect(f); f.connect(g); g.connect(master);
src.start();
} catch (e) {}
}
// ---------------------------------------------------------------- levels
var COLS = 13, MARGIN = 18, CELL_W = (W - MARGIN * 2) / COLS, CELL_H = 30, BRICK_TOP = 92;
var BRICK_COLORS = {
'1': '#ff2e63', '2': '#ff9f1c', '3': '#ffe14d',
'X': '#8e9bad', '*': '#b14dff', '+': '#22e3a2'
};
var BRICK_VALUE = { '1': 50, '2': 80, '3': 120, 'X': 0, '*': 140, '+': 180 };
var LEVELS = [
{
name: 'FIRST CONTACT', speed: 380,
rows: [
'1111111111111',
'1111111111111',
'1111111111111',
'2222222222222',
'.............',
'1111111111111',
'.............',
'2222222222222'
]
},
{
name: 'CHECKERBOARD', speed: 415,
rows: [
'1.1.1.1.1.1.1',
'.2.2.2.2.2.2.',
'1.1.1.1.1.1.1',
'.3.3.3.3.3.3.',
'1.1.1.1.1.1.1',
'.2.2.2.2.2.2.',
'1111111111111',
'.....+++.....'
]
},
{
name: 'THE WALL', speed: 450,
rows: [
'X22222222222X',
'X2.........2X',
'X2.3333333.2X',
'X2.3.....3.2X',
'X2.3.111.3.2X',
'X2.3.....3.2X',
'X2.3333333.2X',
'X22222222222X'
]
},
{
name: 'ASCENSION', speed: 485,
rows: [
'......1......',
'.....121.....',
'....12321....',
'...1233321...',
'..123333321..',
'.12333333321.',
'1233333333321',
'...+++...+++.'
]
},
{
name: 'DETONATION ALLEY', speed: 525,
rows: [
'*..*..*..*..*',
'.11111111111.',
'.2.........2.',
'.2.*******..2',
'.2.........2.',
'.22222222222.',
'.11111111111.',
'+++++++++++++'
]
},
{
name: 'THE CORE', speed: 565,
rows: [
'X3X3X3X3X3X3X',
'3232323232323',
'2121212121212',
'1*1*1*1*1*1*1',
'2121212121212',
'3232323232323',
'X3X3X3X3X3X3X',
'..++.....++..'
]
}
];
// ---------------------------------------------------------------- state
var G = {
state: 'menu',
score: 0, best: 0, lives: 3, level: 0, combo: 0,
balls: [], bricks: [], particles: [], texts: [], powerups: [], lasers: [],
paddle: { x: W / 2, y: H - 44, w: 130, h: 16, vx: 0 },
powerTimers: { wide: 0, slow: 0, laser: 0 },
laserCooldown: 0,
shake: 0, flash: 0, time: 0, muted: false,
levelClearTimer: 0, hintTime: 0, invuln: 0
};
try { G.best = parseInt(localStorage.getItem('neonBreakoutBest') || '0', 10) || 0; } catch (e) {}
function saveBest() {
if (G.score > G.best) {
G.best = G.score;
try { localStorage.setItem('neonBreakoutBest', String(G.best)); } catch (e) {}
}
}
// background orbs
var orbs = [];
for (var oi = 0; oi < 6; oi++) {
orbs.push({
x: Math.random() * W, y: Math.random() * H,
r: rand(120, 300), vx: rand(-14, 14), vy: rand(-9, 9),
hue: rand(195, 285), a: rand(0.05, 0.11)
});
}
// ---------------------------------------------------------------- levels
function loadLevel(idx) {
G.level = idx;
G.bricks.length = 0;
G.balls.length = 0;
G.particles.length = 0;
G.powerups.length = 0;
G.lasers.length = 0;
G.texts.length = 0;
G.combo = 0;
G.powerTimers = { wide: 0, slow: 0, laser: 0 };
G.paddle.w = 130;
var L = LEVELS[idx];
for (var r = 0; r < L.rows.length; r++) {
var row = L.rows[r];
for (var c = 0; c < COLS; c++) {
var ch = row.charAt(c);
if (ch === '.' || !ch) continue;
var hp = ch === '1' ? 1 : ch === '2' ? 2 : ch === '3' ? 3 : ch === 'X' ? 999 : 1;
G.bricks.push({
x: MARGIN + c * CELL_W + 2,
y: BRICK_TOP + r * CELL_H + 2,
w: CELL_W - 4,
h: CELL_H - 5,
type: ch, hp: hp, maxHp: hp,
row: r, col: c, dead: false,
color: BRICK_COLORS[ch] || '#ffffff',
value: BRICK_VALUE[ch] || 50,
drop: ch === '+' || Math.random() < 0.11
});
}
}
resetBall();
G.state = 'playing';
G.hintTime = 0;
tone(420, 0.12, 'triangle', 0.18, 700);
tone(620, 0.16, 'triangle', 0.14, 900, 0.11);
}
function resetBall() {
G.balls.length = 0;
G.balls.push({
x: G.paddle.x, y: G.paddle.y - 22,
vx: 0, vy: 0, r: 9, stuck: true, trail: []
});
G.paddle.x = W / 2;
}
function startGame() {
G.score = 0; G.lives = 3; G.combo = 0;
G.shake = 0; G.flash = 0;
loadLevel(0);
}
function targetSpeed() {
var base = LEVELS[G.level].speed;
var s = clamp(base, 340, 720);
if (G.powerTimers.slow > 0) s *= 0.72;
return s;
}
function launchBall() {
for (var i = 0; i < G.balls.length; i++) {
var b = G.balls[i];
if (!b.stuck) continue;
var ang = rand(-0.5, 0.5);
var sp = targetSpeed();
b.vx = Math.sin(ang) * sp;
b.vy = -Math.cos(ang) * sp;
b.stuck = false;
tone(300, 0.09, 'square', 0.16, 520);
}
}
function nextLevel() {
if (G.level + 1 >= LEVELS.length) {
G.state = 'won';
saveBest();
tone(440, 0.18, 'triangle', 0.2, 660);
tone(660, 0.22, 'triangle', 0.2, 990, 0.16);
tone(880, 0.3, 'triangle', 0.2, 1320, 0.34);
} else {
loadLevel(G.level + 1);
}
}
function loseLife() {
G.lives--;
G.combo = 0;
G.powerTimers = { wide: 0, slow: 0, laser: 0 };
G.paddle.w = 130;
G.shake = Math.min(30, G.shake + 18);
G.flash = Math.min(0.9, G.flash + 0.5);
noiseBurst(0.35, 0.28, 500);
tone(220, 0.3, 'sawtooth', 0.18, 60);
if (G.lives <= 0) {
G.lives = 0;
G.state = 'gameover';
saveBest();
} else {
resetBall();
}
}
// ---------------------------------------------------------------- input
var keys = { left: false, right: false };
var mouseX = W / 2, mouseActive = false;
function pointerX(clientX) {
var r = canvas.getBoundingClientRect();
return clamp((clientX - r.left) / r.width * W, 0, W);
}
canvas.addEventListener('mousemove', function (e) {
mouseX = pointerX(e.clientX);
mouseActive = true;
});
canvas.addEventListener('mousedown', function (e) {
initAudio(); e.preventDefault(); handleAction();
});
canvas.addEventListener('touchstart', function (e) {
initAudio(); e.preventDefault();
if (e.touches.length) {
mouseX = pointerX(e.touches[0].clientX);
mouseActive = true;
}
handleAction();
}, { passive: false });
canvas.addEventListener('touchmove', function (e) {
e.preventDefault();
if (e.touches.length) {
mouseX = pointerX(e.touches[0].clientX);
mouseActive = true;
}
}, { passive: false });
window.addEventListener('keydown', function (e) {
initAudio();
var k = e.key;
if (k === ' ' || k === 'ArrowLeft' || k === 'ArrowRight' || k === 'ArrowUp' || k === 'ArrowDown') e.preventDefault();
if (k === 'ArrowLeft' || k === 'a' || k === 'A') { keys.left = true; mouseActive = false; }
if (k === 'ArrowRight' || k === 'd' || k === 'D') { keys.right = true; mouseActive = false; }
if (k === ' ') {
if (G.state === 'menu' || G.state === 'gameover' || G.state === 'won') {
startGame();
} else if (G.state === 'paused') {
G.state = 'playing';
} else if (G.state === 'levelclear') {
G.levelClearTimer = 0;
} else if (G.state === 'playing') {
var stuck = false;
for (var i = 0; i < G.balls.length; i++) if (G.balls[i].stuck) stuck = true;
if (stuck) launchBall(); else fireLaser();
}
}
if (k === 'p' || k === 'P' || k === 'Escape') {
if (G.state === 'playing') G.state = 'paused';
else if (G.state === 'paused') G.state = 'playing';
}
if (k === 'm' || k === 'M') G.muted = !G.muted;
if (k === 'Enter') {
if (G.state === 'menu' || G.state === 'gameover' || G.state === 'won') startGame();
else if (G.state === 'levelclear') G.levelClearTimer = 0;
else if (G.state === 'paused') G.state = 'playing';
}
if (k === 'r' || k === 'R') startGame();
});
window.addEventListener('keyup', function (e) {
var k = e.key;
if (k === 'ArrowLeft' || k === 'a' || k === 'A') keys.left = false;
if (k === 'ArrowRight' || k === 'd' || k === 'D') keys.right = false;
});
function handleAction() {
if (G.state === 'menu' || G.state === 'gameover' || G.state === 'won') {
startGame();
} else if (G.state === 'paused') {
G.state = 'playing';
} else if (G.state === 'levelclear') {
G.levelClearTimer = 0;
} else if (G.state === 'playing') {
var stuck = false;
for (var i = 0; i < G.balls.length; i++) if (G.balls[i].stuck) stuck = true;
if (stuck) launchBall(); else fireLaser();
}
}
// ---------------------------------------------------------------- fx
function addText(x, y, str, color) {
G.texts.push({ x: x, y: y, str: str, color: color || '#fff', life: 1.05, maxLife: 1.05, vy: -52 });
if (G.texts.length > 60) G.texts.shift();
}
function spawnSparks(x, y, color, n) {
for (var i = 0; i < n; i++) {
var a = Math.random() * Math.PI * 2, sp = rand(60, 300);
G.particles.push({
x: x, y: y, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp,
life: rand(0.25, 0.55), maxLife: 0.55,
size: rand(2, 5), color: color, grav: 420
});
}
if (G.particles.length > 600) G.particles.splice(0, G.particles.length - 600);
}
function spawnDebris(b) {
var n = 15;
for (var i = 0; i < n; i++) {
var a = Math.random() * Math.PI * 2, sp = rand(70, 360);
G.particles.push({
x: b.x + b.w / 2 + rand(-b.w / 3, b.w / 3),
y: b.y + b.h / 2 + rand(-b.h / 3, b.h / 3),
vx: Math.cos(a) * sp, vy: Math.sin(a) * sp - 60,
life: rand(0.45, 0.95), maxLife: 0.95,
size: rand(2.5, 8), color: b.color, grav: 620
});
}
for (var j = 0; j < 7; j++) {
var a2 = Math.random() * Math.PI * 2, sp2 = rand(30, 160);
G.particles.push({
x: b.x + b.w / 2, y: b.y + b.h / 2,
vx: Math.cos(a2) * sp2, vy: Math.sin(a2) * sp2,
life: rand(0.3, 0.6), maxLife: 0.6,
size: rand(8, 20), color: '#ffffff', grav: 0
});
}
if (G.particles.length > 600) G.particles.splice(0, G.particles.length - 600);
}
function spawnExplosion(x, y, color) {
for (var i = 0; i < 34; i++) {
var a = Math.random() * Math.PI * 2, sp = rand(120, 560);
G.particles.push({
x: x, y: y, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp,
life: rand(0.4, 1.0), maxLife: 1.0,
size: rand(3, 12), color: i % 3 === 0 ? '#ffffff' : color, grav: 380
});
}
for (var j = 0; j < 5; j++) {
G.particles.push({
x: x, y: y, vx: 0, vy: 0,
life: rand(0.25, 0.42), maxLife: 0.42,
size: rand(40, 95), color: '#ffd28a', grav: 0
});
}
if (G.particles.length > 600) G.particles.splice(0, G.particles.length - 600);
}
// ---------------------------------------------------------------- powerups
var POWER_TYPES = [
{ id: 'wide', color: '#39d0ff', letter: 'W', weight: 3.0, label: 'WIDE PADDLE' },
{ id: 'multi', color: '#ff6ad5', letter: 'M', weight: 3.0, label: 'MULTIBALL' },
{ id: 'slow', color: '#7dff8a', letter: 'S', weight: 2.4, label: 'SLOW MOTION' },
{ id: 'laser', color: '#ff5c5c', letter: 'L', weight: 2.4, label: 'LASERS' },
{ id: 'life', color: '#ffd93d', letter: '+', weight: 1.0, label: 'EXTRA LIFE' }
];
function spawnPowerup(x, y) {
var total = 0, i;
for (i = 0; i < POWER_TYPES.length; i++) total += POWER_TYPES[i].weight;
var pick = Math.random() * total;
for (i = 0; i < POWER_TYPES.length; i++) {
pick -= POWER_TYPES[i].weight;
if (pick <= 0) break;
}
var t = POWER_TYPES[Math.min(i, POWER_TYPES.length - 1)];
G.powerups.push({ x: x, y: y, vy: 130, t: 0, type: t, w: 34, h: 20 });
tone(760, 0.1, 'sine', 0.14, 1180);
}
function applyPowerup(p) {
var id = p.type.id;
addText(G.paddle.x, G.paddle.y - 34, p.type.label, p.type.color);
if (id === 'wide') {
G.powerTimers.wide = 13;
tone(420, 0.16, 'triangle', 0.2, 900);
} else if (id === 'slow') {
G.powerTimers.slow = 10;
tone(700, 0.22, 'sine', 0.2, 260);
} else if (id === 'laser') {
G.powerTimers.laser = 12;
tone(300, 0.14, 'sawtooth', 0.18, 900);
} else if (id === 'life') {
G.lives = Math.min(6, G.lives + 1);
tone(520, 0.12, 'triangle', 0.22, 780);
tone(780, 0.18, 'triangle', 0.2, 1140, 0.1);
} else if (id === 'multi') {
var existing = G.balls.slice(0);
for (var i = 0; i < existing.length && G.balls.length < 6; i++) {
var src = existing[i];
for (var k = 0; k < 2; k++) {
if (G.balls.length >= 6) break;
var ang = Math.atan2(src.vy, src.vx) + (k === 0 ? 0.55 : -0.55);
var sp = targetSpeed();
G.balls.push({
x: src.x, y: src.y,
vx: Math.cos(ang) * sp, vy: Math.sin(ang) * sp,
r: src.r, stuck: false, trail: []
});
}
}
tone(500, 0.1, 'square', 0.18, 800);
tone(700, 0.12, 'square', 0.16, 1100, 0.08);
tone(900, 0.14, 'square', 0.14, 1400, 0.16);
}
G.flash = Math.min(0.7, G.flash + 0.16);
G.shake = Math.min(20, G.shake + 5);
}
function fireLaser() {
if (G.powerTimers.laser <= 0 || G.laserCooldown > 0) return;
G.laserCooldown = 0.22;
var p = G.paddle;
G.lasers.push({ x: p.x - p.w / 2 + 12, y: p.y - 12, vy: -940, life: 1.6 });
G.lasers.push({ x: p.x + p.w / 2 - 12, y: p.y - 12, vy: -940, life: 1.6 });
tone(920, 0.07, 'sawtooth', 0.12, 320);
G.shake = Math.min(12, G.shake + 2.2);
}
// ---------------------------------------------------------------- bricks
function comboMult() { return clamp(1 + Math.floor(G.combo / 4), 1, 6); }
function damageBrick(b, hitX, hitY, fromLaser) {
if (b.type === 'X') {
spawnSparks(hitX, hitY, '#c8d6ea', 7);
tone(190, 0.05, 'triangle', 0.11, 130);
return;
}
b.hp--;
G.combo++;
if (b.hp <= 0) {
b.dead = true;
var pts = b.value * comboMult();
G.score += pts;
addText(b.x + b.w / 2, b.y + b.h / 2, '+' + pts, b.color);
spawnDebris(b);
if (b.type === '*') explodeBrick(b, 0);
if (b.drop) spawnPowerup(b.x + b.w / 2, b.y + b.h / 2);
tone(280 + (8 - b.row) * 42, 0.065, 'square', 0.16, 190);
if (comboMult() > 1) tone(560 + comboMult() * 60, 0.05, 'triangle', 0.08, 700);
G.shake = Math.min(20, G.shake + 4.5);
G.flash = Math.min(0.55, G.flash + 0.07);
} else {
G.score += 8 * comboMult();
spawnSparks(hitX, hitY, b.color, 6);
tone(235, 0.05, 'square', 0.12, 195);
G.shake = Math.min(14, G.shake + 2.2);
}
if (fromLaser) G.shake = Math.min(18, G.shake + 2);
}
function explodeBrick(b, depth) {
var cx = b.x + b.w / 2, cy = b.y + b.h / 2;
spawnExplosion(cx, cy, b.color);
noiseBurst(0.32, 0.26, 750);
tone(120, 0.28, 'sawtooth', 0.2, 45);
G.shake = Math.min(32, G.shake + 13);
G.flash = Math.min(0.95, G.flash + 0.28);
var radius = 132;
for (var i = 0; i < G.bricks.length; i++) {
var o = G.bricks[i];
if (o.dead || o.type === 'X') continue;
var dx = (o.x + o.w / 2) - cx, dy = (o.y + o.h / 2) - cy;
if (dx * dx + dy * dy < radius * radius) {
o.dead = true;
var pts = o.value;
G.score += pts;
addText(o.x + o.w / 2, o.y + o.h / 2, '+' + pts, o.color);
spawnDebris(o);
if (o.type === '*' && depth < 2) explodeBrick(o, depth + 1);
if (o.drop && Math.random() < 0.5) spawnPowerup(o.x + o.w / 2, o.y + o.h / 2);
}
}
}
// ---------------------------------------------------------------- update
function updatePaddle(dt) {
var p = G.paddle;
var targetW = G.powerTimers.wide > 0 ? 196 : 130;
p.w += (targetW - p.w) * Math.min(1, dt * 9);
var nx = p.x;
if (keys.left) nx -= 880 * dt;
if (keys.right) nx += 880 * dt;
if (mouseActive && !keys.left && !keys.right) nx = mouseX;
nx = clamp(nx, p.w / 2, W - p.w / 2);
p.vx = clamp((nx - p.x) / Math.max(dt, 0.0001), -1400, 1400);
p.x = nx;
G.powerTimers.wide = Math.max(0, G.powerTimers.wide - dt);
G.powerTimers.slow = Math.max(0, G.powerTimers.slow - dt);
G.powerTimers.laser = Math.max(0, G.powerTimers.laser - dt);
G.laserCooldown = Math.max(0, G.laserCooldown - dt);
}
function normalizeBall(b) {
var sp = Math.hypot(b.vx, b.vy);
if (sp < 1) return;
var t = targetSpeed();
b.vx = b.vx / sp * t;
b.vy = b.vy / sp * t;
}
function paddleBounce(b) {
var p = G.paddle;
var hit = clamp((b.x - p.x) / (p.w / 2), -1, 1);
var angle = hit * Math.PI / 3.15;
var sp = targetSpeed();
b.vx = Math.sin(angle) * sp + p.vx * 0.16;
b.vy = -Math.abs(Math.cos(angle) * sp);
normalizeBall(b);
b.y = p.y - p.h / 2 - b.r - 1.5;
G.combo = 0;
spawnSparks(b.x, p.y - p.h / 2, '#7df3ff', 5);
tone(340 + Math.abs(hit) * 160, 0.055, 'square', 0.14, 240);
G.shake = Math.min(12, G.shake + 1.6);
}
function updateBalls(dt) {
for (var i = 0; i < G.balls.length; i++) {
var b = G.balls[i];
if (b.stuck) {
b.x = G.paddle.x;
b.y = G.paddle.y - G.paddle.h / 2 - b.r - 4;
b.trail.length = 0;
continue;
}
var dist = Math.hypot(b.vx, b.vy) * dt;
var steps = clamp(Math.ceil(dist / 6), 1, 14);
var sdt = dt / steps;
for (var s = 0; s < steps; s++) {
b.x += b.vx * sdt;
b.y += b.vy * sdt;
if (b.x < b.r) {
b.x = b.r; b.vx = Math.abs(b.vx);
spawnSparks(b.x, b.y, '#69e8ff', 3);
tone(240, 0.035, 'square', 0.07, 200);
}
if (b.x > W - b.r) {
b.x = W - b.r; b.vx = -Math.abs(b.vx);
spawnSparks(b.x, b.y, '#69e8ff', 3);
tone(240, 0.035, 'square', 0.07, 200);
}
if (b.y < 50 + b.r) {
b.y = 50 + b.r; b.vy = Math.abs(b.vy);
spawnSparks(b.x, b.y, '#69e8ff', 3);
tone(260, 0.035, 'square', 0.07, 220);
}
// paddle
var p = G.paddle;
if (b.vy > 0 &&
b.x > p.x - p.w / 2 - b.r &&
b.x < p.x + p.w / 2 + b.r &&
b.y + b.r > p.y - p.h / 2 &&
b.y - b.r < p.y + p.h / 2) {
paddleBounce(b);
}
// bricks (first hit per sub-step)
for (var bi = 0; bi < G.bricks.length; bi++) {
var br = G.bricks[bi];
if (br.dead) continue;
var cx = clamp(b.x, br.x, br.x + br.w);
var cy = clamp(b.y, br.y, br.y + br.h);
var dx = b.x - cx, dy = b.y - cy;
if (dx * dx + dy * dy > b.r * b.r) continue;
var ox = (br.w / 2 + b.r) - Math.abs(b.x - (br.x + br.w / 2));
var oy = (br.h / 2 + b.r) - Math.abs(b.y - (br.y + br.h / 2));
if (ox < oy) {
if (b.x < br.x + br.w / 2) b.x -= ox; else b.x += ox;
b.vx = -b.vx;
} else {
if (b.y < br.y + br.h / 2) b.y -= oy; else b.y += oy;
b.vy = -b.vy;
}
damageBrick(br, b.x, b.y, false);
normalizeBall(b);
break;
}
normalizeBall(b);
}
b.trail.push({ x: b.x, y: b.y });
if (b.trail.length > 14) b.trail.shift();
if (b.y > H + 60) b.dead = true;
}
G.balls = G.balls.filter(function (b) { return !b.dead; });
if (G.balls.length === 0 && G.state === 'playing') loseLife();
}
function updatePowerups(dt) {
var p = G.paddle;
for (var i = G.powerups.length - 1; i >= 0; i--) {
var pu = G.powerups[i];
pu.t += dt;
pu.y += pu.vy * dt;
pu.x += Math.sin(pu.t * 2.2) * 22 * dt;
if (pu.y > H + 50) { G.powerups.splice(i, 1); continue; }
if (pu.x + pu.w / 2 > p.x - p.w / 2 &&
pu.x - pu.w / 2 < p.x + p.w / 2 &&
pu.y + pu.h / 2 > p.y - p.h / 2 &&
pu.y - pu.h / 2 < p.y + p.h / 2) {
applyPowerup(pu);
G.powerups.splice(i, 1);
}
}
}
function updateLasers(dt) {
for (var i = G.lasers.length - 1; i >= 0; i--) {
var l = G.lasers[i];
l.y += l.vy * dt;
l.life -= dt;
var hit = false;
if (l.y < 40 || l.life <= 0) hit = true;
if (!hit) {
for (var bi = 0; bi < G.bricks.length; bi++) {
var br = G.bricks[bi];
if (br.dead) continue;
if (l.x > br.x && l.x < br.x + br.w && l.y > br.y && l.y < br.y + br.h) {
damageBrick(br, l.x, l.y, true);
hit = true;
break;
}
}
}
if (hit) {
spawnSparks(l.x, l.y, '#ff8080', 5);
G.lasers.splice(i, 1);
}
}
}
function updateParticles(dt) {
for (var i = G.particles.length - 1; i >= 0; i--) {
var p = G.particles[i];
if (p.grav) p.vy += p.grav * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
p.life -= dt;
if (p.life <= 0) G.particles.splice(i, 1);
}
}
function updateTexts(dt) {
for (var i = G.texts.length - 1; i >= 0; i--) {
var t = G.texts[i];
t.y += t.vy * dt;
t.vy *= 0.94;
t.life -= dt;
if (t.life <= 0) G.texts.splice(i, 1);
}
}
function updateOrbs(dt) {
for (var i = 0; i < orbs.length; i++) {
var o = orbs[i];
o.x += o.vx * dt;
o.y += o.vy * dt;
if (o.x < -o.r) o.x = W + o.r;
if (o.x > W + o.r) o.x = -o.r;
if (o.y < -o.r) o.y = H + o.r;
if (o.y > H + o.r) o.y = -o.r;
}
}
function checkLevelClear() {
if (G.state !== 'playing') return;
for (var i = 0; i < G.bricks.length; i++) {
var b = G.bricks[i];
if (!b.dead && b.type !== 'X') return;
}
var bonus = 500 * (G.level + 1) + 250 * G.lives + 30 * G.combo;
G.score += bonus;
G.bonusText = bonus;
G.state = 'levelclear';
G.levelClearTimer = 2.6;
G.flash = Math.min(1, G.flash + 0.5);
G.shake = Math.min(24, G.shake + 12);
tone(520, 0.16, 'triangle', 0.22, 780);
tone(700, 0.18, 'triangle', 0.2, 1050, 0.13);
tone(900, 0.28, 'triangle', 0.2, 1350, 0.27);
}
function update(dt) {
G.time += dt;
updateOrbs(dt);
updateParticles(dt);
updateTexts(dt);
G.shake = Math.max(0, G.shake - dt * 34);
G.flash = Math.max(0, G.flash - dt * 2.1);
G.hintTime += dt;
if (G.state === 'playing') {
updatePaddle(dt);
updateBalls(dt);
updatePowerups(dt);
updateLasers(dt);
checkLevelClear();
} else if (G.state === 'levelclear') {
updatePowerups(dt);
G.levelClearTimer -= dt;
if (G.levelClearTimer <= 0) nextLevel();
} else if (G.state === 'menu' || G.state === 'gameover' || G.state === 'won') {
// idle paddle drift for life
G.paddle.x = W / 2 + Math.sin(G.time * 0.7) * 120;
}
}
// ---------------------------------------------------------------- render
function text(str, x, y, size, color, weight, align) {
ctx.font = (weight || '600') + ' ' + size + 'px "Segoe UI", system-ui, sans-serif';
ctx.fillStyle = color || '#ffffff';
ctx.textAlign = align || 'center';
ctx.textBaseline = 'middle';
ctx.fillText(str, x, y);
}
function drawBackground() {
var g = ctx.createLinearGradient(0, 0, 0, H);
g.addColorStop(0, '#0b1130');
g.addColorStop(0.55, '#080c22');
g.addColorStop(1, '#04060f');
ctx.fillStyle = g;
ctx.fillRect(0, 0, W, H);
for (var i = 0; i < orbs.length; i++) {
var o = orbs[i];
var rg = ctx.createRadialGradient(o.x, o.y, 0, o.x, o.y, o.r);
rg.addColorStop(0, 'hsla(' + o.hue + ',90%,62%,' + o.a + ')');
rg.addColorStop(1, 'hsla(' + o.hue + ',90%,62%,0)');
ctx.fillStyle = rg;
ctx.beginPath();
ctx.arc(o.x, o.y, o.r, 0, Math.PI * 2);
ctx.fill();
}
ctx.strokeStyle = 'rgba(110,150,255,0.055)';
ctx.lineWidth = 1;
var off = (G.time * 16) % 56;
for (var x = -56 + off; x < W; x += 56) {
ctx.beginPath(); ctx.moveTo(x, 46); ctx.lineTo(x, H); ctx.stroke();
}
for (var y = 46 - ((G.time * 9) % 56); y < H; y += 56) {
ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(W, y); ctx.stroke();
}
// vignette
var vg = ctx.createRadialGradient(W / 2, H / 2, H * 0.25, W / 2, H / 2, H * 0.85);
vg.addColorStop(0, 'rgba(0,0,0,0)');
vg.addColorStop(1, 'rgba(0,0,0,0.5)');
ctx.fillStyle = vg;
ctx.fillRect(0, 0, W, H);
}
function drawBricks() {
for (var i = 0; i < G.bricks.length; i++) {
var b = G.bricks[i];
if (b.dead) continue;
var x = b.x, y = b.y, w = b.w, h = b.h;
if (b.type === 'X') {
ctx.fillStyle = '#2b3442';
roundRect(x, y, w, h, 4); ctx.fill();
ctx.fillStyle = '#586576';
roundRect(x, y, w, h * 0.55, 4); ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.16)';
roundRect(x + 3, y + 2, w - 6, h * 0.2, 2); ctx.fill();
ctx.strokeStyle = 'rgba(170,200,240,0.32)';
ctx.lineWidth = 1.2;
roundRect(x + 0.5, y + 0.5, w - 1, h - 1, 4); ctx.stroke();
ctx.fillStyle = 'rgba(255,255,255,0.3)';
ctx.fillRect(x + 8, y + h / 2 - 1.5, 3, 3);
ctx.fillRect(x + w - 11, y + h / 2 - 1.5, 3, 3);
continue;
}
var f = b.hp / b.maxHp;
ctx.globalAlpha = 0.38 + 0.62 * f;
ctx.fillStyle = b.color;
roundRect(x, y, w, h, 5); ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.42)';
roundRect(x + 3, y + 2.5, w - 6, 4, 2); ctx.fill();
ctx.fillStyle = 'rgba(0,0,0,0.24)';
roundRect(x + 2, y + h - 6, w - 4, 4, 2); ctx.fill();
ctx.globalAlpha = 1;
if (b.type === '*') {
var cx = x + w / 2, cy = y + h / 2;
ctx.fillStyle = 'rgba(255,255,255,0.82)';
ctx.beginPath(); ctx.arc(cx, cy, 5, 0, Math.PI * 2); ctx.fill();
for (var k = 0; k < 6; k++) {
var a = k * Math.PI / 3 + G.time * 0.8;
ctx.fillRect(cx + Math.cos(a) * 9 - 1.6, cy + Math.sin(a) * 9 - 1.6, 3.2, 3.2);
}
} else if (b.type === '+') {
var px = x + w / 2, py = y + h / 2;
ctx.fillStyle = 'rgba(255,255,255,0.88)';
ctx.fillRect(px - 2.5, py - 8.5, 5, 17);
ctx.fillRect(px - 8.5, py - 2.5, 17, 5);
}
if (b.hp < b.maxHp && b.hp > 0) {
ctx.strokeStyle = 'rgba(255,255,255,0.32)';
ctx.lineWidth = 1.2;
ctx.beginPath();
ctx.moveTo(x + w * 0.25, y + 2);
ctx.lineTo(x + w * 0.42, y + h * 0.55);
ctx.lineTo(x + w * 0.3, y + h - 2);
ctx.stroke();
}
}
}
function drawPowerups() {
for (var i = 0; i < G.powerups.length; i++) {
var p = G.powerups[i];
var pulse = 0.82 + 0.18 * Math.sin(G.time * 7 + i);
ctx.save();
ctx.shadowColor = p.type.color;
ctx.shadowBlur = 18;
ctx.fillStyle = hexA(p.type.color, 0.92);
roundRect(p.x - p.w / 2, p.y - p.h / 2, p.w, p.h, 10);
ctx.fill();
ctx.restore();
ctx.fillStyle = 'rgba(255,255,255,' + (0.25 * pulse) + ')';
roundRect(p.x - p.w / 2 + 3, p.y - p.h / 2 + 2.5, p.w - 6, 5, 3);
ctx.fill();
text(p.type.letter, p.x, p.y + 0.5, 14, '#08122a', '800', 'center');
}
}
function drawLasers() {
ctx.save();
ctx.globalCompositeOperation = 'lighter';
for (var i = 0; i < G.lasers.length; i++) {
var l = G.lasers[i];
var g = ctx.createLinearGradient(l.x, l.y - 26, l.x, l.y + 12);
g.addColorStop(0, 'rgba(255,120,120,0)');
g.addColorStop(0.5, 'rgba(255,190,190,0.95)');
g.addColorStop(1, 'rgba(255,80,80,0.25)');
ctx.fillStyle = g;
ctx.fillRect(l.x - 3, l.y - 26, 6, 38);
ctx.fillStyle = 'rgba(255,255,255,0.9)';
ctx.fillRect(l.x - 1.2, l.y - 16, 2.4, 22);
}
ctx.restore();
}
function drawPaddle() {
var p = G.paddle;
var w = p.w, h = p.h, x = p.x - w / 2, y = p.y - h / 2;
// glow under paddle
ctx.save();
ctx.globalCompositeOperation = 'lighter';
var gg = ctx.createRadialGradient(p.x, p.y + 6, 2, p.x, p.y + 6, w * 0.65);
gg.addColorStop(0, 'rgba(60,170,255,0.32)');
gg.addColorStop(1, 'rgba(60,170,255,0)');
ctx.fillStyle = gg;
ctx.beginPath();
ctx.ellipse(p.x, p.y + 6, w * 0.72, 26, 0, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
var g = ctx.createLinearGradient(x, y, x, y + h);
g.addColorStop(0, '#8df6ff');
g.addColorStop(0.42, '#37b6ff');
g.addColorStop(1, '#1550c8');
ctx.fillStyle = g;
roundRect(x, y, w, h, 9);
ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.62)';
roundRect(x + 7, y + 2.2, w - 14, 4.2, 3);
ctx.fill();
ctx.strokeStyle = 'rgba(180,235,255,0.55)';
ctx.lineWidth = 1.4;
roundRect(x + 0.6, y + 0.6, w - 1.2, h - 1.2, 8.5);
ctx.stroke();
if (G.powerTimers.laser > 0) {
for (var i = -1; i <= 1; i += 2) {
var tx = p.x + i * (w / 2 - 12);
ctx.fillStyle = '#ff6b6b';
roundRect(tx - 5, y - 11, 10, 15, 3);
ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.8)';
ctx.fillRect(tx - 1.5, y - 9, 3, 9);
}
}
if (G.powerTimers.wide > 0) {
ctx.strokeStyle = 'rgba(90,220,255,' + (0.35 + 0.3 * Math.sin(G.time * 8)) + ')';
ctx.lineWidth = 2;
roundRect(x - 4, y - 4, w + 8, h + 8, 12);
ctx.stroke();
}
}
function drawBalls() {
for (var i = 0; i < G.balls.length; i++) {
var b = G.balls[i];
ctx.save();
ctx.globalCompositeOperation = 'lighter';
for (var t = 0; t < b.trail.length; t++) {
var tr = b.trail[t];
var a = (t + 1) / b.trail.length * 0.30;
ctx.fillStyle = 'rgba(110,215,255,' + a + ')';
ctx.beginPath();
ctx.arc(tr.x, tr.y, b.r * (0.28 + 0.72 * (t / b.trail.length)), 0, Math.PI * 2);
ctx.fill();
}
ctx.restore();
var g = ctx.createRadialGradient(
b.x - b.r * 0.36, b.y - b.r * 0.42, b.r * 0.08,
b.x, b.y, b.r * 1.35
);
g.addColorStop(0, '#ffffff');
g.addColorStop(0.3, '#c8f4ff');
g.addColorStop(0.62, 'rgba(90,190,255,0.62)');
g.addColorStop(1, 'rgba(60,150,255,0)');
ctx.fillStyle = g;
ctx.beginPath();
ctx.arc(b.x, b.y, b.r * 1.45, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.92)';
ctx.beginPath();
ctx.arc(b.x, b.y, b.r * 0.55, 0, Math.PI * 2);
ctx.fill();
}
}
function drawParticles() {
ctx.save();
ctx.globalCompositeOperation = 'lighter';
for (var i = 0; i < G.particles.length; i++) {
var p = G.particles[i];
var a = clamp(p.life / p.maxLife, 0, 1);
ctx.fillStyle = hexA(p.color, a * 0.85);
var sz = p.size * (0.35 + 0.65 * a);
ctx.fillRect(p.x - sz / 2, p.y - sz / 2, sz, sz);
}
ctx.restore();
}
function drawTexts() {
for (var i = 0; i < G.texts.length; i++) {
var t = G.texts[i];
var a = clamp(t.life / t.maxLife, 0, 1);
var sc = 1 + (1 - a) * 0.22;
ctx.save();
ctx.translate(t.x, t.y);
ctx.scale(sc, sc);
ctx.font = '800 21px "Segoe UI", system-ui, sans-serif';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = hexA(t.color, a * 0.35);
ctx.fillText(t.str, 2, 2);
ctx.fillStyle = hexA(t.color, a);
ctx.fillText(t.str, 0, 0);
ctx.restore();
}
}
function drawHUD() {
ctx.fillStyle = 'rgba(7,11,28,0.82)';
ctx.fillRect(0, 0, W, 46);
ctx.fillStyle = 'rgba(90,150,255,0.32)';
ctx.fillRect(0, 45, W, 1.6);
text('SCORE', 22, 15, 11, '#6d8fc9', '700', 'left');
text(String(G.score).padStart(6, '0'), 22, 32, 21, '#eaf3ff', '800', 'left');
if (G.combo > 1) {
var cm = comboMult();
var pulse = 0.72 + 0.28 * Math.sin(G.time * 8);
text('COMBO ' + G.combo, 190, 15, 11, hexA('#ff9f1c', pulse), '700', 'left');
text('x' + cm, 190, 32, 21, hexA('#ffcf6b', pulse), '800', 'left');
}
var L = LEVELS[G.level];
text('LEVEL ' + (G.level + 1) + ' · ' + (L ? L.name : ''), W / 2, 23, 17, '#bcd6ff', '700', 'center');
// lives
text('LIVES', W - 22, 15, 11, '#6d8fc9', '700', 'right');
for (var i = 0; i < G.lives; i++) {
var lx = W - 22 - i * 27 - 19;
ctx.fillStyle = '#4fd2ff';
roundRect(lx - 19, 25, 38, 9, 4.5);
ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.55)';
roundRect(lx - 15, 26.5, 30, 3, 1.5);
ctx.fill();
}
text(G.muted ? 'M SOUND OFF' : 'M SOUND ON', 330, 32, 11, 'rgba(120,155,205,0.72)', '600', 'left');
// active power bars
var barY = 52;
function bar(label, val, max, color) {
if (val <= 0) return;
var w = 130 * clamp(val / max, 0, 1);
ctx.fillStyle = 'rgba(255,255,255,0.12)';
roundRect(18, barY, 130, 8, 4); ctx.fill();
ctx.fillStyle = color;
roundRect(18, barY, w, 8, 4); ctx.fill();
text(label, 156, barY + 4, 10, color, '700', 'left');
barY += 14;
}
bar('WIDE', G.powerTimers.wide, 13, '#39d0ff');
bar('SLOW', G.powerTimers.slow, 10, '#7dff8a');
bar('LASER', G.powerTimers.laser, 12, '#ff6b6b');
}
function drawHint() {
if (G.state !== 'playing') return;
var stuck = false;
for (var i = 0; i < G.balls.length; i++) if (G.balls[i].stuck) stuck = true;
if (!stuck) return;
var a = 0.45 + 0.42 * Math.sin(G.time * 3.6);
text('CLICK · TAP · OR PRESS SPACE TO LAUNCH', W / 2, H - 118, 20, 'rgba(165,225,255,' + a + ')', '700');
}
function panel(x, y, w, h) {
ctx.fillStyle = 'rgba(10,16,42,0.9)';
roundRect(x, y, w, h, 18); ctx.fill();
ctx.strokeStyle = 'rgba(110,175,255,0.32)';
ctx.lineWidth = 1.6;
roundRect(x, y, w, h, 18); ctx.stroke();
}
function drawOverlay() {
if (G.state === 'playing') { drawHint(); return; }
ctx.fillStyle = 'rgba(4,7,20,0.72)';
ctx.fillRect(0, 0, W, H);
if (G.state === 'menu') {
var titleGlow = 0.72 + 0.28 * Math.sin(G.time * 2.2);
text('NEON', W / 2, 176, 74, hexA('#54e0ff', titleGlow), '800');
text('BREAKOUT', W / 2, 248, 74, hexA('#ff4d8d', titleGlow), '800');
text('6 LEVELS · POWER-UPS · COMBOS · EXPLOSIONS', W / 2, 314, 18, '#9dc0f2', '600');
text('MOUSE / TOUCH to move the paddle — ← → or A / D also work', W / 2, 356, 17, '#7fa2d8', '600');
text('SPACE or CLICK to launch & fire lasers · P pause · M mute', W / 2, 386, 17, '#7fa2d8', '600');
var b = 0.55 + 0.45 * Math.sin(G.time * 4);
text('CLICK OR PRESS ENTER TO START', W / 2, 452, 26, hexA('#ffe14d', b), '800');
if (G.best > 0) text('BEST SCORE ' + G.best, W / 2, 508, 18, '#67e2b2', '700');
}
if (G.state === 'paused') {
panel(W / 2 - 230, H / 2 - 120, 460, 240);
text('PAUSED', W / 2, H / 2 - 52, 46, '#8fe6ff', '800');
text('Press P, SPACE or click to resume', W / 2, H / 2 + 4, 19, '#a9c6ef', '600');
text('R to restart · M to toggle sound', W / 2, H / 2 + 44, 17, '#7fa2d8', '600');
}
if (G.state === 'levelclear') {
panel(W / 2 - 260, H / 2 - 130, 520, 260);
text('LEVEL ' + (G.level + 1) + ' CLEAR!', W / 2, H / 2 - 62, 44, '#67e2b2', '800');
text('BONUS +' + (G.bonusText || 0), W / 2, H / 2 - 4, 26, '#ffe14d', '800');
text('SCORE ' + G.score, W / 2, H / 2 + 42, 20, '#bcd6ff', '700');
var pct = clamp(G.levelClearTimer / 2.6, 0, 1);
ctx.fillStyle = 'rgba(255,255,255,0.14)';
roundRect(W / 2 - 170, H / 2 + 82, 340, 10, 5); ctx.fill();
ctx.fillStyle = '#54e0ff';
roundRect(W / 2 - 170, H / 2 + 82, 340 * (1 - pct), 10, 5); ctx.fill();
text('Get ready…', W / 2, H / 2 + 112, 16, '#8fb6e8', '600');
}
if (G.state === 'gameover') {
panel(W / 2 - 250, H / 2 - 140, 500, 280);
text('GAME OVER', W / 2, H / 2 - 72, 50, '#ff5c7a', '800');
text('SCORE ' + G.score, W / 2, H / 2 - 8, 28, '#eaf3ff', '800');
if (G.score >= G.best && G.score > 0) {
text('NEW BEST!', W / 2, H / 2 + 34, 22, '#ffe14d', '800');
} else {
text('BEST ' + G.best, W / 2, H / 2 + 34, 20, '#67e2b2', '700');
}
var b2 = 0.55 + 0.45 * Math.sin(G.time * 4);
text('CLICK OR PRESS ENTER TO PLAY AGAIN', W / 2, H / 2 + 96, 21, hexA('#8fe6ff', b2), '800');
}
if (G.state === 'won') {
panel(W / 2 - 280, H / 2 - 150, 560, 300);
var g1 = 0.7 + 0.3 * Math.sin(G.time * 2.6);
text('YOU WIN!', W / 2, H / 2 - 84, 58, hexA('#ffe14d', g1), '800');
text('All six levels cleared', W / 2, H / 2 - 26, 22, '#a9c6ef', '600');
text('FINAL SCORE ' + G.score, W / 2, H / 2 + 22, 30, '#67e2b2', '800');
text('BEST ' + G.best, W / 2, H / 2 + 62, 20, '#bcd6ff', '700');
var b3 = 0.55 + 0.45 * Math.sin(G.time * 4);
text('PRESS ENTER OR CLICK TO PLAY AGAIN', W / 2, H / 2 + 118, 21, hexA('#8fe6ff', b3), '800');
}
}
function render() {
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, W, H);
drawBackground();
ctx.save();
if (G.shake > 0.15) {
ctx.translate((Math.random() - 0.5) * G.shake, (Math.random() - 0.5) * G.shake);
}
drawBricks();
drawPowerups();
drawLasers();
drawPaddle();
drawBalls();
drawParticles();
drawTexts();
ctx.restore();
drawHUD();
if (G.flash > 0.01) {
ctx.fillStyle = 'rgba(190,225,255,' + (G.flash * 0.42) + ')';
ctx.fillRect(0, 0, W, H);
}
drawOverlay();
// subtle scanlines
ctx.fillStyle = 'rgba(0,0,0,0.055)';
for (var y = 0; y < H; y += 3) ctx.fillRect(0, y, W, 1);
}
// ---------------------------------------------------------------- loop
var last = 0;
function frame(ts) {
if (!last) last = ts;
var dt = (ts - last) / 1000;
last = ts;
if (!isFinite(dt) || dt < 0) dt = 0;
dt = Math.min(dt, 1 / 30);
update(dt);
render();
requestAnimationFrame(frame);
}
// initial demo state
G.state = 'menu';
G.paddle.x = W / 2;
requestAnimationFrame(frame);
})();
</script>
</body>
</html>

