Run details
- Model
- moonshotai/kimi-k3
- Route
- OpenRouter API
- Served by
- Sail Research
- Effort
- max (OpenRouter default)
- Limits
- 60 min · 277,777 output tokens ($3.00 cap at $15.90/M)
- Date
- 24 Oct 2026
- Time
- 4 min 25 s
- Size
- 25 kB
- Tokens
- 162 in, 30,082 out (20,674 thinking)
- List price
- $0.48 at today's price ($0.192 in / $15.90 out per M)
- Paid
- $0.17
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
25 kB 710 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>
*{box-sizing:border-box}
html,body{height:100%;margin:0;overflow:hidden;background:#04050c}
body{display:flex;align-items:center;justify-content:center;
font-family:system-ui,'Segoe UI',Roboto,sans-serif;
background:radial-gradient(1200px 800px at 50% 18%, #0b0f22 0%, #04050c 62%)}
canvas{border-radius:10px;touch-action:none;user-select:none;-webkit-user-select:none;
box-shadow:0 0 0 1px rgba(140,150,255,.14),0 0 80px rgba(96,80,255,.20),0 30px 80px rgba(0,0,0,.6)}
</style>
</head>
<body>
<canvas id="game" width="800" height="600"></canvas>
<script>
(() => {
'use strict';
// ================= setup =================
const W=800, H=600, WALL_TOP=56;
const canvas=document.getElementById('game');
const ctx=canvas.getContext('2d');
const clamp=(v,a,b)=>v<a?a:(v>b?b:v);
const rand=(a,b)=>a+Math.random()*(b-a);
const lerp=(a,b,t)=>a+(b-a)*t;
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();
}
// ================= audio (100% synthesized) =================
let AC=null, muted=false;
function ac(){
if(!AC){try{AC=new (window.AudioContext||window.webkitAudioContext)();}catch(e){}}
if(AC&&AC.state==='suspended')AC.resume();
return AC;
}
function tone(f0,f1,dur,type,vol,delay){
if(muted)return;const a=ac();if(!a)return;
try{
const t=a.currentTime+(delay||0);
const o=a.createOscillator(),g=a.createGain();
o.type=type;o.frequency.setValueAtTime(Math.max(f0,1),t);
if(f1&&f1!==f0)o.frequency.exponentialRampToValueAtTime(Math.max(f1,1),t+dur);
g.gain.setValueAtTime(vol,t);
g.gain.exponentialRampToValueAtTime(0.0001,t+dur);
o.connect(g);g.connect(a.destination);
o.start(t);o.stop(t+dur+0.05);
}catch(e){}
}
function noiseHit(dur,vol,freq){
if(muted)return;const a=ac();if(!a)return;
try{
const t=a.currentTime,len=Math.max(1,(a.sampleRate*dur)|0);
const buf=a.createBuffer(1,len,a.sampleRate),d=buf.getChannelData(0);
for(let i=0;i<len;i++)d[i]=(Math.random()*2-1)*(1-i/len);
const s=a.createBufferSource();s.buffer=buf;
const f=a.createBiquadFilter();f.type='bandpass';f.frequency.value=freq||900;f.Q.value=0.8;
const g=a.createGain();g.gain.setValueAtTime(vol,t);g.gain.exponentialRampToValueAtTime(0.0001,t+dur);
s.connect(f);f.connect(g);g.connect(a.destination);s.start(t);
}catch(e){}
}
const sfx={
paddle(){tone(210,330,0.09,'square',0.22);},
wall(){tone(300,260,0.04,'square',0.10);},
brick(hp){noiseHit(0.08,0.22,700+hp*120);tone(480-hp*40,170,0.12,'triangle',0.2);},
hard(){tone(130,80,0.09,'square',0.18);noiseHit(0.05,0.12,300);},
power(){tone(440,880,0.12,'sine',0.22);tone(660,1320,0.16,'sine',0.18,0.08);},
lose(){tone(300,55,0.55,'sawtooth',0.28);},
launch(){tone(280,560,0.1,'sine',0.18);},
clear(){[523,659,784,1047].forEach((f,i)=>tone(f,f,0.16,'triangle',0.22,i*0.09));},
over(){[392,311,262,175].forEach((f,i)=>tone(f,f*0.7,0.28,'sawtooth',0.2,i*0.17));},
win(){[523,659,784,1047,1319,1568].forEach((f,i)=>tone(f,f,0.22,'triangle',0.22,i*0.11));}
};
// ================= data =================
const LEVELS=[
{name:'WARM UP',map:[
'111111111111',
'111111111111',
'222222222222',
'222222222222']},
{name:'CHECKERS',map:[
'1.1.1.1.1.1.',
'.2.2.2.2.2.2',
'2.2.2.2.2.2.',
'.1.1.1.1.1.1',
'3.3.3.3.3.3.']},
{name:'PYRAMID',map:[
'.....22.....',
'....2222....',
'...221122...',
'..22111122..',
'.2211111122.',
'221111111122']},
{name:'FORTRESS',map:[
'XXXXXXXXXXXX',
'X..........X',
'X.33333333.X',
'X.3......3.X',
'X.3.2222.3.X',
'X.3.2112.3.X',
'X.3.2112.3.X',
'X.3.2222.3.X',
'X.3......3.X',
'X.33333333.X']},
{name:'DIAMOND',map:[
'.....33.....',
'....3223....',
'...321123...',
'..32111123..',
'.3211111123.',
'321111111123',
'.3211111123.',
'..32111123..',
'...321123...',
'....3223....',
'.....33.....']},
{name:'THE GAUNTLET',map:[
'X4X4X4X4X4X4',
'444444444444',
'3.3.3.3.3.3.',
'333333333333',
'..2......2..',
'.222....222.',
'222222222222',
'1.1.1..1.1.1']}
];
const BRICK_STYLE={
1:{c:'#3ee6c4',dark:'#177e68'},
2:{c:'#ffd23f',dark:'#b58a14'},
3:{c:'#ff9f43',dark:'#b35e12'},
4:{c:'#ff5d73',dark:'#b02840'},
X:{c:'#98a2b8',dark:'#59627a'}
};
const POW_STYLE={
'E':{c:'#b78bff',name:'WIDE'},
'M':{c:'#3ee6c4',name:'MULTIBALL'},
'S':{c:'#ffd23f',name:'SLOW-MO'},
'+':{c:'#ff7d92',name:'+1 LIFE'}
};
const CONF=['#ff5d73','#ffd23f','#3ee6c4','#b78bff','#7df9ff'];
// ================= state =================
const state={mode:'menu',score:0,best:0,lives:3,level:0,combo:0,
shake:0,timeScale:1,hitStop:0,slowmo:0,clearT:0,t:0,newBest:false};
try{state.best=+localStorage.getItem('nb_best')||0;}catch(e){}
const banner={a:'',b:'',t:0,dur:2.2};
function setBanner(a,b){banner.a=a;banner.b=b;banner.t=banner.dur;}
const paddle={x:W/2,y:H-42,w:116,h:14,baseW:116,speed:660,vx:0,squash:0,glow:0,expandT:0};
let balls=[],bricks=[],particles=[],powerups=[],floaters=[],stars=[];
let slowBallT=0, mouseX=null;
const keys={};
function initStars(){
stars=[];
for(let i=0;i<70;i++)stars.push({x:Math.random()*W,y:Math.random()*H,z:rand(0.4,1.4),
c:Math.random()<0.8?'#aab3ff':'#ffe9b0'});
}
function buildLevel(idx){
bricks=[];
const map=LEVELS[idx].map, cols=12, gap=5, margin=24, top=86;
const bw=(W-margin*2-gap*(cols-1))/cols, bh=24;
map.forEach((row,r)=>{[...row].forEach((ch,c)=>{
if(ch==='.')return;
const hp=ch==='X'?Infinity:parseInt(ch,10);
bricks.push({x:margin+c*(bw+gap),y:top+r*(bh+gap),w:bw,h:bh,hp,maxHp:hp,ch,alive:true,flash:0,wob:0});
});});
}
function baseSpeed(){return 380+state.level*28;}
function resetBall(){
balls=[{x:paddle.x,y:paddle.y-10,r:8,vx:0,vy:0,speed:baseSpeed(),attached:true,trail:[]}];
}
function saveBest(){
if(state.score>state.best){state.best=state.score;state.newBest=true;
try{localStorage.setItem('nb_best',state.best);}catch(e){}}
}
function startGame(){
saveBest();
state.score=0;state.lives=3;state.level=0;state.combo=0;state.newBest=false;
powerups.length=0;particles.length=0;floaters.length=0;slowBallT=0;
paddle.x=W/2;paddle.w=paddle.baseW;paddle.expandT=0;
buildLevel(0);resetBall();
setBanner('LEVEL 1',LEVELS[0].name);
state.mode='playing';
sfx.launch();
}
function nextLevel(){
state.level++;
buildLevel(state.level);
powerups.length=0;floaters.length=0;slowBallT=0;
paddle.w=paddle.baseW;paddle.expandT=0;
resetBall();
setBanner('LEVEL '+(state.level+1),LEVELS[state.level].name);
state.mode='playing';
}
function launch(){
if(state.mode!=='playing')return;
let any=false;
for(const b of balls)if(b.attached){
b.attached=false;any=true;
const a=rand(-0.45,0.45);
b.vx=Math.sin(a)*b.speed;b.vy=-Math.cos(a)*b.speed;
}
if(any)sfx.launch();
}
function addFloater(x,y,txt,color){floaters.push({x,y,txt,color,t:0,life:1.0});}
function pushParticle(p){particles.push(p);if(particles.length>500)particles.splice(0,particles.length-500);}
function spawnExplosion(br,color){
const cx=br.x+br.w/2,cy=br.y+br.h/2;
for(let i=0;i<16;i++)pushParticle({x:cx+rand(-br.w/2,br.w/2)*0.8,y:cy+rand(-br.h/2,br.h/2),
vx:rand(-230,230),vy:rand(-280,90),g:620,life:rand(0.4,0.85),t:0,size:rand(2,5),color,rot:rand(0,3),vr:rand(-9,9)});
}
function spawnSparks(x,y,color,n){
for(let i=0;i<n;i++)pushParticle({x,y,vx:rand(-190,190),vy:rand(-230,60),g:660,
life:rand(0.22,0.5),t:0,size:rand(1.5,3),color,rot:rand(0,3),vr:rand(-10,10)});
}
function confetti(){
pushParticle({x:rand(0,W),y:-6,vx:rand(-50,50),vy:rand(60,190),g:70,
life:rand(1.5,2.6),t:0,size:rand(3,6),color:CONF[(Math.random()*CONF.length)|0],rot:rand(0,3),vr:rand(-6,6)});
}
function maybeDropPowerup(br){
if(Math.random()>0.18)return;
const r=Math.random();
const type=r<0.32?'E':r<0.62?'M':r<0.9?'S':'+';
powerups.push({x:br.x+br.w/2,y:br.y+br.h/2,vy:150,type,t:0});
}
function applyPowerup(p){
sfx.power();state.shake=Math.max(state.shake,2);
spawnSparks(p.x,p.y,POW_STYLE[p.type].c,10);
if(p.type==='E'){paddle.w=paddle.baseW*1.55;paddle.expandT=12;addFloater(paddle.x,paddle.y-26,'WIDE!',POW_STYLE.E.c);}
else if(p.type==='M'){
for(const b of balls.slice(0,3)){
if(b.attached)continue;
for(const off of[-0.5,0.5]){
if(balls.length>=6)break;
const a=Math.atan2(b.vy,b.vx)+off;
balls.push({x:b.x,y:b.y,r:b.r,vx:Math.cos(a)*b.speed,vy:Math.sin(a)*b.speed,speed:b.speed,attached:false,trail:[]});
}
}
addFloater(paddle.x,paddle.y-26,'MULTIBALL!',POW_STYLE.M.c);
}
else if(p.type==='S'){balls.forEach(b=>b.speed*=0.7);slowBallT=8;addFloater(paddle.x,paddle.y-26,'SLOW-MO',POW_STYLE.S.c);}
else{state.lives=Math.min(state.lives+1,5);addFloater(paddle.x,paddle.y-26,'+1 LIFE',POW_STYLE['+'].c);}
}
function hitBrick(br,b){
if(br.ch==='X'){
br.flash=0.12;state.shake=Math.max(state.shake,2);
spawnSparks(b.x,b.y,'#aab4c8',6);sfx.hard();return;
}
br.hp--;br.flash=0.15;br.wob=1;
if(br.hp<=0){
br.alive=false;
state.combo++;
const mult=Math.min(state.combo,8);
const pts=br.maxHp*50*mult;
state.score+=pts;
addFloater(br.x+br.w/2,br.y+br.h/2,'+'+pts+(mult>1?' x'+mult:''),BRICK_STYLE[br.maxHp].c);
spawnExplosion(br,BRICK_STYLE[br.maxHp].c);
state.shake=Math.max(state.shake,3.5);
state.hitStop=Math.max(state.hitStop,0.028);
b.speed=Math.min(b.speed+3,780);
const m=Math.hypot(b.vx,b.vy)||1;b.vx=b.vx/m*b.speed;b.vy=b.vy/m*b.speed;
sfx.brick(br.maxHp);
maybeDropPowerup(br);
checkClear();
}else{
spawnSparks(b.x,b.y,BRICK_STYLE[br.hp].c,8);
state.shake=Math.max(state.shake,1.5);
sfx.brick(br.hp);
}
}
function checkClear(){
if(state.mode!=='playing')return;
if(bricks.some(br=>br.alive&&br.ch!=='X'))return;
const bonus=250*(state.level+1);
state.score+=bonus;
state.shake=6;
if(state.level>=LEVELS.length-1){
state.mode='win';saveBest();sfx.win();
}else{
setBanner('LEVEL CLEAR!','BONUS +'+bonus);
state.mode='clear';state.clearT=2.2;sfx.clear();
}
}
function loseLife(){
state.lives--;state.combo=0;
powerups.length=0;slowBallT=0;
state.shake=11;state.slowmo=0.75;
sfx.lose();
if(state.lives<=0){state.mode='over';saveBest();sfx.over();}
else{paddle.w=paddle.baseW;paddle.expandT=0;resetBall();}
}
// ================= collisions =================
function collideWalls(b){
if(b.x<b.r){b.x=b.r;b.vx=Math.abs(b.vx);sfx.wall();}
else if(b.x>W-b.r){b.x=W-b.r;b.vx=-Math.abs(b.vx);sfx.wall();}
if(b.y<WALL_TOP+b.r){b.y=WALL_TOP+b.r;b.vy=Math.abs(b.vy);sfx.wall();}
if(Math.abs(b.vy)<24){b.vy=(b.y<WALL_TOP+40||b.vy>0)?60:-60;}
}
function collidePaddle(b){
if(b.vy<=0)return;
const p=paddle;
if(b.y+b.r<p.y||b.y-b.r>p.y+p.h)return;
if(b.x+b.r<p.x-p.w/2||b.x-b.r>p.x+p.w/2)return;
const rel=clamp((b.x-p.x)/(p.w/2),-1,1);
const ang=rel*1.05;
const spd=b.speed;
b.vx=Math.sin(ang)*spd+p.vx*0.12;
b.vy=-Math.cos(ang)*spd;
const m=Math.hypot(b.vx,b.vy)||1;b.vx=b.vx/m*spd;b.vy=b.vy/m*spd;
if(b.vy>-spd*0.4)b.vy=-spd*0.4;
b.y=p.y-b.r-0.5;
p.squash=1;p.glow=1;
if(state.combo>=4)addFloater(p.x,p.y-24,'x'+Math.min(state.combo,8)+' banked','#9aa3c7');
state.combo=0;
spawnSparks(b.x,p.y,'#a78bff',5);
sfx.paddle();
}
function collideBricks(b){
for(const br of bricks){
if(!br.alive)continue;
const nx=clamp(b.x,br.x,br.x+br.w);
const ny=clamp(b.y,br.y,br.y+br.h);
const dx=b.x-nx,dy=b.y-ny;
if(dx*dx+dy*dy>b.r*b.r)continue;
if(dx===0&&dy===0)b.vy*=-1;
else if(Math.abs(dx)>Math.abs(dy))b.vx=dx>0?Math.abs(b.vx):-Math.abs(b.vx);
else b.vy=dy>0?Math.abs(b.vy):-Math.abs(b.vy);
hitBrick(br,b);
break;
}
}
// ================= update =================
function update(dt,raw){
state.t+=raw;
for(const s of stars){s.y+=s.z*18*dt;if(s.y>H+2){s.y=-2;s.x=Math.random()*W;}}
state.shake=Math.max(0,state.shake-raw*36);
if(banner.t>0)banner.t-=raw;
paddle.glow=Math.max(0,paddle.glow-dt*3);
paddle.squash=Math.max(0,paddle.squash-dt*5);
for(const br of bricks){if(br.flash>0)br.flash-=dt;if(br.wob>0)br.wob=Math.max(0,br.wob-dt*4);}
for(let i=particles.length-1;i>=0;i--){const p=particles[i];p.t+=dt;
if(p.t>=p.life){particles.splice(i,1);continue;}
p.x+=p.vx*dt;p.y+=p.vy*dt;p.vy+=p.g*dt;p.rot+=p.vr*dt;}
for(let i=floaters.length-1;i>=0;i--){const f=floaters[i];f.t+=dt;f.y-=46*dt;
if(f.t>=f.life)floaters.splice(i,1);}
if(state.mode==='win'&&Math.random()<0.3)confetti();
if(state.mode==='clear'){state.clearT-=raw;if(state.clearT<=0)nextLevel();}
const active=state.mode==='playing'||state.mode==='clear';
if(!active)return;
if(paddle.expandT>0){paddle.expandT-=dt;if(paddle.expandT<=0)paddle.w=paddle.baseW;}
if(slowBallT>0){slowBallT-=dt;if(slowBallT<=0)balls.forEach(b=>b.speed=Math.min(b.speed/0.7,780));}
let dir=0;
if(keys.ArrowLeft||keys.KeyA)dir--;
if(keys.ArrowRight||keys.KeyD)dir++;
const oldX=paddle.x;
if(dir!==0){paddle.x+=dir*paddle.speed*dt;mouseX=null;}
else if(mouseX!=null)paddle.x+=(mouseX-paddle.x)*Math.min(1,dt*22);
paddle.x=clamp(paddle.x,paddle.w/2+6,W-paddle.w/2-6);
paddle.vx=dt>0?(paddle.x-oldX)/dt:0;
for(let i=powerups.length-1;i>=0;i--){
const p=powerups[i];p.t+=dt;p.y+=p.vy*dt;
if(p.y>H+24){powerups.splice(i,1);continue;}
if(p.y+12>paddle.y&&p.y-12<paddle.y+paddle.h&&Math.abs(p.x-paddle.x)<paddle.w/2+12){
applyPowerup(p);powerups.splice(i,1);
}
}
for(const b of balls){
if(b.attached){b.x=paddle.x;b.y=paddle.y-b.r-2;continue;}
const steps=Math.max(1,Math.ceil(b.speed*dt/(b.r*0.8)));
const sdt=dt/steps;
for(let s=0;s<steps;s++){
b.x+=b.vx*sdt;b.y+=b.vy*sdt;
collideWalls(b);collidePaddle(b);collideBricks(b);
}
b.trail.push({x:b.x,y:b.y});
if(b.trail.length>12)b.trail.shift();
}
balls=balls.filter(b=>b.y<H+40);
if(balls.length===0&&state.mode==='playing')loseLife();
}
// ================= render =================
function drawBricks(){
for(const br of bricks){
if(!br.alive)continue;
const st=br.ch==='X'?BRICK_STYLE.X:BRICK_STYLE[br.hp];
const s=1+br.wob*0.1;
ctx.save();
ctx.translate(br.x+br.w/2,br.y+br.h/2);
ctx.scale(s,s);
const x=-br.w/2,y=-br.h/2;
const g=ctx.createLinearGradient(0,y,0,y+br.h);
g.addColorStop(0,st.c);g.addColorStop(1,st.dark);
roundRect(x,y,br.w,br.h,5);ctx.fillStyle=g;ctx.fill();
ctx.fillStyle='rgba(255,255,255,0.28)';
roundRect(x+3,y+2,br.w-6,4,2);ctx.fill();
if(br.ch==='X'){
ctx.fillStyle='rgba(0,0,0,0.25)';
roundRect(x+5,y+6,br.w-10,br.h-12,3);ctx.fill();
}
if(br.flash>0){
ctx.globalAlpha=clamp(br.flash/0.15,0,1)*0.8;
roundRect(x,y,br.w,br.h,5);ctx.fillStyle='#fff';ctx.fill();
}
ctx.restore();
}
}
function drawPaddle(){
const p=paddle;
ctx.save();
ctx.translate(p.x,p.y+p.h/2);
ctx.rotate(clamp(p.vx*0.00012,-0.1,0.1));
ctx.scale(1+p.squash*0.18,1-p.squash*0.3);
const g=ctx.createLinearGradient(0,-p.h/2,0,p.h/2);
g.addColorStop(0,'#a78bff');g.addColorStop(1,'#5a3ee0');
ctx.shadowColor='rgba(140,110,255,'+(0.5+p.glow*0.5)+')';
ctx.shadowBlur=18+p.glow*24;
roundRect(-p.w/2,-p.h/2,p.w,p.h,7);ctx.fillStyle=g;ctx.fill();
ctx.shadowBlur=0;
ctx.fillStyle='rgba(255,255,255,0.35)';
roundRect(-p.w/2+4,-p.h/2+2,p.w-8,3,2);ctx.fill();
ctx.restore();
}
function drawBalls(){
for(const b of balls){
const n=b.trail.length;
for(let i=0;i<n;i++){
const t=b.trail[i],k=(i+1)/n;
ctx.globalAlpha=k*0.20;ctx.fillStyle='#7df9ff';
ctx.beginPath();ctx.arc(t.x,t.y,b.r*k,0,7);ctx.fill();
}
ctx.globalAlpha=1;
ctx.save();
ctx.shadowColor='rgba(120,240,255,0.9)';
ctx.shadowBlur=16+4*Math.sin(state.t*6);
const rg=ctx.createRadialGradient(b.x-2,b.y-2,1,b.x,b.y,b.r);
rg.addColorStop(0,'#ffffff');rg.addColorStop(1,'#7df9ff');
ctx.fillStyle=rg;
ctx.beginPath();ctx.arc(b.x,b.y,b.r,0,7);ctx.fill();
ctx.restore();
}
}
function drawPowerups(){
for(const p of powerups){
const st=POW_STYLE[p.type];
const wob=Math.sin(p.t*6)*1.5;
ctx.save();
ctx.translate(p.x,p.y);
ctx.shadowColor=st.c;ctx.shadowBlur=14;
ctx.fillStyle='#0d1024';ctx.strokeStyle=st.c;ctx.lineWidth=2;
ctx.beginPath();ctx.arc(0,0,12+wob*0.3,0,7);ctx.fill();ctx.stroke();
ctx.shadowBlur=0;
ctx.fillStyle=st.c;ctx.font='bold 13px system-ui,sans-serif';
ctx.textAlign='center';ctx.textBaseline='middle';
ctx.fillText(p.type,0,1);
ctx.restore();
}
}
function drawParticles(){
ctx.save();
ctx.globalCompositeOperation='lighter';
for(const p of particles){
const k=1-p.t/p.life;
ctx.save();
ctx.translate(p.x,p.y);ctx.rotate(p.rot);
ctx.globalAlpha=k;ctx.fillStyle=p.color;
ctx.fillRect(-p.size/2,-p.size/2,p.size,p.size);
ctx.restore();
}
ctx.restore();
}
function drawFloaters(){
for(const f of floaters){
const k=1-f.t/f.life;
const pop=f.t<0.12?f.t/0.12:1;
ctx.save();
ctx.globalAlpha=Math.min(1,k*1.7);
ctx.font='bold '+(15+4*pop)+'px system-ui,sans-serif';
ctx.textAlign='center';ctx.textBaseline='middle';
ctx.shadowColor=f.color;ctx.shadowBlur=8;
ctx.fillStyle=f.color;
ctx.fillText(f.txt,f.x,f.y);
ctx.restore();
}
}
function drawHeart(x,y,s,color){
ctx.save();ctx.translate(x,y);ctx.scale(s,s);
ctx.beginPath();
ctx.moveTo(0,4);
ctx.bezierCurveTo(-7,-3,-3,-9,0,-4);
ctx.bezierCurveTo(3,-9,7,-3,0,4);
ctx.fillStyle=color;ctx.shadowColor=color;ctx.shadowBlur=8;
ctx.fill();ctx.restore();
}
function drawHUD(){
ctx.save();
ctx.textBaseline='middle';ctx.textAlign='left';
ctx.fillStyle='rgba(160,170,210,0.85)';ctx.font='600 11px system-ui,sans-serif';
ctx.fillText('SCORE',18,16);
ctx.fillStyle='#fff';ctx.font='bold 20px system-ui,sans-serif';
ctx.fillText(String(state.score).padStart(6,'0'),18,37);
ctx.textAlign='center';
ctx.fillStyle='rgba(160,170,210,0.85)';ctx.font='600 11px system-ui,sans-serif';
ctx.fillText('LEVEL '+(state.level+1)+' / '+LEVELS.length,W/2,16);
ctx.fillStyle='#fff';ctx.font='bold 15px system-ui,sans-serif';
ctx.fillText(LEVELS[state.level].name,W/2,35);
if(state.combo>=2){
ctx.fillStyle='#ffd23f';ctx.font='bold 13px system-ui,sans-serif';
ctx.shadowColor='#ffd23f';ctx.shadowBlur=8;
ctx.fillText('COMBO x'+Math.min(state.combo,8),W/2,51);
ctx.shadowBlur=0;
}
ctx.textAlign='right';
ctx.fillStyle='rgba(160,170,210,0.85)';ctx.font='600 11px system-ui,sans-serif';
ctx.fillText('BEST '+String(Math.max(state.best,state.score)).padStart(6,'0'),W-18,16);
for(let i=0;i<state.lives;i++)drawHeart(W-26-i*24,36,1.5,'#ff5d73');
ctx.restore();
}
function drawBanner(){
if(banner.t<=0)return;
const t=banner.t,d=banner.dur;
const a=clamp(t/0.45,0,1)*clamp((d-t)/0.18,0,1);
const sc=t>d-0.18?lerp(1,1.35,(t-(d-0.18))/0.18):1;
ctx.save();
ctx.globalAlpha=a;
ctx.translate(W/2,H*0.40);ctx.scale(sc,sc);
ctx.textAlign='center';ctx.textBaseline='middle';
ctx.shadowColor='rgba(140,110,255,0.9)';ctx.shadowBlur=26;
ctx.fillStyle='#fff';ctx.font='bold 46px system-ui,sans-serif';
ctx.fillText(banner.a,0,0);
ctx.shadowBlur=0;
ctx.fillStyle='#9aa3c7';ctx.font='600 18px system-ui,sans-serif';
ctx.fillText(banner.b,0,38);
ctx.restore();
}
function dim(a){ctx.fillStyle='rgba(4,6,14,'+a+')';ctx.fillRect(0,0,W,H);}
function center(txt,y,size,color,glow,weight){
ctx.save();
ctx.textAlign='center';ctx.textBaseline='middle';
ctx.font=(weight||'bold')+' '+size+'px system-ui,sans-serif';
if(glow){ctx.shadowColor=glow;ctx.shadowBlur=22;}
ctx.fillStyle=color;ctx.fillText(txt,W/2,y);
ctx.restore();
}
function drawOverlays(){
const blink=0.55+0.45*Math.sin(state.t*5);
if(state.mode==='menu'){
dim(0.62);
center('NEON',H*0.24,64,'#7df9ff','rgba(80,220,255,0.9)');
center('BREAKOUT',H*0.24+58,64,'#b78bff','rgba(150,110,255,0.9)');
center('six levels of brick-smashing mayhem',H*0.24+104,16,'#9aa3c7',null,'600');
const entries=Object.keys(POW_STYLE);
entries.forEach((k,i)=>{
const x=W/2-180+i*120,y=H*0.55,st=POW_STYLE[k];
ctx.save();
ctx.shadowColor=st.c;ctx.shadowBlur=10;
ctx.fillStyle='#0d1024';ctx.strokeStyle=st.c;ctx.lineWidth=2;
ctx.beginPath();ctx.arc(x,y,11,0,7);ctx.fill();ctx.stroke();
ctx.shadowBlur=0;
ctx.fillStyle=st.c;ctx.font='bold 12px system-ui,sans-serif';
ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(k,x,1);
ctx.fillStyle='#9aa3c7';ctx.font='600 11px system-ui,sans-serif';
ctx.fillText(st.name,x,y+24);
ctx.restore();
});
center('move: MOUSE or ← → / A D launch: CLICK or SPACE',H*0.66,15,'#c9d1f0',null,'600');
center('P pause · M sound '+(muted?'(off)':'(on)'),H*0.70,13,'#7a84a8',null,'600');
ctx.save();ctx.globalAlpha=blink;
center('CLICK or press SPACE to start',H*0.80,20,'#ffd23f','rgba(255,210,63,0.8)');
ctx.restore();
if(state.best>0)center('BEST '+String(state.best).padStart(6,'0'),H*0.88,14,'#7a84a8',null,'600');
}
else if(state.mode==='paused'){
dim(0.6);
center('PAUSED',H*0.42,48,'#fff','rgba(140,110,255,0.9)');
center('press P or ESC to resume',H*0.42+44,16,'#9aa3c7',null,'600');
}
else if(state.mode==='over'){
dim(0.7);
center('GAME OVER',H*0.34,56,'#ff5d73','rgba(255,93,115,0.9)');
center('SCORE '+String(state.score).padStart(6,'0'),H*0.34+58,22,'#fff');
if(state.newBest)center('★ NEW BEST! ★',H*0.34+92,20,'#ffd23f','rgba(255,210,63,0.8)');
else center('BEST '+String(state.best).padStart(6,'0'),H*0.34+92,16,'#9aa3c7',null,'600');
ctx.save();ctx.globalAlpha=blink;
center('CLICK or press SPACE to retry',H*0.34+140,18,'#7df9ff','rgba(80,220,255,0.7)');
ctx.restore();
}
else if(state.mode==='win'){
dim(0.55);
const hue=(state.t*90)%360;
center('YOU WIN!',H*0.34,58,'hsl('+hue+',90%,70%)','hsl('+hue+',90%,60%)');
center('FINAL SCORE '+String(state.score).padStart(6,'0'),H*0.34+58,22,'#fff');
if(state.newBest)center('★ NEW BEST! ★',H*0.34+92,20,'#ffd23f','rgba(255,210,63,0.8)');
ctx.save();ctx.globalAlpha=blink;
center('CLICK or press SPACE to play again',H*0.34+140,18,'#7df9ff','rgba(80,220,255,0.7)');
ctx.restore();
}
}
function drawHint(){
if(state.mode!=='playing')return;
ctx.save();
ctx.globalAlpha=0.28;
ctx.fillStyle='#aab3d6';ctx.font='12px system-ui,sans-serif';
ctx.textAlign='center';ctx.textBaseline='middle';
ctx.fillText('mouse or ← → / A D · space/click launch · P pause · M sound',W/2,H-10);
ctx.restore();
}
function render(){
ctx.save();
const g=ctx.createLinearGradient(0,0,0,H);
g.addColorStop(0,'#101430');g.addColorStop(0.55,'#0b0e1f');g.addColorStop(1,'#070912');
ctx.fillStyle=g;ctx.fillRect(0,0,W,H);
for(const s of stars){
ctx.globalAlpha=0.15+0.3*Math.abs(Math.sin(state.t*s.z+s.x));
ctx.fillStyle=s.c;ctx.fillRect(s.x,s.y,s.z*1.6,s.z*1.6);
}
ctx.globalAlpha=1;
if(state.shake>0.3)ctx.translate(rand(-state.shake,state.shake),rand(-state.shake,state.shake));
ctx.strokeStyle='rgba(130,110,255,0.35)';ctx.lineWidth=2;
ctx.beginPath();ctx.moveTo(0,WALL_TOP);ctx.lineTo(W,WALL_TOP);ctx.stroke();
drawBricks();drawPowerups();drawPaddle();drawBalls();drawParticles();drawFloaters();
ctx.restore();
drawHUD();drawBanner();drawOverlays();drawHint();
}
// ================= input =================
addEventListener('keydown',e=>{
if(['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','Space'].includes(e.code))e.preventDefault();
keys[e.code]=true;
if(e.repeat)return;
if(e.code==='Space'||e.code==='Enter'){
if(state.mode==='menu'||state.mode==='over'||state.mode==='win')startGame();
else launch();
}
if(e.code==='KeyP'||e.code==='Escape'){
if(state.mode==='playing')state.mode='paused';
else if(state.mode==='paused')state.mode='playing';
}
if(e.code==='KeyM')muted=!muted;
});
addEventListener('keyup',e=>keys[e.code]=false);
function pointerX(clientX){
const r=canvas.getBoundingClientRect();
return (clientX-r.left)/r.width*W;
}
canvas.addEventListener('mousemove',e=>{mouseX=pointerX(e.clientX);});
canvas.addEventListener('mousedown',e=>{
e.preventDefault();
ac();
if(state.mode==='menu'||state.mode==='over'||state.mode==='win')startGame();
else if(state.mode==='playing')launch();
});
canvas.addEventListener('touchstart',e=>{
e.preventDefault();ac();
if(e.touches[0])mouseX=pointerX(e.touches[0].clientX);
if(state.mode==='menu'||state.mode==='over'||state.mode==='win')startGame();
else if(state.mode==='playing')launch();
},{passive:false});
canvas.addEventListener('touchmove',e=>{
e.preventDefault();
if(e.touches[0])mouseX=pointerX(e.touches[0].clientX);
},{passive:false});
// ================= fit & loop =================
function fit(){
const s=Math.min(innerWidth/W,innerHeight/H)*0.97;
canvas.style.width=(W*s|0)+'px';
canvas.style.height=(H*s|0)+'px';
}
addEventListener('resize',fit);
fit();
initStars();
buildLevel(0);
let last=performance.now();
function frame(now){
const raw=Math.min((now-last)/1000,1/30);last=now;
let dt;
if(state.hitStop>0){state.hitStop-=raw;dt=0;}
else{
if(state.slowmo>0)state.slowmo-=raw;
const target=state.slowmo>0?0.22:1;
state.timeScale=lerp(state.timeScale,target,Math.min(1,raw*7));
dt=raw*state.timeScale;
}
if(state.mode!=='paused')update(dt,raw);
render();
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
})();
</script>
</body>
</html>

