Run details
- Model
- inclusionai/ling-3.2-flash:free
- Route
- OpenRouter API
- Served by
- Ant Digital
- Effort
- model default
- Limits
- 60 min · 262,144 output tokens (model max)
- Date
- 24 Nov 2026
- Time
- 6 min 57 s
- Size
- 32 kB
- Tokens
- 98 in, 53,157 out (39,349 thinking)
- List price
- free at today's price (free route)
- 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
32 kB 649 lines Raw
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Neon Breakout</title>
<style>
*{margin:0;padding:0;box-sizing:border-box}
html,body{height:100%}
body{
background:#04050d radial-gradient(1200px 700px at 50% 18%, #0c1233 0%, #04050d 62%);
display:flex;align-items:center;justify-content:center;overflow:hidden;
font-family:"Segoe UI",system-ui,-apple-system,Roboto,Helvetica,Arial,sans-serif;
color:#e6f0ff;-webkit-user-select:none;user-select:none;
}
#wrap{position:relative}
canvas{display:block;border-radius:14px;background:#070a18;cursor:none;touch-action:none;
box-shadow:0 0 0 1px rgba(90,140,255,.25),0 0 45px rgba(60,120,255,.22),0 0 130px rgba(120,60,255,.12)}
body.playing canvas{cursor:none}
#hud{position:absolute;top:0;left:0;right:0;display:flex;justify-content:space-between;align-items:flex-start;
padding:12px 18px;pointer-events:none;z-index:5;font-weight:700;letter-spacing:2px}
.hud-label{font-size:10px;opacity:.55;letter-spacing:3px}
#score{font-size:22px;color:#4df3ff;text-shadow:0 0 12px rgba(77,243,255,.8)}
#best{font-size:11px;opacity:.65;letter-spacing:2px}
#levelTag{font-size:14px;color:#ffd93b;text-shadow:0 0 10px rgba(255,217,59,.7);text-align:center}
#lives{color:#ff4d6d;text-shadow:0 0 10px rgba(255,77,109,.8);font-size:17px;letter-spacing:3px}
#muteBtn{pointer-events:auto;cursor:pointer;margin-left:12px;font-size:16px;opacity:.85}
#muteBtn:hover{opacity:1}
.overlay{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;
gap:16px;background:rgba(4,6,16,.8);backdrop-filter:blur(6px);border-radius:14px;text-align:center;
z-index:10;transition:opacity .25s;padding:20px}
.hidden{opacity:0 !important;pointer-events:none !important}
.overlay h1{font-family:"Arial Black",Arial,sans-serif;font-size:52px;line-height:1.05;letter-spacing:4px;color:#fff;
text-shadow:0 0 12px #4df3ff,0 0 40px #4d7cff,0 0 80px #c44dff}
.overlay h1 .alt{color:#ffd93b;text-shadow:0 0 12px #ffd93b,0 0 40px #ff9f43}
.tag{opacity:.8;letter-spacing:1px}
.controls{font-size:13px;line-height:1.9;opacity:.8;background:rgba(255,255,255,.05);
border:1px solid rgba(120,160,255,.25);padding:10px 20px;border-radius:10px}
.controls b{color:#4df3ff}
.big{font-size:38px;font-weight:800;color:#ffd93b;text-shadow:0 0 14px rgba(255,217,59,.8);letter-spacing:2px}
.hi{font-size:13px;letter-spacing:2px;opacity:.85}
.hi span{color:#ffd93b}
button{font:inherit;font-weight:800;letter-spacing:3px;font-size:16px;color:#04121a;
background:linear-gradient(180deg,#5ff5ff,#28c4ff);border:none;border-radius:10px;padding:13px 34px;cursor:pointer;
box-shadow:0 0 18px rgba(77,243,255,.6),inset 0 0 8px rgba(255,255,255,.5);transition:transform .08s}
button:hover{transform:scale(1.06)}
button:active{transform:scale(.96)}
#pause{background:rgba(4,6,16,.55)}
#pause div{font-family:"Arial Black",Arial,sans-serif;font-size:42px;letter-spacing:6px;color:#fff;
text-shadow:0 0 14px #4df3ff,0 0 40px #4d7cff}
#pause small{letter-spacing:3px;opacity:.7}
</style>
</head>
<body>
<div id="wrap">
<div id="hud">
<div><div class="hud-label">SCORE</div><div id="score">0</div><div id="best">BEST 0</div></div>
<div id="levelTag">LV 1/5</div>
<div style="text-align:right"><div class="hud-label">LIVES</div><span id="lives">♥♥♥</span><span id="muteBtn">🔊</span></div>
</div>
<canvas id="game"></canvas>
<div id="overlay" class="overlay"></div>
<div id="pause" class="overlay hidden"><div>PAUSED</div><small>P TO RESUME</small></div>
</div>
<script>
(()=>{ "use strict";
// ============ CONSTANTS ============
const W=960,H=640,WALL=14;
const PADDLE_Y=H-46,PADDLE_H=14,PADDLE_W=112,PADDLE_WIDE=172;
const BALL_R=8,BW=(W-96-11*6)/12,BH=24,GPAD=6,TOP=88;
const TAU=Math.PI*2;
const clamp=(v,a,b)=>v<a?a:v>b?b:v;
const rand=(a,b)=>a+Math.random()*(b-a);
const fmt=n=>Math.round(n).toLocaleString('en-US');
const easeOutBack=t=>{const c=1.70158;return 1+(c+1)*Math.pow(t-1,3)+c*Math.pow(t-1,2);};
const canvas=document.getElementById('game'),ctx=canvas.getContext('2d');
const dpr=Math.min(2,window.devicePixelRatio||1);
canvas.width=W*dpr;canvas.height=H*dpr;ctx.scale(dpr,dpr);
const scoreEl=document.getElementById('score'),bestEl=document.getElementById('best'),
levelEl=document.getElementById('levelTag'),livesEl=document.getElementById('lives'),
overlay=document.getElementById('overlay'),pauseEl=document.getElementById('pause'),
muteBtn=document.getElementById('muteBtn');
// ============ STATE ============
const G={state:'menu',paused:false,score:0,high:+(localStorage.getItem('nbHigh')||0),
lives:3,level:1,combo:0,bestCombo:0,shake:0,flashA:0,flashColor:'255,255,255',
timeScale:1,time:0,levelTime:0,wideUntil:0,slowUntil:0,breakable:0,
introT:0,clearT:0,clearBonus:0,slowmo:0,hitstop:0,pendingClear:false,muted:false};
let paddle={x:W/2,w:PADDLE_W,vx:0,squash:0};
let balls=[],bricks=[],powers=[],parts=[],texts=[],waves=[],stars=[],bg=null;
let keys={},mouseX=null;
const COLORS={r:'#ff4d6d',o:'#ff9f43',y:'#ffd93b',g:'#5dff8f',c:'#4df3ff',b:'#4d7cff',p:'#c44dff'};
const POWERS={M:{label:'×3',color:'#c44dff'},W:{label:'W',color:'#4df3ff'},
S:{label:'S',color:'#5dff8f'},L:{label:'+1',color:'#ff4d6d'},'$':{label:'$',color:'#ffd93b'}};
const HUES=[215,275,150,35,330];
const LEVELS=[
{name:'FIRST CONTACT',speed:400,rows:[
"rrrrrrrrrrrr","oooooooooooo","yyyyyyyyyyyy","gggggggggggg","bbbbbbbbbbbb"]},
{name:'CHECKMATE',speed:430,rows:[
"c.c.c.c.c.c.",".C.C.C.C.C.C","p.p.p.p.p.p.",".P.P.P.P.P.P","y.y.y.y.y.y.",".Y.Y.Y.Y.Y.Y"]},
{name:'CROSSFIRE',speed:455,rows:[
"g.g.g.g.g.g.",".G.G.G.G.G.G","X.X.X.X.X.X.",".b.b.b.b.b.b","b.b.b.b.b.b.",".B.B.B.B.B.B"]},
{name:'THE DIAMOND',speed:480,rows:[
".....rr.....","....rRRr....","...rRyyRr...","..rRyyyyRr..",".rRyyyyyyRr.","..rRyyyyRr..","...rRyyRr...","....rRRr....",".....rr....."]},
{name:'FORTRESS',speed:505,rows:[
"X..........X","X.gggggggg.X","X.gGGGGGGg.X","X.gGppppGg.X","X.gGp..pGg.X","X.gGppppGg.X","X.gGGGGGGg.X","X.gggggggg.X","X..........X"]}
];
// ============ AUDIO ============
let actx=null,masterGain,sfxBus,musicBus,noiseBuf,musicInt=null,mStep=0;
function initAudio(){
if(actx){if(actx.state==='suspended')actx.resume();return;}
try{actx=new (window.AudioContext||window.webkitAudioContext)();}catch(e){return;}
masterGain=actx.createGain();masterGain.gain.value=G.muted?0:0.5;masterGain.connect(actx.destination);
sfxBus=actx.createGain();sfxBus.gain.value=0.9;sfxBus.connect(masterGain);
musicBus=actx.createGain();musicBus.gain.value=0.15;musicBus.connect(masterGain);
noiseBuf=actx.createBuffer(1,actx.sampleRate*0.5,actx.sampleRate);
const d=noiseBuf.getChannelData(0);for(let i=0;i<d.length;i++)d[i]=Math.random()*2-1;
startMusic();
}
function tone(f,dur,type,vol,slide,bus,delay){
if(!actx)return;const t=actx.currentTime+(delay||0);
const o=actx.createOscillator(),g=actx.createGain();
o.type=type||'square';o.frequency.setValueAtTime(f,t);
if(slide)o.frequency.exponentialRampToValueAtTime(Math.max(30,f+slide),t+dur);
g.gain.setValueAtTime(vol||0.2,t);g.gain.exponentialRampToValueAtTime(0.001,t+dur);
o.connect(g);g.connect(bus||sfxBus);o.start(t);o.stop(t+dur+0.05);
}
function noise(dur,vol,freq,q,bus,delay){
if(!actx)return;const t=actx.currentTime+(delay||0);
const s=actx.createBufferSource();s.buffer=noiseBuf;s.loop=true;
const f=actx.createBiquadFilter();f.type='bandpass';f.frequency.value=freq||1200;f.Q.value=q||1;
const g=actx.createGain();g.gain.setValueAtTime(vol||0.3,t);g.gain.exponentialRampToValueAtTime(0.001,t+dur);
s.connect(f);f.connect(g);g.connect(bus||sfxBus);s.start(t);s.stop(t+dur+0.05);
}
const sfxWall =()=>tone(150,.04,'square',.07);
const sfxPaddle=()=>{tone(190,.07,'square',.16,60);noise(.04,.08,2500);};
const sfxBrick=c=>{tone(300+Math.min(c,14)*28,.09,'square',.14);noise(.12,.22,700+Math.min(c,14)*90);};
const sfxTough=()=>{tone(120,.08,'sawtooth',.14);noise(.05,.12,400);};
const sfxSteel=()=>{tone(1240,.05,'square',.07);tone(760,.09,'square',.05,0,sfxBus,.02);};
const sfxLaunch=()=>tone(240,.1,'square',.15,300);
const sfxPower=()=>{tone(660,.08,'square',.15);tone(880,.08,'square',.15,0,sfxBus,.07);tone(1320,.12,'square',.15,0,sfxBus,.14);};
const sfxLose =()=>{tone(280,.35,'sawtooth',.22,-200);noise(.3,.2,300);};
const sfxLevel=()=>[523,659,784,1047].forEach((f,i)=>tone(f,.14,'square',.15,0,sfxBus,i*.09));
const sfxOver =()=>[392,330,262,196].forEach((f,i)=>tone(f,.22,'sawtooth',.15,0,sfxBus,i*.14));
const sfxWin =()=>[523,659,784,1047,1319,1568].forEach((f,i)=>tone(f,.16,'square',.15,0,sfxBus,i*.11));
const BASS=[110,0,110,0,130.81,0,98,0,110,0,110,0,164.81,0,146.83,130.81];
function startMusic(){if(musicInt||!actx)return;musicInt=setInterval(()=>{
if(G.muted||document.hidden)return;
const f=BASS[mStep%BASS.length];
if(f)tone(f,.16,'triangle',.5,0,musicBus);
if(mStep%4===0)noise(.03,.06,6000,1,musicBus);
if(mStep%8===4)noise(.08,.05,1800,1,musicBus);
mStep++;},190);}
function stopMusic(){clearInterval(musicInt);musicInt=null;}
// ============ LEVELS ============
function parseLevel(def){
bricks=[];
def.rows.forEach((row,ri)=>{
for(let ci=0;ci<row.length;ci++){
const ch=row[ci];if(ch==='.')continue;
const x=48+ci*(BW+GPAD),y=TOP+ri*(BH+GPAD);
if(ch==='X')bricks.push({x,y,w:BW,h:BH,hp:Infinity,steel:true,tough:false,cracked:false,color:'#7c8698',dead:false,flash:0});
else{
const tough=ch!==ch.toLowerCase(),color=COLORS[ch.toLowerCase()]||'#fff';
bricks.push({x,y,w:BW,h:BH,hp:tough?2:1,maxHp:tough?2:1,steel:false,tough,cracked:false,color,dead:false,flash:0});
}
}
});
G.breakable=bricks.filter(b=>!b.steel).length;
}
function loadLevel(n){
parseLevel(LEVELS[n-1]);
balls=[newBall()];powers=[];texts=[];waves=[];
G.combo=0;G.levelTime=0;G.wideUntil=0;G.slowUntil=0;G.pendingClear=false;
paddle.x=W/2;paddle.w=PADDLE_W;makeBG(HUES[(n-1)%HUES.length]);
}
function newBall(){return{x:paddle.x,y:PADDLE_Y-BALL_R-2,vx:0,vy:0,stuck:true,trail:[],squash:0,r:BALL_R};}
function currentSpeed(){
let s=LEVELS[G.level-1].speed*(1+Math.min(.3,G.levelTime*.006));
if(G.time<G.slowUntil)s*=0.7;return s;
}
// ============ FX ============
function burst(x,y,color,n,power,g){
if(parts.length>420)return;
for(let i=0;i<n;i++){const a=rand(0,TAU),s=rand(30,power),L=rand(.35,.8);
parts.push({x,y,vx:Math.cos(a)*s,vy:Math.sin(a)*s-70,g:g===undefined?850:g,life:L,ttl:L,color,size:rand(2,5),rot:rand(0,TAU),vr:rand(-9,9)});}
}
function popup(x,y,text,color,size){texts.push({x,y,vy:-55,life:1.1,ttl:1.1,text,color,size:size||18});}
function setFlash(a,c){G.flashA=a;G.flashColor=c;}
// ============ GAME FLOW ============
function startGame(){
initAudio();if(document.activeElement)document.activeElement.blur();
G.score=0;G.lives=3;G.level=1;G.combo=0;G.bestCombo=0;G.time=0;
loadLevel(1);G.state='intro';G.introT=2.2;G.paused=false;
pauseEl.classList.add('hidden');hideOverlay();startMusic();
document.body.classList.add('playing');
}
function launchBalls(){
let any=false;
for(const b of balls)if(b.stuck){any=true;b.stuck=false;
const a=rand(-.3,.3),sp=currentSpeed();
b.vx=Math.sin(a)*sp+paddle.vx*.15;b.vy=-Math.cos(a)*sp;}
if(any)sfxLaunch();
}
function levelCleared(){G.pendingClear=true;}
function doLevelClear(){
const bonus=400+G.level*100;G.score+=bonus;G.clearBonus=bonus;
G.state='clear';G.clearT=2.3;balls=[];powers=[];
sfxLevel();setFlash(.35,'255,255,255');G.shake=Math.min(1,G.shake+.3);
for(let k=0;k<6;k++)burst(rand(100,W-100),rand(80,220),['#ff4d6d','#ffd93b','#5dff8f','#4df3ff','#c44dff'][k%5],22,320);
}
function advanceLevel(){
if(G.level>=LEVELS.length){winGame();return;}
G.level++;loadLevel(G.level);G.state='intro';G.introT=2.2;
}
function loseLife(){
G.lives--;G.combo=0;sfxLose();setFlash(.5,'255,60,90');G.shake=1;G.slowmo=.6;
if(G.lives<=0){gameOver();return;}
balls=[newBall()];popup(W/2,H/2,'BALL LOST','#ff4d6d',22);
}
function saveHigh(){if(G.score>G.high){G.high=G.score;localStorage.setItem('nbHigh',G.high);}}
function gameOver(){G.state='over';saveHigh();stopMusic();sfxOver();
document.body.classList.remove('playing');showOverlay(overHTML());}
function winGame(){G.state='win';saveHigh();stopMusic();sfxWin();
for(let k=0;k<8;k++)burst(rand(80,W-80),rand(80,300),['#ff4d6d','#ffd93b','#5dff8f','#4df3ff','#c44dff'][k%5],26,340);
document.body.classList.remove('playing');showOverlay(winHTML());}
// ============ COMBAT ============
function hitBrick(br,b){
b.squash=1;br.flash=1;
if(br.steel){sfxSteel();burst(b.x,b.y,'#aab3c5',4,120);G.shake=Math.min(1,G.shake+.05);return;}
br.hp--;
if(br.hp<=0){
br.dead=true;G.breakable--;
G.combo++;G.bestCombo=Math.max(G.bestCombo,G.combo);
const pts=(br.tough?100:50)+G.combo*10;G.score+=pts;
if(G.score>G.high)G.high=G.score;
const cx=br.x+br.w/2,cy=br.y+br.h/2;
popup(cx,cy,'+'+pts,'#ffffff',15);
if(G.combo>=4)popup(cx,cy-20,'COMBO ×'+G.combo,'#ffd93b',17);
burst(cx,cy,br.color,14,300);
waves.push({x:cx,y:cy,r:8,maxR:br.w*.8,life:.3,ttl:.3,color:br.color});
sfxBrick(G.combo);
if(br.tough){G.hitstop=.045;G.shake=Math.min(1,G.shake+.3);}else G.shake=Math.min(1,G.shake+.12);
if(Math.random()<.16)powers.push({x:cx,y:cy,vy:135,type:pickPower()});
if(G.breakable<=0)levelCleared();
}else{
br.cracked=true;sfxTough();burst(b.x,b.y,br.color,5,160);G.shake=Math.min(1,G.shake+.06);
}
}
function pickPower(){const r=Math.random();if(r<.26)return'M';if(r<.5)return'W';if(r<.72)return'S';if(r<.8)return'L';return'$';}
function applyPower(t,x,y){
sfxPower();waves.push({x,y,r:4,maxR:60,life:.3,ttl:.3,color:POWERS[t].color});
if(t==='M'){
const src=balls.filter(b=>!b.stuck),add=[];
for(const b of src)for(const da of[-.5,.5]){
if(balls.length+add.length>=9)break;
const sp=Math.hypot(b.vx,b.vy)||currentSpeed(),a=Math.atan2(b.vy,b.vx)+da;
add.push({x:b.x,y:b.y,vx:Math.cos(a)*sp,vy:Math.sin(a)*sp,stuck:false,trail:[],squash:0,r:BALL_R});}
balls.push(...add);popup(x,y,'MULTIBALL!',POWERS.M.color);
}else if(t==='W'){G.wideUntil=G.time+12;popup(x,y,'WIDE PADDLE!',POWERS.W.color);}
else if(t==='S'){G.slowUntil=G.time+10;popup(x,y,'SLOW BALL!',POWERS.S.color);}
else if(t==='L'){if(G.lives>=5){G.score+=300;popup(x,y,'+300',POWERS.L.color);}else{G.lives++;popup(x,y,'+1 LIFE',POWERS.L.color);}}
else{G.score+=300;popup(x,y,'+300',POWERS['$'].color);}
}
function fixAngle(b){
const sp=Math.hypot(b.vx,b.vy);if(!sp)return;
const minVy=sp*.24;
if(Math.abs(b.vy)<minVy){b.vy=(b.vy<0?-1:1)*minVy;b.vx=(b.vx<0?-1:1)*Math.sqrt(Math.max(0,sp*sp-b.vy*b.vy));}
}
// ============ UPDATE ============
function updatePaddle(dt){
const targetW=(G.time<G.wideUntil)?PADDLE_WIDE:PADDLE_W;
paddle.w+=(targetW-paddle.w)*Math.min(1,dt*10);
let dir=0;
if(keys['ArrowLeft']||keys['KeyA'])dir-=1;
if(keys['ArrowRight']||keys['KeyD'])dir+=1;
const oldX=paddle.x;
if(dir!==0){paddle.x+=dir*640*dt;mouseX=null;}
else if(mouseX!=null)paddle.x=mouseX;
paddle.x=clamp(paddle.x,WALL+paddle.w/2,W-WALL-paddle.w/2);
paddle.vx=(paddle.x-oldX)/Math.max(dt,1e-4);
paddle.squash=Math.max(0,paddle.squash-dt*6);
}
function updateBalls(dt){
for(let i=balls.length-1;i>=0;i--){
const b=balls[i];
b.squash=Math.max(0,b.squash-dt*6);
if(b.stuck){b.x=paddle.x;b.y=PADDLE_Y-BALL_R-2;continue;}
const sp=currentSpeed(),m=Math.hypot(b.vx,b.vy)||1;
b.vx=b.vx/m*sp;b.vy=b.vy/m*sp;
const steps=Math.max(1,Math.ceil(sp*dt/(BALL_R*.7))),sdt=dt/steps;
for(let s=0;s<steps;s++){
b.x+=b.vx*sdt;b.y+=b.vy*sdt;
if(b.x-b.r<WALL){b.x=WALL+b.r;b.vx=Math.abs(b.vx);fixAngle(b);b.squash=1;sfxWall();burst(b.x-b.r,b.y,'#8fb7ff',3,110);}
else if(b.x+b.r>W-WALL){b.x=W-WALL-b.r;b.vx=-Math.abs(b.vx);fixAngle(b);b.squash=1;sfxWall();burst(b.x+b.r,b.y,'#8fb7ff',3,110);}
if(b.y-b.r<WALL){b.y=WALL+b.r;b.vy=Math.abs(b.vy);fixAngle(b);b.squash=1;sfxWall();burst(b.x,b.y-b.r,'#8fb7ff',3,110);}
if(b.vy>0&&b.y+b.r>PADDLE_Y&&b.y-b.r<PADDLE_Y+PADDLE_H&&
b.x>paddle.x-paddle.w/2-b.r*.5&&b.x<paddle.x+paddle.w/2+b.r*.5){
const rel=clamp((b.x-paddle.x)/(paddle.w/2+b.r*.5),-1,1),ang=rel*Math.PI/3.2;
b.vx=Math.sin(ang)*sp;b.vy=-Math.abs(Math.cos(ang))*sp;
b.vx+=paddle.vx*.12;
let m2=Math.hypot(b.vx,b.vy)||1;b.vx=b.vx/m2*sp;b.vy=b.vy/m2*sp;
if(b.vy>-sp*.35){b.vy=-sp*.35;const mm=Math.hypot(b.vx,b.vy);b.vx=b.vx/mm*sp;b.vy=b.vy/mm*sp;}
b.y=PADDLE_Y-b.r-.5;paddle.squash=1;G.combo=0;
sfxPaddle();burst(b.x,PADDLE_Y,'#4df3ff',6,140);
waves.push({x:b.x,y:PADDLE_Y,r:4,maxR:30,life:.2,ttl:.2,color:'#4df3ff'});
}
for(const br of bricks){
if(br.dead)continue;
const cx=clamp(b.x,br.x,br.x+br.w),cy=clamp(b.y,br.y,br.y+br.h);
const dx=b.x-cx,dy=b.y-cy;
if(dx*dx+dy*dy<=b.r*b.r){
if(Math.abs(dx)>Math.abs(dy)){b.vx=dx>0?Math.abs(b.vx):-Math.abs(b.vx);b.x=cx+(dx>0?b.r:-b.r);}
else{b.vy=dy>0?Math.abs(b.vy):-Math.abs(b.vy);b.y=cy+(dy>0?b.r:-b.r);}
fixAngle(b);hitBrick(br,b);break;
}
}
if(G.pendingClear)break;
}
if(G.pendingClear)break;
if(b.y-b.r>H+30){balls.splice(i,1);burst(clamp(b.x,0,W),H-10,'#ff4d6d',10,200);continue;}
b.trail.push({x:b.x,y:b.y});if(b.trail.length>12)b.trail.shift();
}
if(G.state==='play'&&balls.length===0)loseLife();
}
function updatePowers(dt){
for(let i=powers.length-1;i>=0;i--){
const p=powers[i];p.y+=p.vy*dt;
if(p.y>H+30){powers.splice(i,1);continue;}
if(p.y+10>PADDLE_Y&&p.y-10<PADDLE_Y+PADDLE_H&&Math.abs(p.x-paddle.x)<paddle.w/2+16){
applyPower(p.type,p.x,p.y);powers.splice(i,1);}
}
}
function update(dt,rdt){
for(const s of stars){s.y+=s.s*dt;if(s.y>H+2){s.y=-2;s.x=rand(0,W);}}
for(let i=parts.length-1;i>=0;i--){const p=parts[i];p.life-=dt;
if(p.life<=0){parts.splice(i,1);continue;}
p.vy+=p.g*dt;p.x+=p.vx*dt;p.y+=p.vy*dt;p.rot+=p.vr*dt;}
for(let i=texts.length-1;i>=0;i--){const t=texts[i];t.life-=dt;t.y+=t.vy*dt;if(t.life<=0)texts.splice(i,1);}
for(let i=waves.length-1;i>=0;i--){const w=waves[i];w.life-=dt;w.r+=(w.maxR-w.r)*dt*8;if(w.life<=0)waves.splice(i,1);}
for(const b of bricks)if(b.flash>0)b.flash=Math.max(0,b.flash-dt*5);
G.shake=Math.max(0,G.shake-rdt*2.4);
G.flashA=Math.max(0,G.flashA-rdt*2.5);
if(G.state==='intro'){G.introT-=rdt;if(G.introT<=0)G.state='play';}
if(G.state==='clear'){G.clearT-=rdt;if(G.clearT<=0)advanceLevel();}
if(G.state==='play'||G.state==='intro'){
G.levelTime+=dt;updatePaddle(dt);updateBalls(dt);updatePowers(dt);
if(G.pendingClear){G.pendingClear=false;doLevelClear();}
}else updatePaddle(dt);
updateHUD();
}
// ============ RENDER ============
function rr(g,x,y,w,h,r){g.beginPath();g.moveTo(x+r,y);g.arcTo(x+w,y,x+w,y+h,r);
g.arcTo(x+w,y+h,x,y+h,r);g.arcTo(x,y+h,x,y,r);g.arcTo(x,y,x+w,y,r);g.closePath();}
function shade(hex,amt){
const r=parseInt(hex.slice(1,3),16),g=parseInt(hex.slice(3,5),16),b=parseInt(hex.slice(5,7),16);
const f=v=>clamp(Math.round(amt>0?v+(255-v)*amt:v*(1+amt)),0,255);
return`rgb(${f(r)},${f(g)},${f(b)})`;
}
function makeBG(hue){
bg=document.createElement('canvas');bg.width=W;bg.height=H;
const g=bg.getContext('2d');
const lg=g.createLinearGradient(0,0,0,H);
lg.addColorStop(0,'#0a0e22');lg.addColorStop(1,'#04050d');
g.fillStyle=lg;g.fillRect(0,0,W,H);
for(let i=0;i<4;i++){const x=rand(0,W),y=rand(0,H*.7),r=rand(120,260);
const rg=g.createRadialGradient(x,y,0,x,y,r);
rg.addColorStop(0,`hsla(${(hue+i*40)%360},80%,55%,.1)`);rg.addColorStop(1,'rgba(0,0,0,0)');
g.fillStyle=rg;g.fillRect(0,0,W,H);}
g.strokeStyle='rgba(90,120,255,.05)';g.lineWidth=1;
for(let x=0;x<=W;x+=48){g.beginPath();g.moveTo(x,0);g.lineTo(x,H);g.stroke();}
for(let y=0;y<=H;y+=48){g.beginPath();g.moveTo(0,y);g.lineTo(W,y);g.stroke();}
const vg=g.createRadialGradient(W/2,H/2,H*.35,W/2,H/2,H*.75);
vg.addColorStop(0,'rgba(0,0,0,0)');vg.addColorStop(1,'rgba(0,0,0,.5)');
g.fillStyle=vg;g.fillRect(0,0,W,H);
}
const spriteCache={};
function getSprite(color,tough,cracked,steel,hp){
const key=color+'|'+tough+'|'+cracked+'|'+steel+'|'+hp;
if(spriteCache[key])return spriteCache[key];
const c=document.createElement('canvas');c.width=BW+10;c.height=BH+10;
const g=c.getContext('2d');g.translate(5,5);
rr(g,0,0,BW,BH,6);
if(steel){
const gr=g.createLinearGradient(0,0,0,BH);
gr.addColorStop(0,'#5a6478');gr.addColorStop(.5,'#3a4152');gr.addColorStop(1,'#232838');
g.fillStyle=gr;g.fill();g.strokeStyle='#8b95ab';g.lineWidth=2;g.stroke();
g.fillStyle='#aab3c5';
[[7,7],[BW-7,7],[7,BH-7],[BW-7,BH-7]].forEach(p=>{g.beginPath();g.arc(p[0],p[1],2,0,TAU);g.fill();});
}else{
const gr=g.createLinearGradient(0,0,0,BH);
gr.addColorStop(0,shade(color,.6));gr.addColorStop(.45,color);gr.addColorStop(1,shade(color,-.35));
g.fillStyle=gr;g.fill();
g.fillStyle='rgba(255,255,255,.4)';rr(g,4,2.5,BW-8,4,2);g.fill();
g.strokeStyle=shade(color,-.5);g.lineWidth=1.5;rr(g,.75,.75,BW-1.5,BH-1.5,6);g.stroke();
if(tough){
g.strokeStyle='rgba(255,255,255,.85)';g.lineWidth=2.5;rr(g,2,2,BW-4,BH-4,5);g.stroke();
g.fillStyle='rgba(255,255,255,.95)';
for(let i=0;i<hp;i++){g.beginPath();g.arc(BW/2+(i-(hp-1)/2)*12,BH/2,2.4,0,TAU);g.fill();}
}
if(cracked){
g.strokeStyle='rgba(10,10,20,.55)';g.lineWidth=1.6;
g.beginPath();g.moveTo(BW*.3,2);g.lineTo(BW*.42,BH*.45);g.lineTo(BW*.34,BH*.8);
g.moveTo(BW*.65,1);g.lineTo(BW*.58,BH*.5);g.lineTo(BW*.7,BH*.9);g.stroke();
g.fillStyle='rgba(0,0,0,.22)';rr(g,0,0,BW,BH,6);g.fill();
}
}
spriteCache[key]=c;return c;
}
function drawWalls(){
ctx.save();
const g=ctx.createLinearGradient(0,0,W,0);
g.addColorStop(0,'#4df3ff');g.addColorStop(.5,'#7c6bff');g.addColorStop(1,'#ff4d9d');
ctx.strokeStyle=g;ctx.lineWidth=3;ctx.shadowColor='#4df3ff';ctx.shadowBlur=12;
ctx.beginPath();ctx.moveTo(WALL,H+10);ctx.lineTo(WALL,WALL);ctx.lineTo(W-WALL,WALL);ctx.lineTo(W-WALL,H+10);ctx.stroke();
ctx.restore();
const dg=ctx.createLinearGradient(0,H-40,0,H);
dg.addColorStop(0,'rgba(255,77,109,0)');dg.addColorStop(1,'rgba(255,77,109,.18)');
ctx.fillStyle=dg;ctx.fillRect(WALL,H-40,W-2*WALL,40);
}
function drawBricks(){
for(const b of bricks){
if(b.dead)continue;
ctx.drawImage(getSprite(b.color,b.tough,b.cracked,b.steel,b.hp),b.x-5,b.y-5);
if(b.flash>0){ctx.globalAlpha=b.flash*.45;ctx.fillStyle='#fff';rr(ctx,b.x,b.y,b.w,b.h,6);ctx.fill();ctx.globalAlpha=1;}
}
}
function drawPowers(){
for(const p of powers){
const P=POWERS[p.type];
ctx.save();ctx.translate(p.x,p.y);ctx.rotate(Math.sin(G.time*4+p.x)*.15);
ctx.shadowColor=P.color;ctx.shadowBlur=14;
rr(ctx,-17,-10,34,20,10);ctx.fillStyle='rgba(8,12,26,.92)';ctx.fill();
ctx.lineWidth=2;ctx.strokeStyle=P.color;ctx.stroke();
ctx.shadowBlur=0;ctx.fillStyle=P.color;ctx.font='900 13px Arial';
ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(P.label,0,1);
ctx.restore();
}
}
function drawPaddle(){
const w=paddle.w,h=PADDLE_H,wide=G.time<G.wideUntil;
ctx.save();ctx.translate(paddle.x,PADDLE_Y+h/2);
const sq=paddle.squash;ctx.scale(1+.22*sq,1-.3*sq);
const grad=ctx.createLinearGradient(-w/2,0,w/2,0);
grad.addColorStop(0,'#28c4ff');grad.addColorStop(.5,'#7df9ff');grad.addColorStop(1,'#28c4ff');
ctx.shadowColor=wide?'#c44dff':'#4df3ff';ctx.shadowBlur=18;
rr(ctx,-w/2,-h/2,w,h,7);ctx.fillStyle=grad;ctx.fill();
ctx.shadowBlur=0;ctx.fillStyle='rgba(255,255,255,.75)';rr(ctx,-w/2+4,-h/2+2,w-8,4,2);ctx.fill();
ctx.fillStyle='#fff';ctx.beginPath();ctx.arc(-w/2+7,0,3,0,TAU);ctx.arc(w/2-7,0,3,0,TAU);ctx.fill();
ctx.restore();
}
function drawBalls(){
for(const b of balls){
for(let i=0;i<b.trail.length;i++){const p=b.trail[i],f=i/b.trail.length;
ctx.globalAlpha=f*.25;ctx.fillStyle='#4df3ff';
ctx.beginPath();ctx.arc(p.x,p.y,BALL_R*f*.9,0,TAU);ctx.fill();}
ctx.globalAlpha=1;
ctx.save();ctx.translate(b.x,b.y);ctx.rotate(Math.atan2(b.vy,b.vx));
const sq=b.squash;ctx.scale(1+.35*sq,1-.3*sq);
const rg=ctx.createRadialGradient(0,0,1,0,0,b.r);
rg.addColorStop(0,'#ffffff');rg.addColorStop(.6,'#bff6ff');rg.addColorStop(1,'#4dd2ff');
ctx.shadowColor='#4df3ff';ctx.shadowBlur=16;
ctx.fillStyle=rg;ctx.beginPath();ctx.arc(0,0,b.r,0,TAU);ctx.fill();
ctx.restore();
}
}
function drawParticles(){
for(const p of parts){const a=clamp(p.life/p.ttl,0,1);
ctx.save();ctx.globalAlpha=a;ctx.translate(p.x,p.y);ctx.rotate(p.rot);
ctx.fillStyle=p.color;ctx.fillRect(-p.size/2,-p.size/2,p.size,p.size);ctx.restore();}
}
function drawWaves(){
for(const w of waves){const a=clamp(w.life/w.ttl,0,1);
ctx.globalAlpha=a*.8;ctx.strokeStyle=w.color;ctx.lineWidth=3*a+1;
ctx.beginPath();ctx.arc(w.x,w.y,w.r,0,TAU);ctx.stroke();}
ctx.globalAlpha=1;
}
function drawTexts(){
ctx.textAlign='center';
for(const t of texts){const a=clamp(t.life/t.ttl,0,1);
ctx.globalAlpha=a;ctx.font=`800 ${t.size}px "Segoe UI",Arial`;
ctx.fillStyle=t.color;ctx.shadowColor=t.color;ctx.shadowBlur=8;
ctx.fillText(t.text,t.x,t.y);}
ctx.shadowBlur=0;ctx.globalAlpha=1;
}
function chip(label,f,color,y){
ctx.save();ctx.globalAlpha=.95;ctx.fillStyle=color;
ctx.fillText(label,WALL+10,y);
const w=ctx.measureText(label).width,bx=WALL+10+w+8;
ctx.globalAlpha=.25;ctx.fillRect(bx,y-3,64,6);
ctx.globalAlpha=.95;ctx.fillRect(bx,y-3,64*clamp(f,0,1),6);ctx.restore();
}
function drawFX(){
let y=H-20;ctx.font='700 12px "Segoe UI",Arial';ctx.textAlign='left';ctx.textBaseline='middle';
if(G.time<G.wideUntil){chip('WIDE',(G.wideUntil-G.time)/12,'#4df3ff',y);y-=22;}
if(G.time<G.slowUntil){chip('SLOW',(G.slowUntil-G.time)/10,'#5dff8f',y);}
ctx.textBaseline='alphabetic';
}
function drawCombo(){
if(G.combo<3)return;
const p=1+Math.sin(G.time*10)*.08;
ctx.save();ctx.translate(W-WALL-14,64);ctx.scale(p,p);ctx.textAlign='right';
ctx.font='900 20px "Arial Black",Arial';
const c=G.combo>=10?'#ff4d6d':'#ffd93b';
ctx.fillStyle=c;ctx.shadowColor=c;ctx.shadowBlur=12;
ctx.fillText('COMBO ×'+G.combo,0,0);ctx.restore();
}
function drawHint(){
const stuck=balls.some(b=>b.stuck);
if(!stuck||(G.state!=='play'&&G.state!=='intro'))return;
ctx.globalAlpha=.55+.35*Math.sin(G.time*5);
ctx.font='700 14px "Segoe UI",Arial';ctx.textAlign='center';ctx.fillStyle='#9fdcff';
ctx.fillText('SPACE / CLICK TO LAUNCH',W/2,PADDLE_Y+44);
ctx.globalAlpha=1;
}
function drawBanner(main,sub,t,color){
const s=easeOutBack(Math.min(1,t*2.5));
ctx.save();ctx.translate(W/2,H/2-60);ctx.scale(s,s);
ctx.textAlign='center';ctx.font='900 54px "Arial Black",Arial,sans-serif';
ctx.shadowColor=color;ctx.shadowBlur=30;ctx.fillStyle='#fff';
ctx.fillText(main,0,0);ctx.restore();
ctx.save();ctx.globalAlpha=Math.min(1,t*3);
ctx.font='700 22px "Segoe UI",Arial';ctx.textAlign='center';
ctx.fillStyle=color;ctx.shadowColor=color;ctx.shadowBlur=12;
ctx.fillText(sub,W/2,H/2-14);ctx.restore();
}
function render(){
ctx.save();
const s=G.shake*G.shake*14;
ctx.translate((Math.random()*2-1)*s,(Math.random()*2-1)*s);
if(bg)ctx.drawImage(bg,0,0,W,H);
ctx.fillStyle='#cfe6ff';
for(const st of stars){ctx.globalAlpha=.15+.35*Math.abs(Math.sin(G.time*st.tw+st.ph));
ctx.fillRect(st.x,st.y,st.r,st.r);}
ctx.globalAlpha=1;
drawWalls();drawBricks();drawPowers();drawPaddle();drawBalls();
drawParticles();drawWaves();drawTexts();
if(G.time<G.slowUntil){ctx.fillStyle='rgba(80,160,255,.06)';ctx.fillRect(0,0,W,H);}
drawFX();drawCombo();drawHint();
ctx.font='600 11px "Segoe UI",Arial';ctx.textAlign='right';ctx.globalAlpha=.35;ctx.fillStyle='#9fdcff';
ctx.fillText('P PAUSE · M MUTE',W-WALL-10,H-10);ctx.globalAlpha=1;
if(G.state==='intro')drawBanner('LEVEL '+G.level,LEVELS[G.level-1].name,1-G.introT/2.2,'#4df3ff');
if(G.state==='clear')drawBanner('LEVEL CLEAR!','BONUS +'+fmt(G.clearBonus),1-G.clearT/2.3,'#ffd93b');
ctx.restore();
if(G.flashA>.001){ctx.fillStyle=`rgba(${G.flashColor},${G.flashA})`;ctx.fillRect(0,0,W,H);}
}
// ============ HUD / OVERLAYS ============
let lastScore=-1,lastHigh=-1,lastLevel=-1,lastLives=-1;
function updateHUD(){
if(G.score!==lastScore){scoreEl.textContent=fmt(G.score);lastScore=G.score;}
if(G.high!==lastHigh){bestEl.textContent='BEST '+fmt(G.high);lastHigh=G.high;}
if(G.level!==lastLevel){levelEl.textContent='LV '+G.level+'/'+LEVELS.length;lastLevel=G.level;}
if(G.lives!==lastLives){livesEl.textContent=G.lives>0?'♥'.repeat(G.lives):'—';lastLives=G.lives;}
}
function showOverlay(html){overlay.innerHTML=html;overlay.classList.remove('hidden');}
function hideOverlay(){overlay.classList.add('hidden');}
const menuHTML=()=>`<h1>NEON<br><span class="alt">BREAKOUT</span></h1>
<p class="tag">Smash the bricks · Chain combos · Grab power-ups</p>
<div class="controls"><b>MOUSE</b> move · <b>CLICK</b> launch<br>
<b>← → / A D</b> move · <b>SPACE</b> launch<br>
<b>P</b> pause · <b>M</b> mute</div>
<div class="hi">BEST SCORE <span>${fmt(G.high)}</span></div>
<button data-action="start">▶ START</button>
<div class="controls">5 LEVELS · MULTIBALL · WIDE PADDLE · SLOW BALL</div>`;
const overHTML=()=>`<h1>GAME <span class="alt">OVER</span></h1>
<div class="big">SCORE ${fmt(G.score)}</div>
<div class="hi">BEST ${fmt(G.high)} · BEST COMBO ×${G.bestCombo}</div>
<button data-action="start">↻ PLAY AGAIN</button>
<div class="controls">press <b>SPACE</b> to restart</div>`;
const winHTML=()=>`<h1>YOU <span class="alt">WIN!</span></h1>
<div class="big">SCORE ${fmt(G.score)}</div>
<div class="hi">ALL ${LEVELS.length} LEVELS CLEARED · BEST COMBO ×${G.bestCombo} · BEST ${fmt(G.high)}</div>
<button data-action="start">↻ PLAY AGAIN</button>
<div class="controls">press <b>SPACE</b> to restart</div>`;
// ============ INPUT ============
window.addEventListener('keydown',e=>{
if(['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','Space'].includes(e.code))e.preventDefault();
keys[e.code]=true;initAudio();
if(e.code==='Space'||e.code==='Enter'){
if(G.state==='menu'||G.state==='over'||G.state==='win')startGame();
else if((G.state==='play'||G.state==='intro')&&!G.paused)launchBalls();
}
if(e.code==='KeyP')togglePause();
if(e.code==='KeyM')toggleMute();
});
window.addEventListener('keyup',e=>{keys[e.code]=false;});
window.addEventListener('blur',()=>{keys={};if(G.state==='play'){G.paused=true;pauseEl.classList.remove('hidden');}});
document.addEventListener('visibilitychange',()=>{if(document.hidden&&G.state==='play'){G.paused=true;pauseEl.classList.remove('hidden');}});
canvas.addEventListener('pointermove',e=>{
const r=canvas.getBoundingClientRect();mouseX=(e.clientX-r.left)*(W/r.width);});
canvas.addEventListener('pointerdown',e=>{
initAudio();
if(G.state==='play'||G.state==='intro')launchBalls();});
canvas.addEventListener('touchmove',e=>{e.preventDefault();
const r=canvas.getBoundingClientRect();mouseX=(e.touches[0].clientX-r.left)*(W/r.width);},{passive:false});
overlay.addEventListener('click',e=>{
const a=e.target.closest('[data-action]');if(!a)return;
initAudio();if(a.dataset.action==='start')startGame();});
muteBtn.addEventListener('click',e=>{e.stopPropagation();initAudio();toggleMute();});
function toggleMute(){G.muted=!G.muted;if(masterGain)masterGain.gain.value=G.muted?0:0.5;
muteBtn.textContent=G.muted?'🔇':'🔊';}
function togglePause(){
if(!['play','intro','clear'].includes(G.state))return;
G.paused=!G.paused;pauseEl.classList.toggle('hidden',!G.paused);
}
// ============ LOOP ============
function resize(){
const s=Math.min(window.innerWidth/W,window.innerHeight/H)*.98;
canvas.style.width=Math.floor(W*s)+'px';canvas.style.height=Math.floor(H*s)+'px';
}
window.addEventListener('resize',resize);
for(let i=0;i<90;i++)stars.push({x:rand(0,W),y:rand(0,H),s:rand(6,30),r:rand(.6,1.8),tw:rand(1,4),ph:rand(0,TAU)});
loadLevel(1);
showOverlay(menuHTML());
updateHUD();
resize();
let last=performance.now();
function frame(now){
requestAnimationFrame(frame);
const rdt=Math.min(.05,(now-last)/1000);last=now;
if(G.slowmo>0){G.slowmo-=rdt;G.timeScale+=(.28-G.timeScale)*Math.min(1,rdt*8);}
else G.timeScale+=(1-G.timeScale)*Math.min(1,rdt*5);
let dt=rdt*G.timeScale;
if(G.hitstop>0){G.hitstop-=rdt;dt*=.1;}
G.time+=dt;
if(!G.paused)update(dt,rdt);
render();
}
requestAnimationFrame(frame);
})();
</script>
</body>
</html>

