Run details
- Model
- thinkingmachines/inkling-2-mini
- Route
- OpenRouter API, one user message
- Served by
- PrimeIntellect
- Effort
- high, OpenRouter's default for this model
- Limits
- 60 min · 65,536 output tokens (the model's limit)
- Date
- 21 Nov 2026
- Time
- 8 min 20 s
- Size
- 28 kB
- Tokens
- 96 in, 22,448 out (8,788 of them thinking)
- List price
- $0.007 at today's price ($0.075 in / $0.30 out per M)
- Paid
- $0.009
Exact 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
28 kB 930 lines Raw
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Neon Breakout</title>
<style>
* { margin:0; padding:0; box-sizing:border-box; }
html, body {
height:100%;
background:#04050d;
overflow:hidden;
font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
-webkit-user-select:none; user-select:none;
touch-action:none;
}
body {
display:flex; align-items:center; justify-content:center;
background: radial-gradient(ellipse at 50% 30%, #101530 0%, #04050d 70%);
}
canvas {
display:block;
border-radius:14px;
box-shadow: 0 0 40px rgba(60,120,255,.25), 0 0 120px rgba(140,80,255,.12), inset 0 0 0 1px rgba(255,255,255,.06);
cursor:none;
background:#070a18;
}
</style>
</head>
<body>
<canvas id="game"></canvas>
<script>
(() => {
"use strict";
/* ============================ SETUP ============================ */
const LW = 960, LH = 720;
const canvas = document.getElementById('game');
const ctx = canvas.getContext('2d');
function fit(){
const dpr = Math.min(window.devicePixelRatio || 1, 2);
canvas.width = LW * dpr;
canvas.height = LH * dpr;
const s = Math.min(window.innerWidth / LW, window.innerHeight / LH) * 0.98;
canvas.style.width = (LW * s) + 'px';
canvas.style.height = (LH * s) + 'px';
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
}
window.addEventListener('resize', fit);
fit();
const rand = (a,b) => a + Math.random()*(b-a);
const clamp = (v,a,b) => Math.max(a, Math.min(b, v));
/* ============================ AUDIO ============================ */
let AC = null;
function ac(){
if(!AC){
const Ctx = window.AudioContext || window.webkitAudioContext;
if(Ctx) AC = new Ctx();
}
if(AC && AC.state === 'suspended') AC.resume();
return AC;
}
function tone(freq, dur, type, vol, delay, slide){
if(S.muted) return;
const c = ac(); if(!c) return;
const t0 = c.currentTime + (delay || 0);
const o = c.createOscillator(), g = c.createGain();
o.type = type || 'sine';
o.frequency.setValueAtTime(Math.max(20, freq), t0);
if(slide) o.frequency.exponentialRampToValueAtTime(Math.max(20, freq + slide), t0 + dur);
g.gain.setValueAtTime(0.0001, t0);
g.gain.exponentialRampToValueAtTime(vol || 0.15, t0 + 0.012);
g.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
o.connect(g); g.connect(c.destination);
o.start(t0); o.stop(t0 + dur + 0.05);
}
function noiseBurst(dur, vol, delay){
if(S.muted) return;
const c = ac(); if(!c) return;
const t0 = c.currentTime + (delay || 0);
const len = Math.floor(c.sampleRate * dur);
const buf = c.createBuffer(1, len, c.sampleRate);
const data = buf.getChannelData(0);
for(let i=0;i<len;i++) data[i] = (Math.random()*2-1) * (1 - i/len);
const src = c.createBufferSource(); src.buffer = buf;
const f = c.createBiquadFilter(); f.type = 'lowpass'; f.frequency.value = 1800;
const g = c.createGain();
g.gain.setValueAtTime(vol, t0);
g.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
src.connect(f); f.connect(g); g.connect(c.destination);
src.start(t0);
}
const sfx = {
paddle(){ tone(300, 0.09, 'square', 0.12, 0, 140); },
wall(){ tone(150, 0.06, 'square', 0.06); },
brick(){ tone(rand(500,620), 0.09, 'triangle', 0.16); noiseBurst(0.06, 0.08); },
hard(){ tone(rand(280,340), 0.1, 'square', 0.14); noiseBurst(0.08, 0.1); },
destroy(){ tone(rand(700,900), 0.16, 'triangle', 0.16, 0, 260); noiseBurst(0.22, 0.16); },
launch(){ tone(440, 0.12, 'sine', 0.14, 0, 220); },
death(){ tone(340, 0.55, 'sawtooth', 0.2, 0, -270); noiseBurst(0.35, 0.18); },
clear(){ [523,659,784,1047].forEach((f,i)=>tone(f,0.18,'triangle',0.16,i*0.11)); },
gameover(){ [392,330,262,175].forEach((f,i)=>tone(f,0.28,'sawtooth',0.14,i*0.2)); },
win(){ [523,659,784,1047,1319,1568].forEach((f,i)=>tone(f,0.22,'triangle',0.15,i*0.12)); },
combo(){ tone(880, 0.09, 'sine', 0.12, 0, 180); }
};
/* ============================ LEVELS ============================ */
const LEVELS = [
{ name:'Warm-Up', hue:185, speed:400, pattern:[
"##########",
"##########",
"##########",
"##########"
]},
{ name:'Reinforced', hue:300, speed:430, pattern:[
"##########",
"##d####d##",
"##########",
"#d######d#",
"##########"
]},
{ name:'Pyramid', hue:130, speed:460, pattern:[
"....##....",
"...####...",
"..######..",
".########.",
"##########"
]},
{ name:'The Columns', hue:20, speed:480, pattern:[
"##..d...##",
"##..dd.##",
"##..d...##",
"##.....##".replace('.','.'),
"##..d...##"
]},
{ name:'Chevron', hue:260, speed:500, pattern:[
"#........#",
"##......##",
".##....##.",
"..##..##..",
"...####...",
"....##...."
]},
{ name:'Fortress', hue:350, speed:530, pattern:[
"##########",
"#d#d#d#d#d",
"##########",
"dd##gggg##",
"##########"
]},
{ name:'Obliteration',hue:50, speed:570, pattern:[
"##########",
"#t#t##t#t#",
"##t####t##",
"t########t",
"##########"
]}
];
/* ============================ STATE ============================ */
const S = {
state:'title', // title | intro | play | dying | clear | gameover | victory | paused
paused:false,
levelIndex:0,
score:0,
best:0,
lives:3,
combo:0,
comboTimer:0,
mult:1,
muted:false,
stateTimer:0,
time:0
};
try { S.best = parseInt(localStorage.getItem('nb_best') || '0', 10) || 0; } catch(e){}
const paddle = { x: LW/2, y: LH - 54, w: 118, h: 14, flash:0, squash:0 };
const ball = { x: LW/2, y: 0, r: 7, vx: 0, vy: 0, speed: 400, launched:false, trail:[] };
let bricks = [];
let particles = [];
let floaters = [];
let stars = [];
let mouseTarget = null;
let shake = 0;
let hitstop = 0;
for(let i=0;i<90;i++) stars.push({ x: Math.random()*LW, y: Math.random()*LH, r: rand(0.5,1.8), tw: rand(0, Math.PI*2), sp: rand(0.5,2) });
/* ============================ LEVEL LOADING ============================ */
function loadLevel(i){
const L = LEVELS[i];
const pattern = L.pattern;
const cols = 10, rows = pattern.length;
const gridX = 46, gridW = LW - 92;
const bw = gridW / cols, bh = 32, gap = 6;
bricks = [];
for(let r=0;r<rows;r++){
for(let c=0;c<cols;c++){
const ch = pattern[r][c];
if(!ch || ch === '.') continue;
const hp = ch === '#' ? 1 : ch === 'd' ? 2 : ch === 't' ? 3 : ch === 'g' ? 4 : 1;
const hue = (L.hue + r * 22) % 360;
bricks.push({
x: gridX + c*bw + gap/2,
y: 106 + r*bh + gap/2,
w: bw - gap, h: bh - gap,
hp: hp, maxHp: hp,
points: ch === 'g' ? 500 : hp === 1 ? 100 : hp === 2 ? 180 : hp === 3 ? 280 : 500,
hue: ch === 'g' ? 46 : hue,
gold: ch === 'g',
flash: 0
});
}
}
ball.speed = L.speed;
}
function resetBall(){
ball.launched = false;
ball.vx = 0; ball.vy = 0;
ball.speed = LEVELS[S.levelIndex].speed;
ball.trail.length = 0;
ball.x = paddle.x;
ball.y = paddle.y - paddle.h/2 - ball.r - 2;
}
function startGame(){
S.score = 0; S.lives = 3; S.levelIndex = 0;
S.combo = 0; S.comboTimer = 0; S.mult = 1;
paddle.x = LW/2;
loadLevel(0);
resetBall();
S.state = 'intro'; S.stateTimer = 1.7;
particles = []; floaters = [];
}
function launchBall(){
if(ball.launched) return;
ball.launched = true;
const a = -Math.PI/2 + rand(-0.55, 0.55);
ball.vx = Math.cos(a) * ball.speed;
ball.vy = Math.sin(a) * ball.speed;
sfx.launch();
}
/* ============================ EFFECTS ============================ */
function spawnParticles(x, y, hue, count, power){
for(let i=0;i<count;i++){
const a = Math.random()*Math.PI*2;
const sp = rand(power*0.3, power);
particles.push({
x, y,
vx: Math.cos(a)*sp, vy: Math.sin(a)*sp - 40,
life: rand(0.35, 0.75), maxLife: 0.75,
size: rand(2, 5), hue,
spin: rand(-6,6), rot: rand(0,6.28)
});
}
}
function addFloater(x, y, txt, color, size){
floaters.push({ x, y, txt, color: color || '#fff', life: 1.1, maxLife: 1.1, size: size || 22 });
}
/* ============================ GAME LOGIC ============================ */
function loseLife(){
spawnParticles(ball.x, Math.min(ball.y, LH-20), 0, 34, 320);
shake = Math.max(shake, 14);
sfx.death();
S.lives--;
S.combo = 0; S.comboTimer = 0; S.mult = 1;
if(S.lives <= 0){
S.state = 'gameover';
S.stateTimer = 0;
if(S.score > S.best){ S.best = S.score; try{ localStorage.setItem('nb_best', String(S.best)); }catch(e){} }
sfx.gameover();
} else {
S.state = 'dying'; S.stateTimer = 1.15;
}
}
function nextLevel(){
S.levelIndex++;
if(S.levelIndex >= LEVELS.length){
S.state = 'victory'; S.stateTimer = 0;
if(S.score > S.best){ S.best = S.score; try{ localStorage.setItem('nb_best', String(S.best)); }catch(e){} }
sfx.win();
for(let i=0;i<70;i++) setTimeout(()=>{}, 0); // no-op keep
for(let i=0;i<90;i++) spawnParticles(rand(100,LW-100), rand(120,LH*0.5), rand(0,360), 1, rand(80,420));
} else {
loadLevel(S.levelIndex);
resetBall();
S.state = 'intro'; S.stateTimer = 1.7;
S.combo = 0; S.comboTimer = 0; S.mult = 1;
}
}
function circleRect(cx, cy, r, b){
const nx = clamp(cx, b.x, b.x + b.w);
const ny = clamp(cy, b.y, b.y + b.h);
const dx = cx - nx, dy = cy - ny;
return dx*dx + dy*dy <= r*r;
}
function update(dt){
S.time += dt;
// timers & decay
shake = Math.max(0, shake - dt*34);
paddle.flash = Math.max(0, paddle.flash - dt*5);
paddle.squash = Math.max(0, paddle.squash - dt*6);
hitstop = Math.max(0, hitstop - dt);
for(const p of particles){
p.life -= dt;
p.x += p.vx * dt; p.y += p.vy * dt;
p.vy += 520 * dt;
p.vx *= (1 - 1.6*dt);
p.rot += p.spin * dt;
}
particles = particles.filter(p => p.life > 0);
for(const f of floaters){
f.life -= dt; f.y -= 46*dt;
}
floaters = floaters.filter(f => f.life > 0);
for(const b of bricks) b.flash = Math.max(0, b.flash - dt*6);
if(S.paused) return;
if(S.comboTimer > 0){
S.comboTimer -= dt;
if(S.comboTimer <= 0){ S.combo = 0; S.mult = 1; }
}
switch(S.state){
case 'title':
break;
case 'intro':
S.stateTimer -= dt;
if(S.stateTimer <= 0) S.state = 'play';
break;
case 'dying':
S.stateTimer -= dt;
if(S.stateTimer <= 0){ resetBall(); S.state = 'play'; }
break;
case 'clear':
S.stateTimer -= dt;
if(S.stateTimer <= 0) nextLevel();
break;
case 'gameover':
case 'victory':
S.stateTimer += dt;
break;
case 'play':
break;
}
if(S.state !== 'play') return;
// --- paddle ---
let pdx = 0;
if(keys.left) pdx -= 1;
if(keys.right) pdx += 1;
if(pdx !== 0){
paddle.x += pdx * 640 * dt;
mouseTarget = null;
} else if(mouseTarget !== null){
paddle.x += (mouseTarget - paddle.x) * Math.min(1, dt * 20);
}
paddle.x = clamp(paddle.x, paddle.w/2 + 14, LW - paddle.w/2 - 14);
if(!ball.launched){
ball.x = paddle.x;
ball.y = paddle.y - paddle.h/2 - ball.r - 2;
ball.trail.length = 0;
return;
}
const prevX = ball.x, prevY = ball.y;
ball.x += ball.vx * dt;
ball.y += ball.vy * dt;
// walls
if(ball.x - ball.r < 10){ ball.x = ball.r + 10; ball.vx = Math.abs(ball.vx); sfx.wall(); }
if(ball.x + ball.r > LW - 10){ ball.x = LW - 10 - ball.r; ball.vx = -Math.abs(ball.vx); sfx.wall(); }
if(ball.y - ball.r < 88){ ball.y = 88 + ball.r; ball.vy = Math.abs(ball.vy); sfx.wall(); }
// bottom
if(ball.y - ball.r > LH + 30){ loseLife(); return; }
// paddle
const px1 = paddle.x - paddle.w/2, px2 = paddle.x + paddle.w/2;
const py1 = paddle.y - paddle.h/2, py2 = paddle.y + paddle.h/2;
if(ball.vy > 0 &&
ball.x + ball.r > px1 && ball.x - ball.r < px2 &&
ball.y + ball.r > py1 && ball.y - ball.r < py2 + 6){
const rel = clamp((ball.x - paddle.x) / (paddle.w/2), -1, 1);
const ang = rel * (Math.PI/3) * 0.95 + rand(-0.05, 0.05);
ball.speed = Math.min(ball.speed + 4, 880);
ball.vx = Math.sin(ang) * ball.speed;
ball.vy = -Math.cos(ang) * ball.speed;
ball.y = py1 - ball.r - 1;
paddle.flash = 1; paddle.squash = 1;
sfx.paddle();
hitstop = 0.03;
}
// bricks
for(const b of bricks){
if(circleRect(ball.x, ball.y, ball.r, b)){
b.hp--;
b.flash = 1;
const wasGold = b.gold;
if(b.hp <= 0){
b._dead = true;
S.combo++; S.comboTimer = 2.2;
const newMult = Math.min(5, 1 + Math.floor(S.combo / 3));
if(newMult > S.mult){ S.mult = newMult; sfx.combo(); addFloater(ball.x, ball.y - 20, 'COMBO x' + S.mult, '#ffe066', 20); }
S.mult = newMult;
const pts = b.points * S.mult;
S.score += pts;
spawnParticles(b.x + b.w/2, b.y + b.h/2, b.hue, wasGold ? 26 : 14, wasGold ? 330 : 240);
addFloater(b.x + b.w/2, b.y, '+' + pts, b.hue === 46 ? '#ffe066' : `hsl(${b.hue},95%,70%)`, 18);
shake = Math.max(shake, wasGold ? 9 : 4);
sfx.destroy();
} else {
S.score += 20 * S.mult;
spawnParticles(ball.x, ball.y, b.hue, 5, 160);
shake = Math.max(shake, 2.5);
if(b.maxHp >= 3) sfx.hard(); else sfx.brick();
}
// bounce axis
if(prevX < b.x || prevX > b.x + b.w) ball.vx = -ball.vx;
else ball.vy = -ball.vy;
ball.vx = clamp(ball.vx, -900, 900);
ball.vy = clamp(ball.vy, -900, 900);
// keep ball moving along erratic path but avoid pure-horizontal stalls
if(Math.abs(ball.vy) < ball.speed * 0.18) ball.vy = (ball.vy >= 0 ? 1 : -1) * ball.speed * 0.28;
break;
}
}
bricks = bricks.filter(b => !b._dead);
// trail
ball.trail.push({x: ball.x, y: ball.y});
if(ball.trail.length > 14) ball.trail.shift();
if(bricks.length === 0 && S.state === 'play'){
const bonus = 250 * (S.levelIndex + 1);
S.score += bonus;
addFloater(LW/2, LH/2 - 40, 'BONUS +' + bonus, '#7dffb0', 30);
S.state = 'clear';
S.stateTimer = 2.0;
sfx.clear();
spawnParticles(LW/2, LH/2, 140, 40, 380);
}
}
/* ============================ INPUT ============================ */
const keys = { left:false, right:false };
window.addEventListener('keydown', e => {
const k = e.key;
if(k === 'ArrowLeft' || k === 'a' || k === 'A'){ keys.left = true; e.preventDefault(); }
else if(k === 'ArrowRight' || k === 'd' || k === 'D'){ keys.right = true; e.preventDefault(); }
else if(k === ' ' || k === 'Enter'){ e.preventDefault(); primaryAction(); }
else if(k === 'p' || k === 'P'){
if(S.state === 'play' || S.state === 'intro') S.paused = !S.paused;
}
else if(k === 'm' || k === 'M'){ S.muted = !S.muted; }
else if(k === 'Escape'){ S.paused = false; }
});
window.addEventListener('keyup', e => {
const k = e.key;
if(k === 'ArrowLeft' || k === 'a' || k === 'A') keys.left = false;
if(k === 'ArrowRight' || k === 'd' || k === 'D') keys.right = false;
});
function setMouseFromClientX(clientX){
const r = canvas.getBoundingClientRect();
mouseTarget = clamp((clientX - r.left) / r.width * LW, paddle.w/2 + 14, LW - paddle.w/2 - 14);
}
window.addEventListener('mousemove', e => setMouseFromClientX(e.clientX));
window.addEventListener('mousedown', e => { setMouseFromClientX(e.clientX); primaryAction(); });
window.addEventListener('touchstart', e => { e.preventDefault(); setMouseFromClientX(e.touches[0].clientX); primaryAction(); }, {passive:false});
window.addEventListener('touchmove', e => { e.preventDefault(); setMouseFromClientX(e.touches[0].clientX); }, {passive:false});
function primaryAction(){
ac();
if(S.paused){ S.paused = false; return; }
if(S.state === 'title'){ startGame(); return; }
if(S.state === 'gameover' || S.state === 'victory'){ startGame(); return; }
if(S.state === 'play'){ launchBall(); }
}
/* ============================ RENDER ============================ */
function roundRect(x, y, w, h, r){
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 drawBackground(){
const g = ctx.createLinearGradient(0, 0, 0, LH);
g.addColorStop(0, '#0a0e20');
g.addColorStop(0.6, '#070a18');
g.addColorStop(1, '#0d0716');
ctx.fillStyle = g;
ctx.fillRect(0, 0, LW, LH);
// stars
for(const s of stars){
const a = 0.25 + 0.55 * (0.5 + 0.5 * Math.sin(S.time * s.sp + s.tw));
ctx.globalAlpha = a;
ctx.fillStyle = '#cdd7ff';
ctx.beginPath(); ctx.arc(s.x, s.y, s.r, 0, 6.283); ctx.fill();
}
ctx.globalAlpha = 1;
// faint grid
ctx.strokeStyle = 'rgba(90,120,255,0.05)';
ctx.lineWidth = 1;
for(let x = 0; x <= LW; x += 48){ ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, LH); ctx.stroke(); }
for(let y = 96; y <= LH; y += 48){ ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(LW, y); ctx.stroke(); }
// top divider (HUD)
const hg = ctx.createLinearGradient(0, 84, 0, 90);
hg.addColorStop(0, 'rgba(110,150,255,0.05)');
hg.addColorStop(1, 'rgba(110,150,255,0.35)');
ctx.fillStyle = hg;
ctx.fillRect(0, 84, LW, 5);
}
function drawHUD(){
ctx.textBaseline = 'middle';
ctx.font = '700 26px "Courier New", monospace';
ctx.textAlign = 'left';
ctx.fillStyle = '#67e8f9';
ctx.shadowColor = '#22d3ee'; ctx.shadowBlur = 12;
ctx.fillText('SCORE ' + String(S.score).padStart(7, '0'), 26, 44);
ctx.shadowBlur = 0;
const L = LEVELS[S.levelIndex] || LEVELS[0];
ctx.textAlign = 'center';
ctx.font = '600 15px "Segoe UI", system-ui, sans-serif';
ctx.fillStyle = 'rgba(200,215,255,0.65)';
ctx.fillText('LEVEL ' + (S.levelIndex + 1) + ' / ' + LEVELS.length, LW/2, 30);
ctx.font = '700 19px "Segoe UI", system-ui, sans-serif';
ctx.fillStyle = '#e6dcff';
ctx.shadowColor = '#a78bfa'; ctx.shadowBlur = 10;
ctx.fillText(L.name.toUpperCase(), LW/2, 54);
ctx.shadowBlur = 0;
// lives
ctx.textAlign = 'right';
ctx.font = '600 12px "Segoe UI", sans-serif';
ctx.fillStyle = 'rgba(200,215,255,0.6)';
ctx.fillText('LIVES', LW - 26, 28);
for(let i=0;i<3;i++){
const x = LW - 34 - i * 30, y = 52;
if(i < S.lives){
ctx.fillStyle = '#ff5d8f';
ctx.shadowColor = '#ff2d79'; ctx.shadowBlur = 12;
ctx.beginPath(); ctx.arc(x, y, 8, 0, 6.283); ctx.fill();
ctx.shadowBlur = 0;
ctx.fillStyle = 'rgba(255,255,255,0.85)';
ctx.beginPath(); ctx.arc(x - 2.5, y - 2.5, 2.5, 0, 6.283); ctx.fill();
} else {
ctx.strokeStyle = 'rgba(255,93,143,0.3)';
ctx.lineWidth = 2;
ctx.beginPath(); ctx.arc(x, y, 8, 0, 6.283); ctx.stroke();
}
}
// combo
if(S.mult > 1){
const pulse = 1 + 0.12 * Math.sin(S.time * 12);
ctx.textAlign = 'center';
ctx.font = '800 ' + Math.round(22 * pulse) + 'px "Segoe UI", sans-serif';
ctx.fillStyle = '#ffe066';
ctx.shadowColor = '#fbbf24'; ctx.shadowBlur = 16;
ctx.fillText('COMBO x' + S.mult, LW/2, 84 + 26);
ctx.shadowBlur = 0;
}
ctx.textAlign = 'right';
ctx.font = '500 12px "Segoe UI", sans-serif';
ctx.fillStyle = 'rgba(160,175,220,0.45)';
ctx.fillText('P pause · M mute', LW - 24, LH - 12);
}
function drawBricks(){
for(const b of bricks){
const lit = b.flash;
const light = b.gold ? 62 : 58;
const sat = b.gold ? 100 : 88;
ctx.save();
ctx.shadowColor = `hsl(${b.hue},90%,60%)`;
ctx.shadowBlur = 12 + lit * 22;
roundRect(b.x, b.y, b.w, b.h, 6);
ctx.fillStyle = lit > 0 ? `hsl(${b.hue},60%,${75 + lit*15}%)` : `hsl(${b.hue},${sat}%,${light}%)`;
ctx.fill();
ctx.restore();
// top sheen
roundRect(b.x + 2, b.y + 2, b.w - 4, Math.max(3, b.h * 0.34), 4);
ctx.fillStyle = 'rgba(255,255,255,0.28)';
ctx.fill();
// hp pips
if(b.maxHp > 1){
for(let i=0;i<b.maxHp;i++){
ctx.fillStyle = i < b.hp ? 'rgba(255,255,255,0.9)' : 'rgba(0,0,0,0.35)';
ctx.beginPath();
ctx.arc(b.x + b.w/2 - (b.maxHp-1)*6 + i*12, b.y + b.h - 8, 2.6, 0, 6.283);
ctx.fill();
}
}
}
}
function drawBall(){
// trail
ctx.save();
ctx.globalCompositeOperation = 'lighter';
const n = ball.trail.length;
for(let i=0;i<n;i++){
const p = ball.trail[i];
const t = (i+1)/n;
ctx.globalAlpha = t * 0.35;
ctx.fillStyle = '#6ee7ff';
ctx.beginPath();
ctx.arc(p.x, p.y, ball.r * t * 0.9, 0, 6.283);
ctx.fill();
}
ctx.restore();
ctx.save();
ctx.fillStyle = '#aef4ff';
ctx.shadowColor = '#38e1ff'; ctx.shadowBlur = 22;
ctx.beginPath(); ctx.arc(ball.x, ball.y, ball.r, 0, 6.283); ctx.fill();
ctx.shadowBlur = 0;
ctx.fillStyle = '#ffffff';
ctx.beginPath(); ctx.arc(ball.x - 2, ball.y - 2, ball.r * 0.42, 0, 6.283); ctx.fill();
ctx.restore();
}
function drawPaddle(){
const sq = 1 - paddle.squash * 0.45;
const wdt = paddle.w * (1 + paddle.squash * 0.18);
const h = paddle.h * sq;
const x = paddle.x - wdt/2, y = paddle.y - h/2;
ctx.save();
ctx.shadowColor = '#5eeaff'; ctx.shadowBlur = 16 + paddle.flash * 26;
roundRect(x, y, wdt, h, h/2);
const g = ctx.createLinearGradient(0, y, 0, y + h);
const top = paddle.flash > 0 ? '#ffffff' : '#b6f4ff';
const bot = paddle.flash > 0 ? '#5eeaff' : '#0891b2';
g.addColorStop(0, top); g.addColorStop(1, bot);
ctx.fillStyle = g;
ctx.fill();
ctx.shadowBlur = 0;
// center notch
ctx.fillStyle = 'rgba(4,40,60,0.55)';
roundRect(paddle.x - wdt * 0.22, y + h * 0.32, wdt * 0.44, h * 0.36, 4);
ctx.fill();
ctx.restore();
}
function drawParticles(){
ctx.save();
ctx.globalCompositeOperation = 'lighter';
for(const p of particles){
const t = p.life / p.maxLife;
ctx.globalAlpha = Math.max(0, t);
ctx.fillStyle = `hsl(${p.hue},95%,${55 + 30 * t}%)`;
ctx.save();
ctx.translate(p.x, p.y);
ctx.rotate(p.rot);
ctx.fillRect(-p.size/2, -p.size/2, p.size, p.size);
ctx.restore();
}
ctx.restore();
}
function drawFloaters(){
ctx.save();
ctx.textAlign = 'center';
for(const f of floaters){
const t = f.life / f.maxLife;
ctx.globalAlpha = Math.max(0, t);
ctx.font = '800 ' + f.size + 'px "Segoe UI", sans-serif';
ctx.fillStyle = f.color;
ctx.shadowColor = f.color; ctx.shadowBlur = 10;
ctx.fillText(f.txt, f.x, f.y);
}
ctx.restore();
}
function drawStarBurst(){
// launch hint
if(S.state === 'play' && !ball.launched){
const a = 0.55 + 0.45 * Math.sin(S.time * 5);
ctx.save();
ctx.globalAlpha = a;
ctx.textAlign = 'center';
ctx.font = '700 20px "Segoe UI", sans-serif';
ctx.fillStyle = '#baf6ff';
ctx.shadowColor = '#22d3ee'; ctx.shadowBlur = 14;
ctx.fillText('CLICK or press SPACE to launch', LW/2, LH - 120);
ctx.restore();
}
}
function drawTitle(){
ctx.save();
ctx.fillStyle = 'rgba(4,6,18,0.55)';
ctx.fillRect(0, 0, LW, LH);
const t = S.time;
const float = Math.sin(t * 1.6) * 10;
ctx.textAlign = 'center';
// glow orb behind title
const g = ctx.createRadialGradient(LW/2, 240 + float, 10, LW/2, 240 + float, 260);
g.addColorStop(0, 'rgba(80,190,255,0.30)');
g.addColorStop(1, 'rgba(80,190,255,0)');
ctx.fillStyle = g;
ctx.fillRect(0, 0, LW, LH);
ctx.font = '900 84px "Segoe UI", system-ui, sans-serif';
ctx.fillStyle = '#eafcff';
ctx.shadowColor = '#38e1ff'; ctx.shadowBlur = 34;
ctx.fillText('NEON', LW/2, 210 + float);
ctx.font = '900 84px "Segoe UI", system-ui, sans-serif';
ctx.fillStyle = '#ffd7f6';
ctx.shadowColor = '#ff5de4'; ctx.shadowBlur = 34;
ctx.fillText('BREAKOUT', LW/2, 300 + float);
ctx.shadowBlur = 0;
ctx.font = '600 19px "Segoe UI", sans-serif';
ctx.fillStyle = 'rgba(214,225,255,0.9)';
ctx.fillText('7 LEVELS · COMBO MULTIPLIER · NEON PARTICLES', LW/2, 372 + float);
const a = 0.55 + 0.45 * Math.sin(t * 4);
ctx.globalAlpha = a;
ctx.font = '800 24px "Segoe UI", sans-serif';
ctx.fillStyle = '#ffe066';
ctx.shadowColor = '#fbbf24'; ctx.shadowBlur = 16;
ctx.fillText('CLICK or PRESS SPACE', LW/2, 480);
ctx.shadowBlur = 0;
ctx.globalAlpha = 1;
ctx.font = '500 15px "Segoe UI", sans-serif';
ctx.fillStyle = 'rgba(170,185,225,0.75)';
ctx.fillText('Move: mouse or ◄ ► / A D Pause: P Mute: M', LW/2, 528);
if(S.best > 0){
ctx.font = '700 17px "Courier New", monospace';
ctx.fillStyle = '#7dffb0';
ctx.fillText('BEST ' + S.best, LW/2, 576);
}
ctx.restore();
}
function drawIntro(){
const total = 1.7;
const t = 1 - S.stateTimer / total;
const L = LEVELS[S.levelIndex];
ctx.save();
ctx.textAlign = 'center';
const alpha = t < 0.25 ? t/0.25 : (t > 0.8 ? (1 - t)/0.2 : 1);
ctx.globalAlpha = clamp(alpha, 0, 1);
const scale = 0.7 + 0.3 * Math.min(1, t * 2.4);
ctx.translate(LW/2, LH/2 - 20);
ctx.scale(scale, scale);
ctx.font = '700 26px "Segoe UI", sans-serif';
ctx.fillStyle = '#67e8f9';
ctx.shadowColor = '#22d3ee'; ctx.shadowBlur = 16;
ctx.fillText('LEVEL ' + (S.levelIndex + 1), 0, -60);
ctx.font = '900 56px "Segoe UI", sans-serif';
ctx.fillStyle = '#fff3ff';
ctx.shadowColor = '#ff5de4'; ctx.shadowBlur = 26;
ctx.fillText(L.name.toUpperCase(), 0, 10);
ctx.shadowBlur = 0;
ctx.font = '600 16px "Segoe UI", sans-serif';
ctx.fillStyle = 'rgba(220,230,255,0.85)';
ctx.fillText('Clear the board to reach level ' + Math.min(S.levelIndex + 2, LEVELS.length) + ' / ' + LEVELS.length, 0, 62);
ctx.restore();
}
function drawClear(){
ctx.save();
ctx.textAlign = 'center';
ctx.globalAlpha = Math.min(1, (2.0 - S.stateTimer) * 3);
ctx.font = '900 58px "Segoe UI", sans-serif';
ctx.fillStyle = '#7dffb0';
ctx.shadowColor = '#22c55e'; ctx.shadowBlur = 30;
ctx.fillText('LEVEL CLEARED!', LW/2, LH/2 - 40);
ctx.shadowBlur = 0;
ctx.font = '600 19px "Segoe UI", sans-serif';
ctx.fillStyle = '#d6ffe4';
const bonus = 250 * (S.levelIndex + 1);
ctx.fillText('BONUS +' + bonus, LW/2, LH/2 + 10);
ctx.restore();
}
function drawGameOver(win){
ctx.save();
ctx.fillStyle = 'rgba(5,6,16,0.72)';
ctx.fillRect(0, 0, LW, LH);
const t = S.stateTimer;
const pulse = 1 + 0.05 * Math.sin(t * 5);
ctx.textAlign = 'center';
ctx.translate(LW/2, LH/2 - 50);
ctx.scale(pulse, pulse);
ctx.font = '900 ' + (win ? 66 : 72) + 'px "Segoe UI", sans-serif';
ctx.fillStyle = win ? '#7dffb0' : '#ff6b9d';
ctx.shadowColor = win ? '#22c55e' : '#ff2d79';
ctx.shadowBlur = 34;
ctx.fillText(win ? 'YOU WIN!' : 'GAME OVER', 0, 0);
ctx.shadowBlur = 0;
ctx.font = '700 34px "Courier New", monospace';
ctx.fillStyle = '#eafcff';
ctx.fillText(String(S.score).padStart(7, '0'), 0, 72);
ctx.font = '500 17px "Segoe UI", sans-serif';
ctx.fillStyle = 'rgba(205,215,240,0.8)';
ctx.fillText(win ? 'All ' + LEVELS.length + ' levels cleared — brilliant!' : 'Reached level ' + (S.levelIndex + 1), 0, 112);
ctx.fillStyle = '#ffe066';
ctx.fillText('BEST ' + S.best, 0, 146);
const a = 0.5 + 0.5 * Math.sin(t * 4);
ctx.globalAlpha = a;
ctx.font = '800 21px "Segoe UI", sans-serif';
ctx.fillStyle = '#ffffff';
ctx.fillText('CLICK or PRESS SPACE to play again', 0, 196);
ctx.restore();
}
function drawPause(){
ctx.save();
ctx.fillStyle = 'rgba(4,6,18,0.66)';
ctx.fillRect(0, 0, LW, LH);
ctx.textAlign = 'center';
ctx.font = '900 56px "Segoe UI", sans-serif';
ctx.fillStyle = '#baf6ff';
ctx.shadowColor = '#22d3ee'; ctx.shadowBlur = 24;
ctx.fillText('PAUSED', LW/2, LH/2 - 10);
ctx.shadowBlur = 0;
ctx.font = '600 17px "Segoe UI", sans-serif';
ctx.fillStyle = 'rgba(205,220,255,0.8)';
ctx.fillText('Press P to resume', LW/2, LH/2 + 38);
ctx.restore();
}
function drawVignette(){
const g = ctx.createRadialGradient(LW/2, LH/2, LH * 0.42, LW/2, LH/2, LH * 0.85);
g.addColorStop(0, 'rgba(0,0,0,0)');
g.addColorStop(1, 'rgba(0,0,0,0.5)');
ctx.fillStyle = g;
ctx.fillRect(0, 0, LW, LH);
}
function render(){
ctx.clearRect(0, 0, LW, LH);
drawBackground();
ctx.save();
if(shake > 0.2) ctx.translate(rand(-shake, shake), rand(-shake, shake));
drawBricks();
if(S.state !== 'dying' && S.state !== 'gameover' && S.state !== 'victory') drawBall();
drawPaddle();
drawParticles();
drawFloaters();
drawStarBurst();
ctx.restore();
drawHUD();
if(S.state === 'title') drawTitle();
else if(S.state === 'intro') drawIntro();
else if(S.state === 'clear') drawClear();
else if(S.state === 'gameover') drawGameOver(false);
else if(S.state === 'victory') drawGameOver(true);
if(S.paused) drawPause();
drawVignette();
if(S.muted){
ctx.save();
ctx.textAlign = 'center';
ctx.font = '600 13px "Segoe UI", sans-serif';
ctx.fillStyle = 'rgba(255,180,190,0.85)';
ctx.fillText('MUTED', LW/2, LH - 16);
ctx.restore();
}
}
/* ============================ LOOP ============================ */
let last = performance.now();
function frame(now){
let dt = (now - last) / 1000;
last = now;
dt = Math.min(dt, 1/30);
if(hitstop > 0) dt *= 0.25;
update(dt);
render();
requestAnimationFrame(frame);
}
// preload level so title screen shows a board behind it
loadLevel(0);
resetBall();
requestAnimationFrame(frame);
})();
</script>
</body>
</html>

