Run details
- Model
- nvidia/nemotron-3-ultra-550b-a55b:free
- Route
- OpenRouter API
- Served by
- Nvidia
- Effort
- high (OpenRouter default)
- Limits
- 60 min · 65,536 output tokens (model max)
- Date
- 24 Oct 2026
- Time
- 3 min 39 s
- Size
- 41 kB
- Tokens
- 94 in, 13,605 out (134 thinking)
- List price
- $0.029 at today's price ($0.50 in / $2.15 out per M)
- Paid
- $0 (free route)
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,120 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>BREAKOUT NEON</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: #0a0a12;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-family: 'Courier New', Courier, monospace;
color: #00ffc8;
overflow: hidden;
}
canvas {
display: block;
box-shadow: 0 0 40px rgba(0, 255, 200, 0.3),
0 0 80px rgba(0, 255, 200, 0.1),
inset 0 0 60px rgba(0, 255, 200, 0.05);
border: 2px solid #00ffc8;
border-radius: 4px;
}
.ui {
display: flex;
justify-content: space-between;
width: 720px;
margin-bottom: 10px;
padding: 0 4px;
font-size: 14px;
letter-spacing: 2px;
text-transform: uppercase;
opacity: 0.8;
}
.ui span {
display: flex;
align-items: center;
gap: 8px;
}
.ui .label { opacity: 0.5; }
.ui .value { font-weight: bold; color: #fff; text-shadow: 0 0 10px #00ffc8; }
#levelDisplay .value { color: #ffd700; text-shadow: 0 0 10px #ffd700; }
#livesDisplay .value { color: #ff4757; text-shadow: 0 0 10px #ff4757; }
.controls-hint {
margin-top: 12px;
font-size: 11px;
opacity: 0.4;
letter-spacing: 1px;
text-align: center;
max-width: 720px;
}
.controls-hint kbd {
background: rgba(0, 255, 200, 0.1);
border: 1px solid rgba(0, 255, 200, 0.3);
padding: 2px 6px;
border-radius: 3px;
margin: 0 2px;
}
.overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.9);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 100;
transition: opacity 0.3s, visibility 0.3s;
}
.overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.overlay h1 {
font-size: 48px;
font-weight: 700;
letter-spacing: 8px;
background: linear-gradient(90deg, #00ffc8, #ffd700, #ff4757, #00ffc8);
background-size: 300% 100%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: gradientShift 3s linear infinite;
margin-bottom: 8px;
text-shadow: none;
}
@keyframes gradientShift { 0% { background-position: 0% 50%; } 100% { background-position: 300% 50%; } }
.overlay p { font-size: 14px; opacity: 0.6; letter-spacing: 3px; margin-bottom: 30px; }
.btn {
background: transparent;
border: 2px solid #00ffc8;
color: #00ffc8;
padding: 14px 48px;
font-family: inherit;
font-size: 14px;
letter-spacing: 4px;
text-transform: uppercase;
cursor: pointer;
transition: all 0.2s;
position: relative;
overflow: hidden;
}
.btn::before {
content: '';
position: absolute;
inset: 0;
background: #00ffc8;
transform: translateX(-101%);
transition: transform 0.2s;
z-index: -1;
}
.btn:hover { color: #0a0a12; }
.btn:hover::before { transform: translateX(0); }
.btn:focus-visible { outline: 2px solid #ffd700; outline-offset: 4px; }
.level-transition {
position: fixed;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 50;
pointer-events: none;
opacity: 0;
transition: opacity 0.3s;
}
.level-transition.active { opacity: 1; }
.level-transition h2 {
font-size: 60px;
font-weight: 700;
letter-spacing: 12px;
background: linear-gradient(90deg, #ffd700, #fff, #ffd700);
background-size: 200% 100%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: goldShift 1.5s linear infinite;
transform: scale(0.8);
transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.level-transition.active h2 { transform: scale(1); }
@keyframes goldShift { 0% { background-position: 200% 50%; } 100% { background-position: -200% 50%; } }
.powerup-indicator {
position: fixed;
bottom: 20px;
right: 20px;
display: flex;
flex-direction: column;
gap: 8px;
z-index: 10;
pointer-events: none;
}
.powerup-slot {
width: 50px;
height: 50px;
border: 2px solid rgba(0, 255, 200, 0.3);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
background: rgba(0, 0, 0, 0.5);
opacity: 0.3;
transform: scale(0.8);
transition: all 0.2s;
}
.powerup-slot.active { opacity: 1; transform: scale(1); border-color: currentColor; box-shadow: 0 0 20px currentColor; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 20px currentColor; } 50% { box-shadow: 0 0 40px currentColor; } }
@media (max-width: 760px) {
canvas { width: 95vw; height: auto; border-width: 1px; }
.ui { width: 95vw; font-size: 11px; }
.overlay h1 { font-size: 32px; letter-spacing: 4px; }
.level-transition h2 { font-size: 36px; letter-spacing: 6px; }
}
</style>
</head>
<body>
<div class="ui">
<div id="scoreDisplay"><span class="label">SCORE</span><span class="value" id="score">0</span></div>
<div id="levelDisplay"><span class="label">LEVEL</span><span class="value" id="level">1</span></div>
<div id="livesDisplay"><span class="label">LIVES</span><span class="value" id="lives">●●●</span></div>
</div>
<canvas id="game" width="720" height="480"></canvas>
<div class="controls-hint">← → / A D / Mouse to move | Space / Click / Tap to launch | P / Esc to pause</div>
<div class="overlay" id="startOverlay">
<h1>BREAKOUT NEON</h1>
<p>Destroy all bricks to advance</p>
<button class="btn" id="startBtn">START GAME</button>
</div>
<div class="overlay hidden" id="pauseOverlay">
<h1>PAUSED</h1>
<p>Press P or click to resume</p>
<button class="btn" id="resumeBtn">RESUME</button>
</div>
<div class="overlay hidden" id="gameOverOverlay">
<h1>GAME OVER</h1>
<p>Final Score: <span id="finalScore" style="color:#00ffc8">0</span></p>
<button class="btn" id="restartBtn">PLAY AGAIN</button>
</div>
<div class="overlay hidden" id="winOverlay">
<h1>VICTORY</h1>
<p>Final Score: <span id="winScore" style="color:#ffd700">0</span></p>
<button class="btn" id="nextGameBtn">NEW GAME</button>
</div>
<div class="level-transition" id="levelTransition">
<h2 id="levelText">LEVEL 1</h2>
</div>
<div class="powerup-indicator" id="powerupIndicator"></div>
<script>
// ============ GAME CONSTANTS ============
const CANVAS_W = 720, CANVAS_H = 480;
const PADDLE_W = 100, PADDLE_H = 16, PADDLE_Y = CANVAS_H - 40;
const BALL_R = 8;
const BRICK_ROWS = 6, BRICK_COLS = 10;
const BRICK_W = 68, BRICK_H = 24, BRICK_GAP = 4;
const BRICK_OFFSET_X = (CANVAS_W - (BRICK_COLS * (BRICK_W + BRICK_GAP) - BRICK_GAP)) / 2;
const BRICK_OFFSET_Y = 60;
const MAX_LEVELS = 8;
const INITIAL_LIVES = 3;
const BASE_BALL_SPEED = 4.5;
const MAX_BALL_SPEED = 14;
// Power-up types
const POWERUPS = {
WIDE: { char: '▲', color: '#00ffc8', name: 'WIDE PADDLE', duration: 10000 },
MULTI: { char: '◆', color: '#ffd700', name: 'MULTI BALL', duration: 0 },
SLOW: { char: '■', color: '#74b9ff', name: 'SLOW BALL', duration: 8000 },
LIFE: { char: '♥', color: '#ff4757', name: 'EXTRA LIFE', duration: 0 },
LASER: { char: '⚡', color: '#ff6b6b', name: 'LASER', duration: 8000 },
SCORE: { char: '★', color: '#fdcb6e', name: 'BONUS', duration: 0 }
};
const POWERUP_DROP_CHANCE = 0.15;
const POWERUP_FALL_SPEED = 2.5;
const POWERUP_SIZE = 24;
// ============ AUDIO ENGINE ============
class AudioEngine {
constructor() {
this.ctx = null;
this.enabled = true;
this.masterGain = null;
}
init() {
if (this.ctx) return;
this.ctx = new (window.AudioContext || window.webkitAudioContext)();
this.masterGain = this.ctx.createGain();
this.masterGain.connect(this.ctx.destination);
this.masterGain.gain.value = 0.3;
}
resume() { if (this.ctx && this.ctx.state === 'suspended') this.ctx.resume(); }
tone(freq, dur, type='square', vol=1, sweep=null) {
if (!this.enabled || !this.ctx) return;
const t = this.ctx.currentTime;
const osc = this.ctx.createOscillator();
const gain = this.ctx.createGain();
osc.type = type;
osc.frequency.value = freq;
if (sweep) {
osc.frequency.setValueAtTime(sweep[0], t);
osc.frequency.exponentialRampToValueAtTime(sweep[1], t + dur);
}
gain.gain.setValueAtTime(vol * 0.1, t);
gain.gain.exponentialRampToValueAtTime(0.001, t + dur);
osc.connect(gain); gain.connect(this.masterGain);
osc.start(t); osc.stop(t + dur);
}
noise(dur, vol=1) {
if (!this.enabled || !this.ctx) return;
const t = this.ctx.currentTime;
const bufferSize = this.ctx.sampleRate * dur;
const buffer = this.ctx.createBuffer(1, bufferSize, this.ctx.sampleRate);
const data = buffer.getChannelData(0);
for (let i = 0; i < bufferSize; i++) data[i] = Math.random() * 2 - 1;
const src = this.ctx.createBufferSource();
const gain = this.ctx.createGain();
const filter = this.ctx.createBiquadFilter();
filter.type = 'highpass'; filter.frequency.value = 1000;
src.buffer = buffer;
gain.gain.setValueAtTime(vol * 0.05, t);
gain.gain.exponentialRampToValueAtTime(0.001, t + dur);
src.connect(filter); filter.connect(gain); gain.connect(this.masterGain);
src.start(t);
}
// Sound effects
paddleHit(ballSpeed) { this.tone(220 + ballSpeed * 10, 0.08, 'square', 0.8, [220 + ballSpeed * 10, 440]); }
brickHit(points, combo) {
const base = 300 + combo * 50;
this.tone(base, 0.06, 'triangle', 0.6, [base, base * 2]);
}
brickBreak(tier) { this.tone(400 + tier * 100, 0.12, 'sawtooth', 0.5, [400 + tier * 100, 800 + tier * 200]); }
wallHit() { this.tone(150, 0.05, 'square', 0.4); }
lifeLost() { this.tone(200, 0.3, 'sawtooth', 0.6, [200, 80]); this.noise(0.2, 0.5); }
powerupSpawn() { this.tone(600, 0.15, 'sine', 0.4, [600, 1200]); }
powerupCollect(type) {
const freqs = { WIDE: 800, MULTI: 1000, SLOW: 500, LIFE: 1200, LASER: 1100, SCORE: 1400 };
this.tone(freqs[type] || 800, 0.2, 'sine', 0.7, [freqs[type] || 800, (freqs[type] || 800) * 1.5]);
}
levelUp() {
[0, 0.1, 0.2, 0.3].forEach((d, i) => this.tone(440 * Math.pow(2, i/4), 0.15, 'triangle', 0.4, null, d));
}
gameOver() { [0, 0.15, 0.3].forEach((d, i) => this.tone(200 * Math.pow(0.5, i), 0.4, 'sawtooth', 0.5, [200 * Math.pow(0.5, i), 50], d)); }
laserFire() { this.tone(800, 0.05, 'square', 0.3, [1200, 400]); }
}
const audio = new AudioEngine();
// ============ PARTICLE SYSTEM ============
class Particle {
constructor(x, y, color, velocity, life, size, gravity=0, fade=true) {
this.x = x; this.y = y; this.color = color; this.vx = velocity[0]; this.vy = velocity[1];
this.life = life; this.maxLife = life; this.size = size; this.gravity = gravity; this.fade = fade;
this.rotation = Math.random() * Math.PI * 2; this.rotSpeed = (Math.random() - 0.5) * 0.2;
}
update(dt) {
this.x += this.vx * dt; this.y += this.vy * dt;
this.vy += this.gravity * dt; this.life -= dt; this.rotation += this.rotSpeed * dt;
return this.life > 0;
}
draw(ctx) {
const alpha = this.fade ? this.life / this.maxLife : 1;
ctx.globalAlpha = alpha;
ctx.fillStyle = this.color;
ctx.save();
ctx.translate(this.x, this.y);
ctx.rotate(this.rotation);
ctx.fillRect(-this.size/2, -this.size/2, this.size, this.size);
ctx.restore();
ctx.globalAlpha = 1;
}
}
class ParticleSystem {
constructor() { this.particles = []; }
update(dt) { this.particles = this.particles.filter(p => p.update(dt)); }
draw(ctx) { this.particles.forEach(p => p.draw(ctx)); }
emit(x, y, color, count, speedRange, lifeRange, sizeRange, gravity=0, fade=true) {
for (let i = 0; i < count; i++) {
const angle = Math.random() * Math.PI * 2;
const speed = speedRange[0] + Math.random() * (speedRange[1] - speedRange[0]);
this.particles.push(new Particle(
x, y, color,
[Math.cos(angle) * speed, Math.sin(angle) * speed],
lifeRange[0] + Math.random() * (lifeRange[1] - lifeRange[0]),
sizeRange[0] + Math.random() * (sizeRange[1] - sizeRange[0]),
gravity, fade
));
}
}
// Special effects
brickExplosion(x, y, color, tier) {
this.emit(x, y, color, 20 + tier * 5, [100, 300], [0.4, 0.8], [3, 8], 200);
this.emit(x, y, '#fff', 10, [200, 400], [0.2, 0.4], [2, 5], 100);
}
paddleHit(x, y, color) {
this.emit(x, y, color, 12, [150, 250], [0.3, 0.5], [2, 6], 100);
}
ballTrail(x, y, color) {
this.particles.push(new Particle(x, y, color, [0,0], 0.15, 4, 0, true));
}
powerupCollect(x, y, color) {
this.emit(x, y, color, 30, [100, 300], [0.5, 1], [4, 10], -50);
this.emit(x, y, '#fff', 15, [200, 400], [0.3, 0.6], [2, 5], 0);
}
laserHit(x, y) {
this.emit(x, y, '#ff6b6b', 8, [50, 150], [0.2, 0.4], [2, 4], 0);
}
}
const particles = new ParticleSystem();
// ============ SCREEN SHAKE ============
let shakeIntensity = 0, shakeTime = 0;
function addShake(intensity, duration) {
shakeIntensity = Math.max(shakeIntensity, intensity);
shakeTime = Math.max(shakeTime, duration);
}
// ============ ENTITIES ============
class Paddle {
constructor() { this.reset(); }
reset() {
this.x = CANVAS_W / 2 - PADDLE_W / 2;
this.y = PADDLE_Y;
this.w = PADDLE_W; this.h = PADDLE_H;
this.targetX = this.x; this.velX = 0;
this.color = '#00ffc8'; this.glow = 0;
this.laserActive = false; this.laserTimer = 0;
this.widthTimer = 0; this.baseWidth = PADDLE_W;
}
update(dt, input) {
// Mouse/keyboard input
if (input.mouseX !== null) this.targetX = input.mouseX - this.w / 2;
if (input.left) this.targetX -= 600 * dt;
if (input.right) this.targetX += 600 * dt;
this.targetX = Math.max(0, Math.min(CANVAS_W - this.w, this.targetX));
this.velX = (this.targetX - this.x) * 15 * dt;
this.x = this.targetX;
// Timers
if (this.widthTimer > 0) { this.widthTimer -= dt; if (this.widthTimer <= 0) this.w = this.baseWidth; }
if (this.laserTimer > 0) { this.laserTimer -= dt; if (this.laserTimer <= 0) this.laserActive = false; }
this.glow = Math.max(0, this.glow - dt * 3);
}
draw(ctx) {
ctx.save();
// Glow
if (this.glow > 0 || this.laserActive) {
ctx.shadowColor = this.laserActive ? '#ff6b6b' : this.color;
ctx.shadowBlur = 20 + this.glow * 30;
}
// Body
const gradient = ctx.createLinearGradient(this.x, this.y, this.x, this.y + this.h);
gradient.addColorStop(0, this.color);
gradient.addColorStop(0.5, '#00ccaa');
gradient.addColorStop(1, '#009977');
ctx.fillStyle = gradient;
this.roundRect(ctx, this.x, this.y, this.w, this.h, 4);
ctx.fill();
// Laser indicators
if (this.laserActive) {
ctx.fillStyle = '#ff6b6b';
ctx.fillRect(this.x + 4, this.y + 2, 4, this.h - 4);
ctx.fillRect(this.x + this.w - 8, this.y + 2, 4, this.h - 4);
}
ctx.restore();
}
roundRect(ctx, x, y, w, h, r) {
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();
}
activatePowerup(type) {
switch(type) {
case 'WIDE': this.w = Math.min(this.w * 1.5, 200); this.widthTimer = POWERUPS.WIDE.duration / 1000; break;
case 'LASER': this.laserActive = true; this.laserTimer = POWERUPS.LASER.duration / 1000; break;
}
}
}
class Ball {
constructor(x, y, vx, vy, isMain=true) {
this.x = x; this.y = y; this.vx = vx; this.vy = vy;
this.r = BALL_R; this.isMain = isMain;
this.trail = []; this.maxTrail = 8;
this.color = '#fff'; this.glowColor = '#00ffc8';
this.speedMultiplier = 1; this.slowTimer = 0;
}
update(dt, paddle) {
// Trail
this.trail.unshift({ x: this.x, y: this.y });
if (this.trail.length > this.maxTrail) this.trail.pop();
// Slow effect
if (this.slowTimer > 0) { this.slowTimer -= dt; this.speedMultiplier = 0.6; }
else this.speedMultiplier = 1;
const speed = Math.hypot(this.vx, this.vy) * this.speedMultiplier;
this.x += this.vx * dt * this.speedMultiplier;
this.y += this.vy * dt * this.speedMultiplier;
// Walls
if (this.x - this.r < 0) { this.x = this.r; this.vx = Math.abs(this.vx); audio.wallHit(); addShake(2, 0.05); }
if (this.x + this.r > CANVAS_W) { this.x = CANVAS_W - this.r; this.vx = -Math.abs(this.vx); audio.wallHit(); addShake(2, 0.05); }
if (this.y - this.r < 0) { this.y = this.r; this.vy = Math.abs(this.vy); audio.wallHit(); addShake(2, 0.05); }
// Paddle collision
if (this.vy > 0 && this.y + this.r >= paddle.y && this.y - this.r <= paddle.y + paddle.h &&
this.x + this.r >= paddle.x && this.x - this.r <= paddle.x + paddle.w) {
this.y = paddle.y - this.r;
const hitPos = (this.x - paddle.x) / paddle.w - 0.5;
const angle = hitPos * Math.PI * 0.65;
const newSpeed = Math.min(speed * 1.02, MAX_BALL_SPEED);
this.vx = Math.sin(angle) * newSpeed;
this.vy = -Math.cos(angle) * newSpeed;
paddle.glow = 1;
audio.paddleHit(newSpeed);
particles.paddleHit(this.x, this.y, this.glowColor);
addShake(3, 0.08);
}
return this.y < CANVAS_H + 50; // alive
}
draw(ctx) {
// Trail
this.trail.forEach((pos, i) => {
const alpha = (i + 1) / this.trail.length * 0.4;
ctx.globalAlpha = alpha;
ctx.fillStyle = this.glowColor;
ctx.beginPath();
ctx.arc(pos.x, pos.y, this.r * (i + 1) / this.trail.length, 0, Math.PI * 2);
ctx.fill();
});
ctx.globalAlpha = 1;
// Ball glow
ctx.shadowColor = this.glowColor;
ctx.shadowBlur = 15;
ctx.fillStyle = this.color;
ctx.beginPath();
ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2);
ctx.fill();
ctx.shadowBlur = 0;
}
setSlow(duration) { this.slowTimer = duration / 1000; }
}
class Brick {
constructor(x, y, tier) {
this.x = x; this.y = y; this.w = BRICK_W; this.h = BRICK_H;
this.tier = Math.max(1, Math.min(4, tier)); // 1-4
this.health = this.tier;
this.maxHealth = this.tier;
this.alive = true;
this.hitFlash = 0;
this.setColor();
}
setColor() {
const colors = ['', '#74b9ff', '#00ffc8', '#ffd700', '#ff4757'];
this.color = colors[this.tier];
this.glowColor = colors[this.tier];
}
hit(ball, game) {
if (!this.alive) return 0;
this.health--;
this.hitFlash = 0.15;
let points = 10 * this.tier;
if (this.health <= 0) {
this.alive = false;
points = 50 * this.tier;
audio.brickBreak(this.tier);
particles.brickExplosion(this.x + this.w/2, this.y + this.h/2, this.color, this.tier);
addShake(this.tier * 1.5, 0.1);
// Powerup drop
if (Math.random() < POWERUP_DROP_CHANCE) {
game.spawnPowerup(this.x + this.w/2, this.y + this.h/2);
}
} else {
audio.brickHit(points, game.combo);
particles.emit(this.x + this.w/2, this.y + this.h/2, this.color, 8, [80, 180], [0.2, 0.4], [2, 5], 100);
addShake(1, 0.05);
}
return points;
}
update(dt) { if (this.hitFlash > 0) this.hitFlash -= dt; }
draw(ctx) {
if (!this.alive) return;
ctx.save();
if (this.hitFlash > 0) {
ctx.globalAlpha = 0.5 + Math.sin(this.hitFlash * 60) * 0.5;
ctx.fillStyle = '#fff';
} else {
ctx.globalAlpha = 1;
const grad = ctx.createLinearGradient(this.x, this.y, this.x, this.y + this.h);
grad.addColorStop(0, this.color);
grad.addColorStop(1, this.shadeColor(this.color, -40));
ctx.fillStyle = grad;
}
this.roundRect(ctx, this.x, this.y, this.w, this.h, 3);
ctx.fill();
// Tier indicator
ctx.fillStyle = 'rgba(0,0,0,0.3)';
ctx.font = 'bold 11px Courier New';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(this.health, this.x + this.w/2, this.y + this.h/2 + 1);
ctx.restore();
}
shadeColor(color, percent) {
const num = parseInt(color.slice(1), 16);
const amt = Math.round(2.55 * percent);
const R = Math.max(0, Math.min(255, (num >> 16) + amt));
const G = Math.max(0, Math.min(255, ((num >> 8) & 0x00FF) + amt));
const B = Math.max(0, Math.min(255, (num & 0x0000FF) + amt));
return '#' + (0x1000000 + R * 0x10000 + G * 0x100 + B).toString(16).slice(1);
}
roundRect(ctx, x, y, w, h, r) {
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();
}
}
class Powerup {
constructor(x, y, type) {
this.x = x; this.y = y; this.type = type;
this.w = POWERUP_SIZE; this.h = POWERUP_SIZE;
this.vy = POWERUP_FALL_SPEED;
this.alive = true;
this.rotation = 0;
this.data = POWERUPS[type];
this.bob = Math.random() * Math.PI * 2;
}
update(dt) {
this.y += this.vy * dt * 60;
this.rotation += dt * 2;
this.bob += dt * 3;
if (this.y > CANVAS_H + 50) this.alive = false;
}
draw(ctx) {
if (!this.alive) return;
ctx.save();
ctx.translate(this.x, this.y + Math.sin(this.bob) * 3);
ctx.rotate(this.rotation);
// Background
ctx.fillStyle = this.data.color;
ctx.shadowColor = this.data.color;
ctx.shadowBlur = 15;
ctx.beginPath();
for (let i = 0; i < 4; i++) {
const angle = (i * Math.PI / 2) + Math.PI / 4;
const r = i % 2 === 0 ? 14 : 8;
ctx.lineTo(Math.cos(angle) * r, Math.sin(angle) * r);
}
ctx.closePath();
ctx.fill();
ctx.shadowBlur = 0;
// Symbol
ctx.fillStyle = '#0a0a12';
ctx.font = 'bold 16px Courier New';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(this.data.char, 0, 1);
ctx.restore();
}
checkPaddle(paddle) {
return this.x > paddle.x && this.x < paddle.x + paddle.w &&
this.y + this.h/2 > paddle.y && this.y - this.h/2 < paddle.y + paddle.h;
}
}
class Laser {
constructor(x, y) { this.x = x; this.y = y; this.w = 4; this.h = 20; this.alive = true; }
update(dt) { this.y -= 500 * dt; if (this.y < -this.h) this.alive = false; }
draw(ctx) {
ctx.save();
ctx.fillStyle = '#ff6b6b';
ctx.shadowColor = '#ff6b6b';
ctx.shadowBlur = 10;
ctx.fillRect(this.x - this.w/2, this.y, this.w, this.h);
ctx.restore();
}
}
// ============ LEVEL GENERATION ============
function generateLevel(level) {
const bricks = [];
const patterns = [
// Level 1: Simple rows
() => { for (let r = 0; r < 4; r++) for (let c = 0; c < BRICK_COLS; c++) bricks.push(new Brick(BRICK_OFFSET_X + c*(BRICK_W+BRICK_GAP), BRICK_OFFSET_Y + r*(BRICK_H+BRICK_GAP), 1)); },
// Level 2: Pyramid
() => { for (let r = 0; r < 5; r++) { const start = Math.floor(r/2); const count = BRICK_COLS - r; for (let c = 0; c < count; c++) bricks.push(new Brick(BRICK_OFFSET_X + (start+c)*(BRICK_W+BRICK_GAP) + (BRICK_W+BRICK_GAP)/2, BRICK_OFFSET_Y + r*(BRICK_H+BRICK_GAP), r < 2 ? 1 : 2)); }},
// Level 3: Wall with gaps
() => { for (let r = 0; r < 6; r++) for (let c = 0; c < BRICK_COLS; c++) if ((r + c) % 3 !== 0) bricks.push(new Brick(BRICK_OFFSET_X + c*(BRICK_W+BRICK_GAP), BRICK_OFFSET_Y + r*(BRICK_H+BRICK_GAP), Math.min(3, r+1))); },
// Level 4: Diamond
() => { const mid = BRICK_COLS/2; for (let r = 0; r < 6; r++) { const dist = Math.abs(r - 2.5); const start = Math.floor(mid - 4 + dist); for (let c = start; c < start + 8 - dist*2; c++) if (c>=0 && c<BRICK_COLS) bricks.push(new Brick(BRICK_OFFSET_X + c*(BRICK_W+BRICK_GAP), BRICK_OFFSET_Y + r*(BRICK_H+BRICK_GAP), r < 3 ? 2 : 3)); }},
// Level 5: Checkerboard tough
() => { for (let r = 0; r < 6; r++) for (let c = 0; c < BRICK_COLS; c++) if ((r+c)%2===0) bricks.push(new Brick(BRICK_OFFSET_X + c*(BRICK_W+BRICK_GAP), BRICK_OFFSET_Y + r*(BRICK_H+BRICK_GAP), 3 + (r>3?1:0))); },
// Level 6: Fortress
() => { for (let r = 0; r < 6; r++) for (let c = 0; c < BRICK_COLS; c++) { if (r < 2 || r > 4 || c < 2 || c > 7) bricks.push(new Brick(BRICK_OFFSET_X + c*(BRICK_W+BRICK_GAP), BRICK_OFFSET_Y + r*(BRICK_H+BRICK_GAP), 4)); else if ((r+c)%2) bricks.push(new Brick(BRICK_OFFSET_X + c*(BRICK_W+BRICK_GAP), BRICK_OFFSET_Y + r*(BRICK_H+BRICK_GAP), 2)); }},
// Level 7: Descending
() => { for (let r = 0; r < 7; r++) { const count = BRICK_COLS - r; for (let c = 0; c < count; c++) bricks.push(new Brick(BRICK_OFFSET_X + c*(BRICK_W+BRICK_GAP) + r*(BRICK_W+BRICK_GAP)/2, BRICK_OFFSET_Y + r*(BRICK_H+BRICK_GAP), Math.min(4, r+1))); }},
// Level 8: Chaos
() => { for (let r = 0; r < 8; r++) for (let c = 0; c < BRICK_COLS; c++) if (Math.random() < 0.7) bricks.push(new Brick(BRICK_OFFSET_X + c*(BRICK_W+BRICK_GAP), BRICK_OFFSET_Y + r*(BRICK_H+BRICK_GAP), 1 + Math.floor(Math.random()*4))); }
];
(patterns[(level-1) % patterns.length] || patterns[0])();
return bricks;
}
// ============ GAME STATE ============
const canvas = document.getElementById('game');
const ctx = canvas.getContext('2d');
const input = { left: false, right: false, mouseX: null, launch: false, pause: false };
let paddle, balls, bricks, powerups, lasers;
let score = 0, level = 1, lives = INITIAL_LIVES, combo = 0, lastBrickHit = 0;
let gameState = 'START'; // START, PLAYING, PAUSED, LEVEL_TRANSITION, GAME_OVER, WIN
let ballLaunched = false;
let lastTime = 0;
let levelTransitionTimer = 0;
const activePowerups = { WIDE: 0, SLOW: 0, LASER: 0 };
// UI Elements
const startOverlay = document.getElementById('startOverlay');
const pauseOverlay = document.getElementById('pauseOverlay');
const gameOverOverlay = document.getElementById('gameOverOverlay');
const winOverlay = document.getElementById('winOverlay');
const levelTransition = document.getElementById('levelTransition');
const levelText = document.getElementById('levelText');
const powerupIndicator = document.getElementById('powerupIndicator');
// ============ INIT ============
function initGame() {
paddle = new Paddle();
balls = [new Ball(CANVAS_W/2, PADDLE_Y - BALL_R - 5, 0, 0, true)];
bricks = generateLevel(level);
powerups = []; lasers = [];
score = 0; lives = INITIAL_LIVES; combo = 0; lastBrickHit = 0;
ballLaunched = false;
activePowerups.WIDE = 0; activePowerups.SLOW = 0; activePowerups.LASER = 0;
updateUI();
updatePowerupUI();
particles.particles = [];
}
function resetBall() {
balls = [new Ball(paddle.x + paddle.w/2, PADDLE_Y - BALL_R - 5, 0, 0, true)];
ballLaunched = false;
paddle.glow = 1;
}
function launchBall(ball) {
const angle = -Math.PI/2 + (Math.random() - 0.5) * 0.5;
const speed = BASE_BALL_SPEED;
ball.vx = Math.cos(angle) * speed;
ball.vy = Math.sin(angle) * speed;
ballLaunched = true;
}
function updateUI() {
document.getElementById('score').textContent = score.toLocaleString();
document.getElementById('level').textContent = level;
document.getElementById('lives').textContent = '●'.repeat(lives);
}
function updatePowerupUI() {
powerupIndicator.innerHTML = '';
Object.entries(POWERUPS).forEach(([key, data]) => {
const slot = document.createElement('div');
slot.className = 'powerup-slot' + (activePowerups[key] > 0 ? ' active' : '');
slot.style.color = data.color;
slot.textContent = data.char;
slot.title = data.name + (activePowerups[key] > 0 ? ` (${Math.ceil(activePowerups[key])}s)` : '');
powerupIndicator.appendChild(slot);
});
}
// ============ INPUT ============
window.addEventListener('keydown', e => {
if (e.code === 'ArrowLeft' || e.code === 'KeyA') input.left = true;
if (e.code === 'ArrowRight' || e.code === 'KeyD') input.right = true;
if (e.code === 'Space') { input.launch = true; e.preventDefault(); }
if (e.code === 'KeyP' || e.code === 'Escape') { input.pause = true; e.preventDefault(); }
});
window.addEventListener('keyup', e => {
if (e.code === 'ArrowLeft' || e.code === 'KeyA') input.left = false;
if (e.code === 'ArrowRight' || e.code === 'KeyD') input.right = false;
if (e.code === 'Space') input.launch = false;
if (e.code === 'KeyP' || e.code === 'Escape') input.pause = false;
});
canvas.addEventListener('mousemove', e => {
const rect = canvas.getBoundingClientRect();
input.mouseX = e.clientX - rect.left;
});
canvas.addEventListener('mouseleave', () => input.mouseX = null);
canvas.addEventListener('click', () => { input.launch = true; setTimeout(() => input.launch = false, 0); });
canvas.addEventListener('touchstart', e => { e.preventDefault(); input.launch = true; const rect = canvas.getBoundingClientRect(); input.mouseX = e.touches[0].clientX - rect.left; });
canvas.addEventListener('touchmove', e => { e.preventDefault(); const rect = canvas.getBoundingClientRect(); input.mouseX = e.touches[0].clientX - rect.left; });
canvas.addEventListener('touchend', () => { input.launch = false; input.mouseX = null; });
document.getElementById('startBtn').addEventListener('click', () => { audio.init(); audio.resume(); startGame(); });
document.getElementById('resumeBtn').addEventListener('click', () => { audio.resume(); resumeGame(); });
document.getElementById('restartBtn').addEventListener('click', () => { audio.resume(); restartGame(); });
document.getElementById('nextGameBtn').addEventListener('click', () => { audio.resume(); restartGame(); });
function startGame() {
initGame();
gameState = 'PLAYING';
startOverlay.classList.add('hidden');
lastTime = performance.now();
requestAnimationFrame(gameLoop);
}
function pauseGame() {
if (gameState === 'PLAYING') {
gameState = 'PAUSED';
pauseOverlay.classList.remove('hidden');
}
}
function resumeGame() {
if (gameState === 'PAUSED') {
gameState = 'PLAYING';
pauseOverlay.classList.add('hidden');
lastTime = performance.now();
requestAnimationFrame(gameLoop);
}
}
function restartGame() {
level = 1;
gameOverOverlay.classList.add('hidden');
winOverlay.classList.add('hidden');
startGame();
}
function gameOver() {
gameState = 'GAME_OVER';
document.getElementById('finalScore').textContent = score.toLocaleString();
gameOverOverlay.classList.remove('hidden');
audio.gameOver();
}
function victory() {
gameState = 'WIN';
document.getElementById('winScore').textContent = score.toLocaleString();
winOverlay.classList.remove('hidden');
}
function nextLevel() {
level++;
if (level > MAX_LEVELS) { victory(); return; }
gameState = 'LEVEL_TRANSITION';
levelTransitionTimer = 1.5;
levelText.textContent = `LEVEL ${level}`;
levelTransition.classList.add('active');
audio.levelUp();
// Reset for next level
paddle = new Paddle();
balls = [new Ball(CANVAS_W/2, PADDLE_Y - BALL_R - 5, 0, 0, true)];
bricks = generateLevel(level);
powerups = []; lasers = [];
ballLaunched = false;
combo = 0;
activePowerups.WIDE = 0; activePowerups.SLOW = 0; activePowerups.LASER = 0;
updateUI();
updatePowerupUI();
}
function spawnPowerup(x, y) {
const types = Object.keys(POWERUPS);
const type = types[Math.floor(Math.random() * types.length)];
powerups.push(new Powerup(x, y, type));
audio.powerupSpawn();
}
// ============ MAIN LOOP ============
function gameLoop(timestamp) {
if (gameState !== 'PLAYING') return;
const dt = Math.min((timestamp - lastTime) / 1000, 0.05);
lastTime = timestamp;
update(dt);
draw();
requestAnimationFrame(gameLoop);
}
function update(dt) {
// Screen shake decay
if (shakeTime > 0) { shakeTime -= dt; shakeIntensity *= 0.9; }
// Paddle
paddle.update(dt, input);
// Lasers
if (paddle.laserActive && Math.random() < 0.02) {
lasers.push(new Laser(paddle.x + 6, paddle.y));
lasers.push(new Laser(paddle.x + paddle.w - 6, paddle.y));
audio.laserFire();
}
lasers = lasers.filter(l => l.alive);
lasers.forEach(l => l.update(dt));
// Laser-Brick collision
lasers.forEach(laser => {
bricks.forEach(brick => {
if (brick.alive && laser.x > brick.x && laser.x < brick.x + brick.w &&
laser.y < brick.y + brick.h && laser.y + laser.h > brick.y) {
brick.alive = false;
laser.alive = false;
score += 25 * brick.tier;
particles.laserHit(laser.x, laser.y);
audio.brickBreak(brick.tier);
}
});
});
// Balls
let anyBallAlive = false;
balls.forEach(ball => {
if (ball.update(dt, paddle)) anyBallAlive = true;
// Brick collisions
bricks.forEach(brick => {
if (!brick.alive) return;
// AABB vs Circle
const closestX = Math.max(brick.x, Math.min(ball.x, brick.x + brick.w));
const closestY = Math.max(brick.y, Math.min(ball.y, brick.y + brick.h));
const dx = ball.x - closestX;
const dy = ball.y - closestY;
if (dx*dx + dy*dy < ball.r * ball.r) {
// Determine bounce direction
const overlapX = ball.r - Math.abs(dx);
const overlapY = ball.r - Math.abs(dy);
if (overlapX < overlapY) {
ball.vx = dx > 0 ? Math.abs(ball.vx) : -Math.abs(ball.vx);
ball.x = closestX + (dx > 0 ? ball.r : -ball.r);
} else {
ball.vy = dy > 0 ? Math.abs(ball.vy) : -Math.abs(ball.vy);
ball.y = closestY + (dy > 0 ? ball.r : -ball.r);
}
const points = brick.hit(ball, { combo });
score += points;
updateUI();
// Combo system
const now = performance.now();
if (now - lastBrickHit < 1000) combo = Math.min(combo + 1, 10);
else combo = 1;
lastBrickHit = now;
// Slow powerup affects all balls
if (activePowerups.SLOW > 0) ball.setSlow(activePowerups.SLOW * 1000);
}
});
});
// Remove dead balls (fell off bottom)
const mainBallAlive = balls.some(b => b.isMain && b.y < CANVAS_H + 50);
balls = balls.filter(b => b.y < CANVAS_H + 50);
if (!mainBallAlive && gameState === 'PLAYING') {
lives--;
updateUI();
audio.lifeLost();
addShake(10, 0.3);
particles.emit(CANVAS_W/2, CANVAS_H/2, '#ff4757', 40, [100, 400], [0.5, 1.5], [4, 12], 200);
if (lives <= 0) { gameOver(); return; }
resetBall();
}
// Powerups
powerups.forEach(p => {
p.update(dt);
if (p.checkPaddle(paddle)) {
collectPowerup(p);
p.alive = false;
}
});
powerups = powerups.filter(p => p.alive);
// Powerup timers
Object.keys(activePowerups).forEach(key => {
if (activePowerups[key] > 0) {
activePowerups[key] -= dt;
if (activePowerups[key] <= 0) {
activePowerups[key] = 0;
if (key === 'WIDE') paddle.w = paddle.baseWidth;
if (key === 'LASER') paddle.laserActive = false;
}
}
});
updatePowerupUI();
// Launch ball
if (input.launch && !ballLaunched) {
launchBall(balls[0]);
input.launch = false;
}
// Check level complete
const bricksLeft = bricks.filter(b => b.alive).length;
if (bricksLeft === 0) { nextLevel(); return; }
// Pause check
if (input.pause) { pauseGame(); input.pause = false; }
}
function collectPowerup(p) {
audio.powerupCollect(p.type);
particles.powerupCollect(p.x, p.y, p.data.color);
addShake(5, 0.15);
switch(p.type) {
case 'WIDE': activePowerups.WIDE = POWERUPS.WIDE.duration / 1000; paddle.activatePowerup('WIDE'); break;
case 'MULTI':
const mainBall = balls.find(b => b.isMain);
if (mainBall) {
for (let i = 0; i < 2; i++) {
const angle = Math.atan2(mainBall.vy, mainBall.vx) + (i === 0 ? -0.5 : 0.5);
const speed = Math.hypot(mainBall.vx, mainBall.vy);
balls.push(new Ball(mainBall.x, mainBall.y, Math.cos(angle)*speed, Math.sin(angle)*speed, false));
}
}
break;
case 'SLOW': activePowerups.SLOW = POWERUPS.SLOW.duration / 1000; balls.forEach(b => b.setSlow(POWERUPS.SLOW.duration)); break;
case 'LIFE': if (lives < 5) { lives++; updateUI(); } break;
case 'LASER': activePowerups.LASER = POWERUPS.LASER.duration / 1000; paddle.activatePowerup('LASER'); break;
case 'SCORE': score += 500; updateUI(); break;
}
}
function draw() {
// Clear with trails
ctx.fillStyle = 'rgba(10, 10, 18, 0.3)';
ctx.fillRect(0, 0, CANVAS_W, CANVAS_H);
// Screen shake
ctx.save();
if (shakeTime > 0) {
ctx.translate(
(Math.random() - 0.5) * shakeIntensity * 2,
(Math.random() - 0.5) * shakeIntensity * 2
);
}
// Background grid
drawBackground();
// Bricks
bricks.forEach(b => b.draw(ctx));
// Powerups
powerups.forEach(p => p.draw(ctx));
// Lasers
lasers.forEach(l => l.draw(ctx));
// Particles
particles.draw(ctx);
// Paddle
paddle.draw(ctx);
// Balls
balls.forEach(b => b.draw(ctx));
ctx.restore();
// Combo display
if (combo > 1) {
ctx.save();
ctx.font = 'bold 24px Courier New';
ctx.fillStyle = '#ffd700';
ctx.textAlign = 'center';
ctx.shadowColor = '#ffd700';
ctx.shadowBlur = 10;
ctx.fillText(`COMBO x${combo}`, CANVAS_W/2, 40);
ctx.restore();
}
}
function drawBackground() {
// Subtle grid
ctx.strokeStyle = 'rgba(0, 255, 200, 0.03)';
ctx.lineWidth = 1;
for (let x = 0; x <= CANVAS_W; x += 40) {
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, CANVAS_H); ctx.stroke();
}
for (let y = 0; y <= CANVAS_H; y += 40) {
ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(CANVAS_W, y); ctx.stroke();
}
// Top accent line
ctx.strokeStyle = 'rgba(0, 255, 200, 0.2)';
ctx.lineWidth = 2;
ctx.beginPath(); ctx.moveTo(0, 40); ctx.lineTo(CANVAS_W, 40); ctx.stroke();
}
// Level transition animation
function updateLevelTransition(dt) {
levelTransitionTimer -= dt;
if (levelTransitionTimer <= 0) {
levelTransition.classList.remove('active');
gameState = 'PLAYING';
lastTime = performance.now();
requestAnimationFrame(gameLoop);
}
}
// Master loop to handle non-playing states
function masterLoop(timestamp) {
const dt = Math.min((timestamp - lastTime) / 1000, 0.05);
lastTime = timestamp;
if (gameState === 'LEVEL_TRANSITION') {
updateLevelTransition(dt);
} else if (gameState === 'PLAYING') {
// Handled by gameLoop
return;
}
// Keep drawing background in menus
ctx.fillStyle = '#0a0a12';
ctx.fillRect(0, 0, CANVAS_W, CANVAS_H);
drawBackground();
requestAnimationFrame(masterLoop);
}
// Start master loop
requestAnimationFrame(masterLoop);
// Handle visibility change
document.addEventListener('visibilitychange', () => {
if (document.hidden && gameState === 'PLAYING') pauseGame();
});
// Prevent context menu on canvas
canvas.addEventListener('contextmenu', e => e.preventDefault());
</script>
</body>
</html>

