Run details
- Model
- upstage/solar-pro-4-contributor
- Route
- OpenRouter API
- Served by
- Upstage
- Effort
- medium (OpenRouter default)
- Limits
- 60 min · 131,072 output tokens (model max)
- Date
- 25 Nov 2026
- Time
- 2 min 3 s
- Size
- 24 kB
- Tokens
- 128 in, 8,524 out
- List price
- $0.003 at today's price ($0.09 in / $0.36 out per M)
- Paid
- $0.003
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
24 kB 777 lines Raw
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Breakout — Solar Pro4</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: #0a0a1a;
display: flex;
justify-content: center;
align-items: center;
min-height: 100dvh;
font-family: 'Segoe UI', system-ui, sans-serif;
overflow: hidden;
user-select: none;
}
#game {
position: relative;
border-radius: 12px;
box-shadow: 0 0 60px rgba(80,140,255,0.25), 0 0 120px rgba(80,140,255,0.10);
background: #0f0f2a;
}
#hud {
position: absolute;
top: 0; left: 0; right: 0;
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 18px;
color: #c8d8ff;
font-size: 15px;
font-weight: 600;
letter-spacing: 0.5px;
text-shadow: 0 1px 4px rgba(0,0,0,0.8);
z-index: 5;
pointer-events: none;
}
#hud .hud-left, #hud .hud-right {
display: flex;
gap: 20px;
}
#hud span { background: rgba(0,0,0,0.5); padding: 4px 10px; border-radius: 6px; }
#overlay {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: rgba(5,5,20,0.82);
color: white;
z-index: 10;
transition: opacity 0.35s;
backdrop-filter: blur(4px);
}
#overlay.hidden { opacity: 0; pointer-events: none; }
#overlay h1 {
font-size: 42px;
font-weight: 800;
margin-bottom: 8px;
background: linear-gradient(135deg, #7abfff, #a77aff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
#overlay h2 {
font-size: 22px;
font-weight: 600;
margin-bottom: 6px;
color: #cfe0ff;
}
#overlay p {
font-size: 15px;
color: #8a9bc0;
margin-bottom: 28px;
text-align: center;
max-width: 380px;
line-height: 1.5;
}
#overlay button {
padding: 12px 32px;
font-size: 17px;
font-weight: 700;
border: none;
border-radius: 10px;
background: linear-gradient(135deg, #4a9eff, #7a4aff);
color: #fff;
cursor: pointer;
box-shadow: 0 4px 20px rgba(74,158,255,0.45);
transition: transform 0.15s, box-shadow 0.15s;
letter-spacing: 0.5px;
}
#overlay button:hover { transform: scale(1.05); box-shadow: 0 6px 28px rgba(74,158,255,0.6); }
#overlay .level-badge {
display: inline-block;
padding: 4px 14px;
border-radius: 20px;
background: rgba(255,255,255,0.1);
color: #b8ceff;
font-size: 13px;
margin-bottom: 18px;
font-weight: 500;
}
#overlay .stats {
display: flex;
gap: 28px;
margin-bottom: 22px;
color: #9ab0e0;
font-size: 14px;
}
#overlay .stats b { color: #e0ecff; }
#instructions {
position: absolute;
bottom: 14px;
left: 0; right: 0;
text-align: center;
color: rgba(200,216,255,0.35);
font-size: 12px;
z-index: 5;
pointer-events: none;
letter-spacing: 0.5px;
}
</style>
</head>
<body>
<div id="game">
<canvas id="canvas" width="640" height="480"></canvas>
<div id="hud">
<div class="hud-left">
<span id="scoreDisplay">Score: 0</span>
<span id="levelDisplay">Level 1</span>
</div>
<div class="hud-right">
<span id="livesDisplay">❤❤❤</span>
<span id="highDisplay">Best: 0</span>
</div>
</div>
<div id="overlay">
<h1 id="overlayTitle">BREAKOUT</h1>
<div id="overlayBadge" class="level-badge" style="display:none"></div>
<div id="overlayStats" class="stats" style="display:none"></div>
<h2 id="overlaySub" style="display:none"></h2>
<p id="overlayDesc">Clear the bricks with the ball. Don't let it fall!</p>
<button id="overlayBtn">PLAY</button>
</div>
<div id="instructions">Keyboard: ← → or A/D • Mouse: move to aim</div>
</div>
<script>
(() => {
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// ---- Colors / theme per level ----
const LEVEL_THEMES = [
{ bg: '#0f0f2a', bricks: [[255,140,80],[255,180,60],[255,220,100]], accent: '#ffb050', unbreakable: [180,180,220] },
{ bg: '#0d1a2a', bricks: [[60,200,255],[100,220,255],[160,240,255]], accent: '#50c0ff', unbreakable: [140,200,255] },
{ bg: '#1a0d2a', bricks: [[255,80,160],[255,120,200],[255,180,230]], accent: '#ff60a8', unbreakable: [220,180,220] },
{ bg: '#0d1a14', bricks: [[80,255,140],[120,255,180],[180,255,220]], accent: '#50ff90', unbreakable: [150,200,150] },
{ bg: '#1a140d', bricks: [[255,200,60],[255,160,40],[255,120,20]], accent: '#ffa030', unbreakable: [220,200,160] },
{ bg: '#0a0a2a', bricks: [[160,120,255],[200,160,255],[240,200,255]], accent: '#a080ff', unbreakable: [200,180,255] },
{ bg: '#1a0a14', bricks: [[255,60,100],[255,100,140],[255,160,180]], accent: '#ff5070', unbreakable: [240,200,200] },
{ bg: '#0a141a', bricks: [[60,255,200],[80,255,160],[120,255,220]], accent: '#40ffc0', unbreakable: [160,255,200] },
];
// ---- Game state ----
let W = 640, H = 480;
let gameState = 'menu'; // menu | playing | paused | levelIntro | gameOver | win
let score = 0;
let lives = 3;
let highScore = parseInt(localStorage.getItem('breakout_high') || '0', 10);
let currentLevel = 0;
let levelIndex = 0;
// paddle
let paddle = { x: W/2, y: 0, w: 80, h: 10, speed: 0, baseSpeed: 380, mouseX: W/2, useMouse: false, glow: 0 };
paddle.y = H - 30;
// ball
let ball = { x: 0, y: 0, r: 6, vx: 0, vy: 0, speed: 320, trail: [], stuck: true };
// bricks
let bricks = [];
const BRICK_ROWS = 7;
const BRICK_COLS = 10;
const BRICK_W = 54;
const BRICK_H = 20;
const BRICK_GAP = 6;
const BRICK_TOP = 50;
const BRICK_LEFT = (W - (BRICK_COLS * (BRICK_W + BRICK_GAP) - BRICK_GAP)) / 2;
// particles
let particles = [];
let blockBreakEffect = { active: false, t: 0, color: '#fff' };
let starField = [];
// input
const keys = {};
document.addEventListener('keydown', e => {
keys[e.code] = true;
if (['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','Space'].includes(e.code)) e.preventDefault();
if (gameState === 'playing' && ball.stuck && (e.code === 'ArrowLeft' || e.code === 'ArrowRight' || e.code === 'KeyA' || e.code === 'KeyD')) {
ball.stuck = false;
ball.vx = keys['ArrowRight'] || keys['KeyD'] ? 1 : -1;
ball.vy = -1;
const s = ball.speed;
const len = Math.hypot(ball.vx, ball.vy);
ball.vx = ball.vx / len * s * 0.75;
ball.vy = ball.vy / len * s;
paddle.glow = 1;
}
});
document.addEventListener('keyup', e => { keys[e.code] = false; });
canvas.addEventListener('mousemove', e => {
const rect = canvas.getBoundingClientRect();
const scaleX = canvas.width / rect.width;
const mx = (e.clientX - rect.left) * scaleX;
paddle.mouseX = Math.max(paddle.w/2, Math.min(W - paddle.w/2, mx));
if (gameState === 'playing') paddle.useMouse = true;
});
canvas.addEventListener('touchmove', e => {
e.preventDefault();
const rect = canvas.getBoundingClientRect();
const scaleX = canvas.width / rect.width;
const touch = e.touches[0];
const mx = (touch.clientX - rect.left) * scaleX;
paddle.mouseX = Math.max(paddle.w/2, Math.min(W - paddle.w/2, mx));
if (gameState === 'playing') paddle.useMouse = true;
}, { passive: false });
document.getElementById('overlayBtn').addEventListener('click', onClickOverlay);
// ---- Init ----
function initStars() {
starField = [];
for (let i = 0; i < 80; i++) starField.push({ x: Math.random()*W, y: Math.random()*H, s: Math.random()*1.4+0.3, twinkle: Math.random()*Math.PI*2 });
}
initStars();
function spawnParticles(x, y, color, count = 14, speed = 180) {
for (let i = 0; i < count; i++) {
const a = Math.random() * Math.PI * 2;
const s = (Math.random() * 0.7 + 0.3) * speed;
particles.push({
x, y,
vx: Math.cos(a) * s,
vy: Math.sin(a) * s,
life: 1,
decay: Math.random() * 2.2 + 1.5,
size: Math.random() * 3 + 1.5,
color
});
}
}
function spawnStarBurst(x, y, color, count = 8) {
for (let i = 0; i < count; i++) {
const a = Math.random() * Math.PI * 2;
const s = (Math.random() * 0.5 + 0.3) * 110;
particles.push({
x, y,
vx: Math.cos(a) * s,
vy: Math.sin(a) * s,
life: 1,
decay: 1.2,
size: 1.2,
color: '#ffffff',
star: true
});
}
}
function buildBricks(level) {
bricks = [];
const theme = LEVEL_THEMES[level % LEVEL_THEMES.length];
const rows = [7, 7, 8, 8, 9, 9, 10, 10][level % 8];
const cols = BRICK_COLS;
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
const isUnbreakable = (r === 0 && c === Math.floor(cols/2));
const hp = isUnbreakable ? 99 : (r % 3 === 0 ? 2 : 1);
const ci = r % theme.bricks.length;
const colors = theme.bricks[ci];
// slight variation per brick
const vary = 20;
const col = `rgb(${Math.min(255,colors[0]+Math.random()*vary- vary/2)},${Math.min(255,colors[1]+Math.random()*vary- vary/2)},${Math.min(255,colors[2]+Math.random()*vary- vary/2)})`;
bricks.push({
x: BRICK_LEFT + c * (BRICK_W + BRICK_GAP),
y: BRICK_TOP + r * (BRICK_H + BRICK_GAP),
w: BRICK_W, h: BRICK_H,
hp, maxHp: hp,
color: isUnbreakable ? `rgb(${theme.unbreakable[0]},${theme.unbreakable[1]},${theme.unbreakable[2]})` : col,
broken: false,
row: r, col: c,
shimmer: Math.random() * Math.PI * 2,
hitFlash: 0
});
}
}
}
function startLevel(idx) {
currentLevel = idx;
const theme = LEVEL_THEMES[idx % LEVEL_THEMES.length];
buildBricks(idx);
paddle.x = W / 2;
paddle.mouseX = W / 2;
paddle.useMouse = false;
paddle.glow = 0;
ball.x = paddle.x;
ball.y = paddle.y - ball.r - 2;
ball.stuck = true;
ball.trail = [];
ball.speed = 300 + idx * 12;
ball.speed = Math.min(ball.speed, 440);
particles = [];
gameState = 'playing';
updateHUD();
hideOverlay(false);
}
function showOverlay(title, sub, desc, btnText, badge, stats) {
const ov = document.getElementById('overlay');
const t = document.getElementById('overlayTitle');
const s = document.getElementById('overlaySub');
const d = document.getElementById('overlayDesc');
const b = document.getElementById('overlayBtn');
const badgeEl = document.getElementById('overlayBadge');
const statsEl = document.getElementById('overlayStats');
t.textContent = title;
t.style.display = '';
if (sub) { s.textContent = sub; s.style.display = ''; } else s.style.display = 'none';
if (desc) { d.textContent = desc; d.style.display = ''; } else d.style.display = 'none';
b.textContent = btnText;
if (badge) { badgeEl.textContent = badge; badgeEl.style.display = ''; } else badgeEl.style.display = 'none';
if (stats) {
statsEl.innerHTML = stats;
statsEl.style.display = '';
} else statsEl.style.display = 'none';
ov.classList.remove('hidden');
}
function hideOverlay(instant) {
const ov = document.getElementById('overlay');
if (instant) { ov.classList.add('hidden'); return; }
ov.classList.remove('hidden');
requestAnimationFrame(() => ov.classList.add('hidden'));
}
function onClickOverlay() {
if (gameState === 'menu') {
score = 0;
lives = 3;
levelIndex = 0;
startLevel(0);
} else if (gameState === 'gameOver') {
score = 0;
lives = 3;
levelIndex = 0;
startLevel(0);
} else if (gameState === 'win') {
levelIndex = 0;
startLevel(0);
}
}
function updateHUD() {
document.getElementById('scoreDisplay').textContent = `Score: ${score}`;
document.getElementById('levelDisplay').textContent = `Level ${currentLevel + 1}`;
document.getElementById('livesDisplay').textContent = '❤'.repeat(Math.max(0, lives));
document.getElementById('highDisplay').textContent = `Best: ${highScore}`;
}
function resetBall() {
ball.x = paddle.x;
ball.y = paddle.y - ball.r - 2;
ball.stuck = true;
ball.vx = 0;
ball.vy = 0;
ball.trail = [];
if (lives <= 0) {
gameState = 'gameOver';
if (score > highScore) {
highScore = score;
localStorage.setItem('breakout_high', String(highScore));
}
updateHUD();
showOverlay(
'GAME OVER',
'',
`You scored ${score} points across ${currentLevel} level(s).`,
'TRY AGAIN',
'',
`<div class="stats"><span>Score <b>${score}</b></span><span>Levels <b>${currentLevel}</b></span></div>`
);
}
}
function nextLevel() {
levelIndex++;
if (levelIndex >= LEVEL_THEMES.length) {
// beat the game
gameState = 'win';
if (score > highScore) {
highScore = score;
localStorage.setItem('breakout_high', String(highScore));
}
updateHUD();
showOverlay(
'YOU WIN!',
'All levels cleared.',
`Final score: ${score}. You're a breakout master!`,
'PLAY AGAIN',
'🏆 Champion',
`<div class="stats"><span>Score <b>${score}</b></span><span>Best <b>${highScore}</b></span></div>`
);
return;
}
showOverlay(
`Level ${levelIndex + 1}`,
LEVEL_THEMES[levelIndex % LEVEL_THEMES.length].accent,
'Ready...',
'START',
`Level ${levelIndex + 1}`,
''
);
gameState = 'menu';
}
// ---- Collision & physics ----
function ballPaddleCollision() {
if (ball.stuck) return;
const px = paddle.x - paddle.w / 2;
const py = paddle.y;
if (ball.vy > 0 &&
ball.x > px && ball.x < px + paddle.w &&
ball.y + ball.r >= py && ball.y + ball.r <= py + paddle.h + 6 &&
ball.y + ball.r - ball.vy * (1/60) <= py + paddle.h) {
// reflect
const normy = 1;
const nx = 0;
const ny = 1;
const dot = ball.vx * nx + ball.vy * ny;
// relative hit position on paddle (-1..1)
const hit = (ball.x - paddle.x) / (paddle.w / 2);
const angle = (hit) * (Math.PI / 3.2); // ~56deg max
const sp = Math.hypot(ball.vx, ball.vy);
ball.vx = Math.sin(angle) * sp * (hit > 0 ? 1 : -1) * 0.96;
ball.vy = -Math.cos(angle) * sp * 0.96;
ball.y = py - ball.r - 1;
paddle.glow = 1;
spawnParticles(ball.x, py, '#7abfff', 6, 120);
}
}
function ballBrickCollision() {
if (ball.stuck) return;
for (let i = 0; i < bricks.length; i++) {
const b = bricks[i];
if (b.broken) continue;
// AABB vs circle (conservative)
const cx = Math.max(b.x, Math.min(ball.x, b.x + b.w));
const cy = Math.max(b.y, Math.min(ball.y, b.y + b.h));
const dx = ball.x - cx;
const dy = ball.y - cy;
const dist = Math.hypot(dx, dy);
if (dist < ball.r) {
// determine which side
const overlapLeft = (ball.x + ball.r) - b.x;
const overlapRight = (b.x + b.w) - (ball.x - ball.r);
const overlapTop = (ball.y + ball.r) - b.y;
const overlapBottom = (b.y + b.h) - (ball.y - ball.r);
const minOverlap = Math.min(overlapLeft, overlapRight, overlapTop, overlapBottom);
if (minOverlap === overlapTop) ball.vy = -ball.vy;
else if (minOverlap === overlapBottom) ball.vy = -ball.vy;
else if (minOverlap === overlapLeft) ball.vx = -ball.vx;
else ball.vx = -ball.vx;
// push out
if (ball.vy < 0) ball.y = b.y - ball.r - 1;
else if (ball.vy > 0) ball.y = b.y + b.h + ball.r + 1;
if (ball.vx < 0) ball.x = b.x - ball.r - 1;
else if (ball.vx > 0) ball.x = b.x + b.w + ball.r + 1;
// damage
b.hp--;
b.hitFlash = 1;
if (b.hp <= 0) {
b.broken = true;
const pts = b.maxHp === 99 ? 0 : (b.row + 1) * 10 + b.col * 2;
score += pts;
spawnParticles(b.x + b.w/2, b.y + b.h/2, b.color, 16, 200);
spawnStarBurst(b.x + b.w/2, b.y + b.h/2, b.color, 6);
// check level clear
const remaining = bricks.some(bb => !bb.broken);
if (!remaining) {
// level clear
setTimeout(() => {
if (gameState === 'playing') nextLevel();
}, 400);
}
} else {
spawnParticles(cx, cy, b.color, 6, 140);
b.color = `rgb(${Math.random()*30+200},${Math.random()*40+180},${Math.random()*30+200})`;
}
updateHUD();
return; // one brick per frame
}
}
}
// ---- Update ----
let lastT = 0;
function update(dt) {
// stars
for (const s of starField) s.twinkle += dt * 2.5;
// paddle
if (gameState === 'playing') {
paddle.glow = Math.max(0, paddle.glow - dt * 3);
if (paddle.useMouse) {
paddle.x += (paddle.mouseX - paddle.x) * Math.min(1, dt * 12);
} else {
let dir = 0;
if (keys['ArrowLeft'] || keys['KeyA']) dir = -1;
if (keys['ArrowRight'] || keys['KeyD']) dir = 1;
paddle.x += dir * paddle.baseSpeed * dt;
paddle.x = Math.max(paddle.w/2, Math.min(W - paddle.w/2, paddle.x));
}
}
if (gameState === 'playing' && !ball.stuck) {
ball.x += ball.vx * dt;
ball.y += ball.vy * dt;
// walls
if (ball.x - ball.r < 0) { ball.x = ball.r; ball.vx = -ball.vx; spawnParticles(ball.x, ball.y, '#7abfff', 4, 80); }
if (ball.x + ball.r > W) { ball.x = W - ball.r; ball.vx = -ball.vx; spawnParticles(ball.x, ball.y, '#7abfff', 4, 80); }
if (ball.y - ball.r < 0) { ball.y = ball.r; ball.vy = -ball.vy; spawnParticles(ball.x, ball.y, '#7abfff', 4, 80); }
// bottom
if (ball.y - ball.r > H) {
lives--;
updateHUD();
resetBall();
continue;
}
ballPaddleCollision();
ballBrickCollision();
// trail
ball.trail.push({ x: ball.x, y: ball.y, life: 1 });
if (ball.trail.length > 14) ball.trail.shift();
for (const t of ball.trail) t.life -= dt * 4.5;
ball.trail = ball.trail.filter(t => t.life > 0);
}
// particles
for (const p of particles) {
p.x += p.vx * dt;
p.y += p.vy * dt;
p.vy += 180 * dt; // gravity
p.life -= p.decay * dt;
p.vx *= 0.98;
p.vy *= 0.98;
}
particles = particles.filter(p => p.life > 0);
// brick flash decay
for (const b of bricks) {
b.hitFlash = Math.max(0, b.hitFlash - dt * 5);
b.shimmer += dt * 2;
}
}
// ---- Draw ----
function draw() {
ctx.clearRect(0, 0, W, H);
const theme = LEVEL_THEMES[currentLevel % LEVEL_THEMES.length];
ctx.fillStyle = theme.bg;
ctx.fillRect(0, 0, W, H);
// stars
for (const s of starField) {
const a = 0.3 + 0.4 * (0.5 + 0.5 * Math.sin(s.twinkle));
ctx.globalAlpha = a;
ctx.fillStyle = '#e8f0ff';
ctx.fillRect(s.x, s.y, s.s, s.s);
}
ctx.globalAlpha = 1;
// bricks
for (const b of bricks) {
if (b.broken) continue;
const x = b.x, y = b.y, w = b.w, h = b.h;
// glow for unbreakable
const isUB = b.maxHp === 99;
if (isUB) {
ctx.shadowColor = theme.accent;
ctx.shadowBlur = 6;
}
// base
ctx.fillStyle = b.color;
ctx.fillRect(x, y, w, h);
ctx.shadowBlur = 0;
// border
ctx.strokeStyle = `rgba(255,255,255,0.15)`;
ctx.lineWidth = 1;
ctx.strokeRect(x + 0.5, y + 0.5, w - 1, h - 1);
// hit flash
if (b.hitFlash > 0) {
ctx.fillStyle = `rgba(255,255,255,${b.hitFlash * 0.6})`;
ctx.fillRect(x, y, w, h);
}
// hp indicator for multi-hit
if (b.maxHp > 1) {
ctx.fillStyle = 'rgba(255,255,255,0.5)';
ctx.font = 'bold 11px system-ui';
ctx.textAlign = 'center';
ctx.fillText(b.hp, x + w/2, y + h/2 + 4);
}
// unbreakable icon
if (isUB) {
ctx.fillStyle = 'rgba(255,255,255,0.85)';
ctx.font = 'bold 14px system-ui';
ctx.textAlign = 'center';
ctx.fillText('◆', x + w/2, y + h/2 + 5);
}
// shimmer highlight
const sh = (Math.sin(b.shimmer) * 0.5 + 0.5) * 0.18;
if (sh > 0.05) {
ctx.fillStyle = `rgba(255,255,255,${sh})`;
ctx.fillRect(x, y, w, h * 0.35);
}
}
// ball trail
for (let i = 0; i < ball.trail.length; i++) {
const t = ball.trail[i];
const a = t.life * 0.5;
ctx.globalAlpha = a;
ctx.fillStyle = '#a8d0ff';
ctx.beginPath();
ctx.arc(t.x, t.y, ball.r * (0.3 + t.life * 0.7), 0, Math.PI * 2);
ctx.fill();
}
ctx.globalAlpha = 1;
// ball
if (!ball.stuck || gameState !== 'playing') {
// glow
const grad = ctx.createRadialGradient(ball.x, ball.y, 0, ball.x, ball.y, ball.r * 4);
grad.addColorStop(0, 'rgba(180,220,255,0.35)');
grad.addColorStop(1, 'rgba(180,220,255,0)');
ctx.fillStyle = grad;
ctx.beginPath();
ctx.arc(ball.x, ball.y, ball.r * 4, 0, Math.PI * 2);
ctx.fill();
}
ctx.fillStyle = '#e8f2ff';
ctx.beginPath();
ctx.arc(ball.x, ball.y, ball.r, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.7)';
ctx.beginPath();
ctx.arc(ball.x - 1.5, ball.y - 2, ball.r * 0.35, 0, Math.PI * 2);
ctx.fill();
// paddle
const px = paddle.x - paddle.w / 2;
const py = paddle.y;
// glow
if (paddle.glow > 0.05) {
ctx.shadowColor = '#7abfff';
ctx.shadowBlur = 18 * paddle.glow;
}
const grad = ctx.createLinearGradient(px, py, px, py + paddle.h);
grad.addColorStop(0, '#5a9eff');
grad.addColorStop(1, '#3a6ad0');
ctx.fillStyle = grad;
ctx.beginPath();
ctx.roundRect(px, py, paddle.w, paddle.h, 5);
ctx.fill();
ctx.shadowBlur = 0;
// highlight
ctx.fillStyle = 'rgba(255,255,255,0.25)';
ctx.beginPath();
ctx.roundRect(px + 4, py + 1, paddle.w - 8, paddle.h * 0.45, 3);
ctx.fill();
// paddle rim
ctx.strokeStyle = 'rgba(180,220,255,0.4)';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.roundRect(px + 0.5, py + 0.5, paddle.w - 1, paddle.h - 1, 5);
ctx.stroke();
// particles
for (const p of particles) {
ctx.globalAlpha = Math.max(0, p.life);
if (p.star) {
ctx.fillStyle = p.color;
ctx.fillRect(p.x - p.size/2, p.y - p.size/2, p.size, p.size);
} else {
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size * p.life, 0, Math.PI * 2);
ctx.fill();
}
}
ctx.globalAlpha = 1;
// vignette
const vig = ctx.createRadialGradient(W/2, H/2, H*0.3, W/2, H/2, H*0.8);
vig.addColorStop(0, 'rgba(0,0,0,0)');
vig.addColorStop(1, 'rgba(0,0,0,0.45)');
ctx.fillStyle = vig;
ctx.fillRect(0, 0, W, H);
// bottom line hint
ctx.strokeStyle = 'rgba(120,160,255,0.15)';
ctx.lineWidth = 1;
ctx.setLineDash([4, 6]);
ctx.beginPath();
ctx.moveTo(0, H - 2);
ctx.lineTo(W, H - 2);
ctx.stroke();
ctx.setLineDash([]);
}
// ---- Main loop ----
function loop(t) {
const dt = Math.min(0.032, (t - lastT) / 1000 || 0);
lastT = t;
if (gameState === 'playing') update(dt);
draw();
requestAnimationFrame(loop);
}
// ---- Boot ----
// roundRect polyfill for older browsers
if (!CanvasRenderingContext2D.prototype.roundRect) {
CanvasRenderingContext2D.prototype.roundRect = function(x, y, w, h, r) {
if (r > w/2) r = w/2;
if (r > h/2) r = h/2;
this.moveTo(x + r, y);
this.arcTo(x + w, y, x + w, y + h, r);
this.arcTo(x + w, y + h, x, y + h, r);
this.arcTo(x, y + h, x, y, r);
this.arcTo(x, y, x + w, y, r);
return this;
};
}
showOverlay(
'BREAKOUT',
'',
'Bounce the ball to clear all bricks.\nMulti-hit bricks shown with numbers.\n◆ = unbreakable. Clear the level to advance!',
'START GAME',
'',
`<div class="stats"><span>High score <b>${highScore}</b></span></div>`
);
// subtle initial draw
paddle.x = W/2;
ball.x = paddle.x;
ball.y = paddle.y - ball.r - 2;
ball.stuck = true;
requestAnimationFrame(loop);
})();
</script>
</body>
</html>

