• Updated 5 Dec, 14:20 UTC
  • Next run 6 Dec, 05:17 UTCNext 6 Dec 05:17
  • Last 7 days: 7 new models · 66 runs7 d: 7 models · 66 runs
Playable Breakout

MiMo v2.6 FlashXiaomi

Network offOpen alone (new tab)

Run details

Model
xiaomi/mimo-v2.6-flash
Route
OpenRouter API
Served by
Cohere
Effort
model default
Limits
60 min · 32,000 output tokens (model max)
Date
24 Oct 2026
Time
44 s
Size
32 kB
Tokens
83 in, 21,201 out (8,656 thinking)
List price
$0.006 at today's price ($0.14 in / $0.28 out per M)
Paid
$0.006

Raw: output · meta.json

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 983 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>
  *{margin:0;padding:0;box-sizing:border-box}
  html,body{height:100%}
  body{
    background:
      radial-gradient(circle at 50% 15%, #17204a 0%, #0a0e20 45%, #05060c 100%);
    display:flex;flex-direction:column;align-items:center;justify-content:center;
    font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
    color:#9fb2e6;overflow:hidden;user-select:none;
  }
  #stage{
    position:relative;
    width:min(96vw, calc(94vh * 900 / 640), 900px);
    aspect-ratio:900/640;
    border-radius:16px;overflow:hidden;
    box-shadow:0 0 70px rgba(70,110,255,.28), 0 0 0 1px rgba(255,255,255,.07), inset 0 0 60px rgba(0,0,0,.6);
    background:#05060c;
  }
  canvas{width:100%;height:100%;display:block;cursor:crosshair;touch-action:none}
  #scan{
    position:absolute;inset:0;pointer-events:none;
    background:repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,.16) 2px 4px);
    opacity:.45;mix-blend-mode:multiply;
  }
  #glow{
    position:absolute;inset:0;pointer-events:none;
    box-shadow:inset 0 0 120px rgba(0,0,0,.75);
    border-radius:16px;
  }
  #hint{
    margin-top:14px;font-size:13px;letter-spacing:.14em;text-transform:uppercase;
    color:#6d7fb8;text-align:center;line-height:1.7;padding:0 12px;
  }
  #hint b{color:#a9c0ff;font-weight:700}
</style>
</head>
<body>
<div id="stage">
  <canvas id="c" width="900" height="640"></canvas>
  <div id="scan"></div>
  <div id="glow"></div>
</div>
<div id="hint">
  <b>Mouse / ← → / A D</b> move &nbsp;•&nbsp; <b>Space / Click</b> launch &amp; laser &nbsp;•&nbsp; <b>P</b> pause &nbsp;•&nbsp; <b>M</b> mute &nbsp;•&nbsp; <b>R</b> restart
</div>

<script>
(function(){
'use strict';

/* ============================ SETUP ============================ */
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d');
const W = canvas.width, H = canvas.height;

const clamp=(v,a,b)=>v<a?a:(v>b?b:v);
const rnd=(a,b)=>a+Math.random()*(b-a);
const pick=arr=>arr[(Math.random()*arr.length)|0];
const easeOut=x=>1-Math.pow(1-x,3);
const easeOutBack=x=>{const c1=1.70158,c3=c1+1;return 1+c3*Math.pow(x-1,3)+c1*Math.pow(x-1,2);};

const COLS=12, LEFT=40, TOP=86, GAP=4;
const BW=(W-2*LEFT-(COLS-1)*GAP)/COLS;
const BH=26, ROWH=32;
const CEIL=66;
const PADDLE_Y=H-52, PADDLE_H=16, PADDLE_BASE=132;

/* ============================ AUDIO ============================ */
let AC=null, muted=false;
function ac(){
  if(!AC){ try{ AC=new (window.AudioContext||window.webkitAudioContext)(); }catch(e){ AC=null; } }
  if(AC && AC.state==='suspended'){ AC.resume(); }
  return AC;
}
function tone(freq,dur,type,vol,slideTo){
  if(muted) return; const a=ac(); if(!a) return;
  const t=a.currentTime, o=a.createOscillator(), g=a.createGain();
  o.type=type||'square';
  o.frequency.setValueAtTime(freq,t);
  if(slideTo) o.frequency.exponentialRampToValueAtTime(Math.max(30,slideTo), t+dur);
  g.gain.setValueAtTime(vol||0.05,t);
  g.gain.exponentialRampToValueAtTime(0.0001,t+dur);
  o.connect(g); g.connect(a.destination);
  o.start(t); o.stop(t+dur+0.02);
}
function noiseBurst(dur,vol,hp){
  if(muted) return; const a=ac(); if(!a) return;
  const len=Math.floor(a.sampleRate*dur);
  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 src=a.createBufferSource(); src.buffer=buf;
  const g=a.createGain(); g.gain.value=vol||0.14;
  const f=a.createBiquadFilter(); f.type='highpass'; f.frequency.value=hp||500;
  src.connect(f); f.connect(g); g.connect(a.destination); src.start();
}
const sfx={
  paddle(){ tone(220,0.06,'square',0.05,340); },
  wall(){ tone(520,0.04,'triangle',0.035,440); },
  brick(c){ tone(560+c*40,0.07,'square',0.05,900+c*60); },
  hard(){ tone(180,0.06,'sawtooth',0.05,120); },
  boom(){ noiseBurst(0.35,0.18,300); tone(90,0.3,'sawtooth',0.07,40); },
  power(){ tone(660,0.12,'square',0.05,1320); setTimeout(()=>tone(990,0.12,'square',0.05,1650),70); },
  laser(){ tone(1400,0.07,'sawtooth',0.04,400); },
  lose(){ tone(300,0.5,'sawtooth',0.07,60); },
  clear(){ [523,659,784,1046].forEach((f,i)=>setTimeout(()=>tone(f,0.22,'square',0.06),i*110)); },
  over(){ [440,330,262,196].forEach((f,i)=>setTimeout(()=>tone(f,0.35,'triangle',0.07),i*170)); },
  launch(){ tone(400,0.1,'square',0.05,760); }
};

/* ============================ LEVELS ============================ */
const LEVELS=[
{name:"First Contact", spd:6.4, pal:["#ff4d8d","#ff7a4d","#ffd166"], map:[
"111111111111",
"111111111111",
"111111111111",
"111111111111",
"111111111111"]},
{name:"Checkerboard", spd:6.9, pal:["#4dc9ff","#5c7cff","#a25cff"], map:[
"1.1.1.1.1.1.",
".1.1.1.1.1.1",
"1.2.1.2.1.2.",
".1.1.1.1.1.1",
"1.1.1.1.1.1.",
"111111111111"]},
{name:"The Pyramid", spd:7.3, pal:["#7bff6a","#ffe14d","#ff9b3d"], map:[
"....1111....",
"...112211...",
"..11222211..",
".1122112211.",
"112211112211",
"111111111111"]},
{name:"Blast Zone", spd:7.7, pal:["#ff5cc8","#ff8ae0","#ffd6f2"], map:[
"1X11111111X1",
"11111X111111",
"11X111111X11",
"111111111111",
"2.2.2.2.2.2.",
".2.2.2.2.2.2"]},
{name:"The Fortress", spd:8.2, pal:["#ffd166","#ff9b3d","#ff5c5c"], map:[
"SS11111111SS",
"S1222222221S",
"S12XS11SX21S",
"S1222222221S",
"SS11111111SS",
".1111111111."]},
{name:"Final Stand", spd:8.8, pal:["#66ffe0","#4dc9ff","#7c5cff"], map:[
"333333333333",
"3X3233323X33",
"333333333333",
"222222222222",
"X2222222222X",
"111111111111",
"111111111111"]}
];
const TYPE={
  '1':{hp:1,pts:50,color:null},
  '2':{hp:2,pts:90,color:null},
  '3':{hp:3,pts:140,color:null},
  'X':{hp:1,pts:80,color:'#ff7a1a'},
  'S':{hp:99,pts:0,color:'#8d99b5',steel:true}
};

/* ============================ STATE ============================ */
let state='menu';
let t=0, levelT=0, clearT=0, bannerT=0;
let score=0, hi=0, lives=3, levelIndex=0, combo=1, chainDepth=0;
let shake=0, shakeX=0, shakeY=0, flashScreen=0, slowT=0, slowMul=1;

try{ hi = parseInt(localStorage.getItem('neon_breakout_hi')||'0',10)||0; }catch(e){ hi=0; }

const paddle={
  x:W/2, w:PADDLE_BASE, targetW:PADDLE_BASE, vx:0, prevX:W/2,
  squash:0, flash:0, laser:0, cool:0, wide:0
};
let balls=[], bricks=[], powerups=[], particles=[], texts=[], lasers=[], stars=[];
let bestCombo=1;

for(let i=0;i<90;i++) stars.push({x:Math.random()*W,y:Math.random()*H,r:Math.random()*1.4+.3,p:Math.random()*6.28,s:rnd(.6,1.6)});

const keys={};

/* ============================ LEVEL LOADING ============================ */
function loadLevel(i){
  const L=LEVELS[i];
  bricks=[]; powerups=[]; lasers=[]; particles=[]; texts=[];
  combo=1; slowT=0; slowMul=1;
  levelT=0;
  const rows=L.map.length;
  for(let r=0;r<rows;r++){
    const line=L.map[r];
    for(let c=0;c<COLS;c++){
      const ch=line[c]||'.';
      if(ch==='.') continue;
      const def=TYPE[ch];
      bricks.push({
        x:LEFT+c*(BW+GAP), y:TOP+r*ROWH, w:BW, h:BH,
        col:c, row:r, type:ch,
        hp:def.hp, maxHp:def.hp, pts:def.pts, steel:!!def.steel,
        color: def.color || L.pal[r % L.pal.length],
        alive:true, flash:0, delay:r*0.055 + c*0.014
      });
    }
  }
  paddle.w=PADDLE_BASE; paddle.targetW=PADDLE_BASE;
  paddle.x=W/2; paddle.prevX=W/2; paddle.laser=0; paddle.wide=0; paddle.cool=0;
  spawnBall(true);
  bannerT=1.9;
}
function spawnBall(attached){
  balls=[{x:paddle.x, y:paddle.y-paddle.h/2-10, a:-Math.PI/2, spd:(LEVELS[levelIndex].spd+0.6)*60,
          r:8, attached:!!attached, trail:[], hitP:0}];
}
function startGame(){
  score=0; lives=3; levelIndex=0; bestCombo=1;
  loadLevel(0);
  state='play';
}

/* ============================ FX ============================ */
function burst(x,y,color,n,speed,grav){
  n=n||14; speed=speed||260;
  for(let i=0;i<n;i++){
    const a=Math.random()*Math.PI*2, s=rnd(speed*.25,speed);
    particles.push({x,y,vx:Math.cos(a)*s,vy:Math.sin(a)*s,life:1,dec:rnd(1.1,2.1),
      color,size:rnd(2,5.5),grav:grav===undefined?420:grav});
  }
}
function ring(x,y,color,n){
  n=n||18;
  for(let i=0;i<n;i++){
    const a=(i/n)*Math.PI*2;
    particles.push({x,y,vx:Math.cos(a)*rnd(260,420),vy:Math.sin(a)*rnd(260,420),
      life:1,dec:2.4,color,size:rnd(2,4),grav:0});
  }
}
function popup(x,y,txt,color,size){
  texts.push({x,y,txt,color:color||'#ffffff',size:size||18,life:1});
}
function addShake(v){ shake=Math.min(26,shake+v); }
function saveHi(){ if(score>hi){ hi=score; try{localStorage.setItem('neon_breakout_hi',String(hi));}catch(e){} } }

/* ============================ GAMEPLAY ============================ */
function launchBalls(){
  let did=false;
  for(const b of balls) if(b.attached){ b.attached=false; b.a=-Math.PI/2+rnd(-0.28,0.28); did=true; }
  if(did) sfx.launch();
  return did;
}
function fireLaser(){
  if(paddle.laser<=0 || paddle.cool>0) return;
  paddle.cool=0.20;
  const y=paddle.y-paddle.h/2;
  lasers.push({x:paddle.x-paddle.w/2+14,y,vy:-900});
  lasers.push({x:paddle.x+paddle.w/2-14,y,vy:-900});
  sfx.laser(); addShake(1.6);
}
function reflectAngle(a, axis){
  if(axis==='x') a=Math.PI-a; else a=-a;
  let s=Math.sin(a), c=Math.cos(a);
  if(Math.abs(s)<0.30) s = (s>=0?0.30:-0.30);
  const len=Math.hypot(s,c); s/=len; c/=len;
  return Math.atan2(s,c);
}
function damageBrick(b, amount, deep){
  if(!b.alive || b.steel) return;
  b.hp-=amount;
  b.flash=1;
  if(b.hp>0){
    sfx.hard();
    burst(b.x+b.w/2,b.y+b.h/2,'#ffffff',5,160,300);
    return;
  }
  destroyBrick(b, deep);
}
function destroyBrick(b, deep){
  if(!b.alive) return;
  b.alive=false;
  const cx=b.x+b.w/2, cy=b.y+b.h/2;
  const gain=b.pts*combo;
  score+=gain;
  popup(cx,cy,'+'+gain, combo>1?'#ffd166':'#ffffff', combo>1?22:17);
  if(combo>1) popup(cx,cy+18,'COMBO x'+combo,'#ff8ae0',14);
  burst(cx,cy,b.color, b.type==='X'?30:16, b.type==='X'?420:300, 500);
  if(b.type==='X'){
    ring(cx,cy,'#ffb347',22);
    sfx.boom(); addShake(9); flashScreen=Math.max(flashScreen,.35);
    if((deep||0)<3){
      for(const n of bricks){
        if(!n.alive||n.steel) continue;
        const dx=Math.abs((n.x+n.w/2)-cx), dy=Math.abs((n.y+n.h/2)-cy);
        if(dx < BW+GAP+2 && dy < ROWH+2){
          n.hp=1; n.flash=1;
          setTimeout(((bb)=>()=>{ if(bb.alive) destroyBrick(bb,(deep||0)+1); })(n), 70);
        }
      }
    }
  } else {
    sfx.brick(Math.min(6,Math.floor(b.row)));
    addShake(2.2);
  }
  if(Math.random()<0.13) dropPowerup(cx,cy);
  combo=Math.min(combo+1,12);
  bestCombo=Math.max(bestCombo,combo);
  checkClear();
}
function checkClear(){
  if(bricks.some(b=>b.alive && !b.steel)){
    return;
  }
  const bonus=400+levelIndex*250+(lives*100);
  score+=bonus;
  saveHi();
  state='clear'; clearT=2.4;
  powerups=[]; lasers=[];
  ring(W/2,H/2,'#7bff6a',40);
  burst(W/2,H/2,'#ffd166',60,520,300);
  addShake(14); flashScreen=.5;
  sfx.clear();
}
const PU_TYPES=[
  {k:'W',label:'WIDE',   color:'#4dc9ff'},
  {k:'M',label:'MULTI',  color:'#ff4d8d'},
  {k:'S',label:'SLOW',   color:'#7bff6a'},
  {k:'L',label:'LASER',  color:'#ffd166'},
  {k:'+',label:'LIFE',   color:'#ff8ae0'}
];
function dropPowerup(x,y){
  const def=pick(PU_TYPES);
  powerups.push({x,y,vy:170,type:def,r:15,rot:0});
}
function applyPowerup(p){
  sfx.power();
  popup(paddle.x, paddle.y-40, p.type.label, p.type.color, 22);
  ring(p.x,p.y,p.type.color,16);
  switch(p.type.k){
    case 'W': paddle.wide=13; paddle.targetW=214; break;
    case 'S': slowT=9; slowMul=0.68; break;
    case 'L': paddle.laser=11; break;
    case '+': lives=Math.min(6,lives+1); break;
    case 'M': {
      const add=[];
      for(const b of balls){
        if(b.attached) continue;
        if(balls.length+add.length>=8) break;
        add.push({x:b.x,y:b.y,a:b.a-0.42,spd:b.spd,r:b.r,attached:false,trail:[],hitP:0});
        if(balls.length+add.length<8)
          add.push({x:b.x,y:b.y,a:b.a+0.42,spd:b.spd,r:b.r,attached:false,trail:[],hitP:0});
      }
      balls=balls.concat(add);
      addShake(5);
      break;
    }
  }
}
function loseLife(){
  lives--; combo=1; slowT=0; slowMul=1;
  paddle.laser=0; paddle.wide=0; paddle.targetW=PADDLE_BASE;
  powerups=[]; lasers=[];
  addShake(18); flashScreen=.4;
  sfx.lose();
  burst(paddle.x, paddle.y, '#ff4d8d', 34, 420, 500);
  if(lives<=0){
    saveHi(); state='over'; sfx.over();
  } else {
    spawnBall(true);
  }
}

/* ============================ UPDATE ============================ */
function update(dt){
  t+=dt;
  shake=Math.max(0, shake-dt*34);
  shakeX=rnd(-shake,shake); shakeY=rnd(-shake,shake);
  flashScreen=Math.max(0, flashScreen-dt*1.8);
  bannerT=Math.max(0,bannerT-dt);

  // particles / texts (always)
  for(let i=particles.length-1;i>=0;i--){
    const p=particles[i];
    p.x+=p.vx*dt; p.y+=p.vy*dt; p.vy+=p.grav*dt;
    p.life-=p.dec*dt;
    if(p.life<=0) particles.splice(i,1);
  }
  for(let i=texts.length-1;i>=0;i--){
    const x=texts[i]; x.y-=34*dt; x.life-=dt*1.25;
    if(x.life<=0) texts.splice(i,1);
  }
  for(const b of bricks) if(b.flash>0) b.flash=Math.max(0,b.flash-dt*3.4);

  if(state==='clear'){
    clearT-=dt;
    if(clearT<=0){
      levelIndex++;
      if(levelIndex>=LEVELS.length){ state='win'; saveHi(); }
      else loadLevel(levelIndex);
    }
    return;
  }
  if(state!=='play') return;

  levelT+=dt;

  // paddle width animation
  paddle.w += (paddle.targetW-paddle.w)*Math.min(1,dt*9);
  paddle.x = clamp(paddle.x, paddle.w/2+4, W-paddle.w/2-4);
  paddle.squash=Math.max(0,paddle.squash-dt*4.5);
  paddle.flash=Math.max(0,paddle.flash-dt*4);
  paddle.cool=Math.max(0,paddle.cool-dt);
  if(paddle.laser>0){ paddle.laser-=dt; if(paddle.laser<=0){paddle.laser=0; popup(paddle.x,paddle.y-46,'LASER OFF','#8899cc',14);} }
  if(paddle.wide>0){ paddle.wide-=dt; if(paddle.wide<=0){paddle.wide=0; paddle.targetW=PADDLE_BASE;} }
  if(slowT>0){ slowT-=dt; if(slowT<=0){ slowT=0; slowMul=1; popup(W/2,H/2-60,'SPEED UP','#ff8a5c',20);} }

  // keyboard paddle
  let dir=0;
  if(keys['ArrowLeft']||keys['a']||keys['A']) dir-=1;
  if(keys['ArrowRight']||keys['d']||keys['D']) dir+=1;
  if(dir!==0){
    paddle.x += dir*760*dt;
    paddle.x = clamp(paddle.x, paddle.w/2+4, W-paddle.w/2-4);
  }
  paddle.vx=(paddle.x-paddle.prevX)/Math.max(dt,0.0001);
  paddle.prevX=paddle.x;

  // powerups
  for(let i=powerups.length-1;i>=0;i--){
    const p=powerups[i];
    p.y+=p.vy*dt; p.rot+=dt*3;
    if(p.y>H+30){ powerups.splice(i,1); continue; }
    if(p.y+p.r>paddle.y-paddle.h/2 && p.y-p.r<paddle.y+paddle.h/2 &&
       p.x>paddle.x-paddle.w/2-p.r && p.x<paddle.x+paddle.w/2+p.r){
      applyPowerup(p); powerups.splice(i,1);
    }
  }

  // lasers
  for(let i=lasers.length-1;i>=0;i--){
    const l=lasers[i]; l.y+=l.vy*dt;
    if(l.y<CEIL-20){ lasers.splice(i,1); continue; }
    let hit=null;
    for(const b of bricks){
      if(!b.alive) continue;
      if(l.x>b.x && l.x<b.x+b.w && l.y<b.y+b.h && l.y>b.y){ hit=b; break; }
    }
    if(hit){
      burst(l.x,hit.y+hit.h,'#ffd166',8,240,300);
      damageBrick(hit,1,0);
      lasers.splice(i,1);
    }
  }

  // balls
  let alive=0;
  for(const b of balls){
    if(b.attached){
      b.x=paddle.x; b.y=paddle.y-paddle.h/2-b.r-1;
      b.hitP=0;
      alive++;
      continue;
    }
    alive++;
    const eff=b.spd*slowMul;
    b.x+=Math.cos(b.a)*eff*dt;
    b.y+=Math.sin(b.a)*eff*dt;
    b.hitP=Math.max(0,b.hitP-dt*4);

    b.trail.push({x:b.x,y:b.y});
    if(b.trail.length>15) b.trail.shift();

    // walls
    if(b.x<b.r){ b.x=b.r; b.a=reflectAngle(b.a,'x'); sfx.wall(); burst(b.x,b.y,'#4dc9ff',5,150,200); }
    else if(b.x>W-b.r){ b.x=W-b.r; b.a=reflectAngle(b.a,'x'); sfx.wall(); burst(b.x,b.y,'#4dc9ff',5,150,200); }
    if(b.y<CEIL+b.r){ b.y=CEIL+b.r; b.a=reflectAngle(b.a,'y'); sfx.wall(); burst(b.x,b.y,'#4dc9ff',5,150,200); }

    // paddle
    const py=paddle.y-paddle.h/2;
    if(Math.sin(b.a)>0 && b.y+b.r>=py-2 && b.y-b.r<paddle.y+paddle.h &&
       b.x>paddle.x-paddle.w/2-b.r && b.x<paddle.x+paddle.w/2+b.r){
      b.y=py-b.r-0.5;
      const off=clamp((b.x-paddle.x)/(paddle.w/2),-1,1);
      b.a=-Math.PI/2 + off*1.06 + clamp(paddle.vx*0.00016,-0.22,0.22);
      b.spd=Math.min(b.spd*1.012, 900);
      b.hitP=1;
      combo=1;
      paddle.squash=1; paddle.flash=1;
      sfx.paddle();
      burst(b.x,py,'#7cff9b',10,240,300);
      addShake(3.2);
    }

    // bricks
    for(const br of bricks){
      if(!br.alive) continue;
      const cx=br.x+br.w/2, cy=br.y+br.h/2;
      const ox=(br.w/2+b.r)-Math.abs(b.x-cx);
      const oy=(br.h/2+b.r)-Math.abs(b.y-cy);
      if(ox>0 && oy>0){
        if(ox<oy){
          b.x += (b.x<cx?-1:1)*ox;
          b.a=reflectAngle(b.a,'x');
        } else {
          b.y += (b.y<cy?-1:1)*oy;
          b.a=reflectAngle(b.a,'y');
        }
        b.hitP=1;
        if(br.steel){
          sfx.hard(); burst(b.x,b.y,'#c9d4ff',6,200,300); addShake(2);
        } else {
          damageBrick(br,1,0);
        }
        break;
      }
    }
  }
  balls=balls.filter(b=>b.y<H+b.r*3);
  if(alive>0 && balls.length===0) loseLife();
  else if(alive===0 && balls.length===0) loseLife();
}

/* ============================ DRAW HELPERS ============================ */
function rr(x,y,w,h,r){
  r=Math.min(r,w/2,h/2);
  ctx.beginPath();
  ctx.moveTo(x+r,y);
  ctx.arcTo(x+w,y,x+w,y+h,r);
  ctx.arcTo(x+w,y+h,x,y+h,r);
  ctx.arcTo(x,y+h,x,y,r);
  ctx.arcTo(x,y,x+w,y,r);
  ctx.closePath();
}
function text(str,x,y,size,color,align,weight){
  ctx.font=(weight||700)+' '+size+'px ui-monospace, "SF Mono", Menlo, Consolas, monospace';
  ctx.fillStyle=color||'#fff';
  ctx.textAlign=align||'left';
  ctx.textBaseline='middle';
  ctx.fillText(str,x,y);
}
function glowText(str,x,y,size,color,align,blur){
  ctx.save();
  ctx.shadowColor=color; ctx.shadowBlur=blur||22;
  text(str,x,y,size,color,align,800);
  ctx.restore();
}

/* ============================ RENDER ============================ */
function render(){
  ctx.save();
  ctx.clearRect(0,0,W,H);

  // background
  const bg=ctx.createLinearGradient(0,0,0,H);
  bg.addColorStop(0,'#0b1026'); bg.addColorStop(.55,'#080b1a'); bg.addColorStop(1,'#04050c');
  ctx.fillStyle=bg; ctx.fillRect(0,0,W,H);

  // stars
  for(const s of stars){
    const a=0.25+0.35*Math.sin(t*s.s+s.p);
    ctx.fillStyle='rgba(160,190,255,'+a.toFixed(3)+')';
    ctx.fillRect(s.x,s.y,s.r,s.r);
  }
  // grid
  ctx.strokeStyle='rgba(90,140,255,0.045)'; ctx.lineWidth=1;
  ctx.beginPath();
  for(let x=0;x<=W;x+=45){ ctx.moveTo(x+.5,CEIL); ctx.lineTo(x+.5,H); }
  for(let y=CEIL;y<=H;y+=45){ ctx.moveTo(0,y+.5); ctx.lineTo(W,y+.5); }
  ctx.stroke();

  ctx.save();
  ctx.translate(shakeX,shakeY);

  // ceiling line
  const cg=ctx.createLinearGradient(0,CEIL-4,0,CEIL+4);
  cg.addColorStop(0,'rgba(120,170,255,0)');
  cg.addColorStop(.5,'rgba(120,170,255,.55)');
  cg.addColorStop(1,'rgba(120,170,255,0)');
  ctx.fillStyle=cg; ctx.fillRect(0,CEIL-5,W,10);

  drawBricks();
  drawPowerups();
  drawLasers();
  if(state==='play'||state==='clear'||state==='pause'||state==='over'||state==='win') drawPaddle();
  drawBalls();
  drawParticles();
  drawTexts();

  ctx.restore(); // shake

  drawHUD();

  if(flashScreen>0){
    ctx.fillStyle='rgba(255,255,255,'+(flashScreen*0.5).toFixed(3)+')';
    ctx.fillRect(0,0,W,H);
  }

  drawOverlays();
  ctx.restore();
}

function drawBricks(){
  for(const b of bricks){
    if(!b.alive) continue;
    const prog=clamp((levelT-b.delay)/0.35,0,1);
    if(prog<=0) continue;
    const e=easeOutBack(prog);
    const cx=b.x+b.w/2, cy=b.y+b.h/2;
    ctx.save();
    ctx.globalAlpha=prog;
    ctx.translate(cx,cy); ctx.scale(e,e); ctx.translate(-cx,-cy);

    let col=b.color;
    if(b.steel){
      const g=ctx.createLinearGradient(b.x,b.y,b.x,b.y+b.h);
      g.addColorStop(0,'#c8d2ea'); g.addColorStop(.5,'#8d99b5'); g.addColorStop(1,'#5d6780');
      ctx.fillStyle=g;
    } else {
      const g=ctx.createLinearGradient(b.x,b.y,b.x,b.y+b.h);
      g.addColorStop(0, shade(col, .35));
      g.addColorStop(.5, col);
      g.addColorStop(1, shade(col, -.32));
      ctx.fillStyle=g;
    }
    ctx.shadowColor=col; ctx.shadowBlur= b.type==='X'?18:10;
    rr(b.x,b.y,b.w,b.h,6); ctx.fill();
    ctx.shadowBlur=0;

    // top highlight
    ctx.fillStyle='rgba(255,255,255,.30)';
    rr(b.x+3,b.y+3,b.w-6,4,3); ctx.fill();
    // inner outline
    ctx.strokeStyle='rgba(255,255,255,.18)'; ctx.lineWidth=1;
    rr(b.x+.5,b.y+.5,b.w-1,b.h-1,6); ctx.stroke();

    // damage cracks
    const dmg=b.maxHp>1 && b.maxHp<90 ? (b.maxHp-b.hp)/b.maxHp : 0;
    if(dmg>0){
      ctx.fillStyle='rgba(0,0,0,'+(dmg*0.42).toFixed(2)+')';
      rr(b.x,b.y,b.w,b.h,6); ctx.fill();
      ctx.strokeStyle='rgba(255,255,255,.55)'; ctx.lineWidth=1.4;
      ctx.beginPath();
      ctx.moveTo(b.x+b.w*0.32,b.y+4);
      ctx.lineTo(b.x+b.w*0.46,b.y+b.h*0.5);
      ctx.lineTo(b.x+b.w*0.34,b.y+b.h-4);
      if(dmg>0.5){
        ctx.moveTo(b.x+b.w*0.66,b.y+4);
        ctx.lineTo(b.x+b.w*0.56,b.y+b.h*0.55);
        ctx.lineTo(b.x+b.w*0.7,b.y+b.h-4);
      }
      ctx.stroke();
    }
    if(b.type==='X'){
      ctx.fillStyle='rgba(0,0,0,.55)';
      ctx.beginPath(); ctx.arc(cx,cy,7.5,0,6.283); ctx.fill();
      ctx.strokeStyle='#ffd166'; ctx.lineWidth=2;
      ctx.beginPath(); ctx.arc(cx,cy,7.5,0,6.283); ctx.stroke();
      text('✕',cx,cy+.5,11,'#ffd166','center',800);
    }
    if(b.flash>0){
      ctx.globalAlpha=prog*b.flash*0.85;
      ctx.fillStyle='#ffffff';
      rr(b.x,b.y,b.w,b.h,6); ctx.fill();
    }
    ctx.restore();
  }
}
function shade(hex,amt){
  const n=parseInt(hex.slice(1),16);
  let r=(n>>16)&255,g=(n>>8)&255,b=n&255;
  r=clamp(Math.round(r+255*amt),0,255);
  g=clamp(Math.round(g+255*amt),0,255);
  b=clamp(Math.round(b+255*amt),0,255);
  return 'rgb('+r+','+g+','+b+')';
}

function drawPowerups(){
  for(const p of powerups){
    ctx.save();
    ctx.translate(p.x,p.y); ctx.rotate(Math.sin(p.rot)*0.25);
    ctx.shadowColor=p.type.color; ctx.shadowBlur=18;
    ctx.fillStyle=p.type.color;
    rr(-p.r,-p.r,p.r*2,p.r*2,7); ctx.fill();
    ctx.shadowBlur=0;
    ctx.fillStyle='rgba(0,0,0,.75)';
    rr(-p.r+3,-p.r+3,p.r*2-6,p.r*2-6,5); ctx.fill();
    ctx.fillStyle=p.type.color;
    text(p.type.k,0,1,17,p.type.color,'center',800);
    ctx.restore();
  }
}
function drawLasers(){
  for(const l of lasers){
    const g=ctx.createLinearGradient(l.x-4,l.y,l.x+4,l.y);
    g.addColorStop(0,'rgba(255,209,102,0)');
    g.addColorStop(.5,'#fff6d6');
    g.addColorStop(1,'rgba(255,209,102,0)');
    ctx.fillStyle=g;
    ctx.shadowColor='#ffd166'; ctx.shadowBlur=14;
    ctx.fillRect(l.x-4,l.y,8,26);
    ctx.shadowBlur=0;
  }
}
function drawPaddle(){
  const s=paddle.squash;
  const sx=1-0.14*s, sy=1+0.35*s;
  const w=paddle.w*sx, h=PADDLE_H*sy;
  const x=paddle.x-w/2, y=paddle.y-h/2;

  const active = paddle.laser>0 || paddle.wide>0;
  const base = active? '#ffd166' : '#4dc9ff';
  ctx.save();
  ctx.shadowColor=base; ctx.shadowBlur=24;
  const g=ctx.createLinearGradient(x,y,x,y+h);
  g.addColorStop(0,'#ffffff');
  g.addColorStop(.35, base);
  g.addColorStop(1, shade(base,-.4));
  ctx.fillStyle=g;
  rr(x,y,w,h,8); ctx.fill();
  ctx.shadowBlur=0;

  ctx.fillStyle='rgba(255,255,255,.75)';
  rr(x+6,y+3,w-12,3.5,2); ctx.fill();

  ctx.strokeStyle='rgba(255,255,255,.35)'; ctx.lineWidth=1;
  rr(x+.5,y+.5,w-1,h-1,8); ctx.stroke();

  if(paddle.flash>0){
    ctx.globalAlpha=paddle.flash*0.8;
    ctx.fillStyle='#fff'; rr(x,y,w,h,8); ctx.fill();
    ctx.globalAlpha=1;
  }
  if(paddle.laser>0){
    ctx.fillStyle='#ffd166';
    rr(x+8,y-6,10,8,2); ctx.fill();
    rr(x+w-18,y-6,10,8,2); ctx.fill();
  }
  ctx.restore();
}
function drawBalls(){
  for(const b of balls){
    // trail
    for(let i=0;i<b.trail.length;i++){
      const p=b.trail[i], k=i/b.trail.length;
      ctx.globalAlpha=k*0.34;
      ctx.fillStyle='#7cffd0';
      ctx.beginPath(); ctx.arc(p.x,p.y,b.r*k*0.9,0,6.283); ctx.fill();
    }
    ctx.globalAlpha=1;

    if(b.attached && state==='play'){
      ctx.save();
      ctx.setLineDash([6,8]);
      ctx.strokeStyle='rgba(124,255,208,.35)'; ctx.lineWidth=2;
      ctx.beginPath(); ctx.moveTo(b.x,b.y); ctx.lineTo(b.x,CEIL+6); ctx.stroke();
      ctx.restore();
    }

    ctx.save();
    ctx.shadowColor='#7cffd0'; ctx.shadowBlur=22;
    const g=ctx.createRadialGradient(b.x-2.5,b.y-3,1,b.x,b.y,b.r+1);
    g.addColorStop(0,'#ffffff'); g.addColorStop(.55,'#c9fff0'); g.addColorStop(1,'#39d9b0');
    ctx.fillStyle=g;
    ctx.beginPath(); ctx.arc(b.x,b.y,b.r*(1+b.hitP*0.35),0,6.283); ctx.fill();
    ctx.restore();
  }
}
function drawParticles(){
  for(const p of particles){
    ctx.globalAlpha=clamp(p.life,0,1);
    ctx.fillStyle=p.color;
    ctx.fillRect(p.x-p.size/2,p.y-p.size/2,p.size,p.size);
  }
  ctx.globalAlpha=1;
}
function drawTexts(){
  for(const x of texts){
    ctx.globalAlpha=clamp(x.life,0,1);
    ctx.save();
    ctx.shadowColor=x.color; ctx.shadowBlur=12;
    text(x.txt,x.x,x.y,x.size,x.color,'center',800);
    ctx.restore();
  }
  ctx.globalAlpha=1;
}

function drawHUD(){
  ctx.fillStyle='rgba(255,255,255,.035)';
  ctx.fillRect(0,0,W,54);
  ctx.fillStyle='rgba(120,170,255,.18)';
  ctx.fillRect(0,53,W,1);

  text('SCORE',20,17,11,'#6d7fb8','left',700);
  glowText(String(score).padStart(6,'0'),20,38,24,'#ffffff','left',10);
  text('HI '+String(Math.max(hi,score)).padStart(6,'0'),150,38,15,'#7f92cc','left',700);

  const L=LEVELS[Math.min(levelIndex,LEVELS.length-1)];
  text('LEVEL '+(Math.min(levelIndex+1,LEVELS.length))+'  •  '+L.name, W/2, 38, 16, '#a9c0ff','center',700);
  text('LIVES', W-190, 17, 11,'#6d7fb8','left',700);
  for(let i=0;i<lives;i++){
    const x=W-190+i*24;
    ctx.fillStyle= i===0? '#ff4d8d':'#4dc9ff';
    ctx.shadowColor=ctx.fillStyle; ctx.shadowBlur=8;
    rr(x,30,18,7,3); ctx.fill();
    ctx.shadowBlur=0;
  }

  if(combo>1 && state==='play'){
    ctx.save();
    const a=clamp((combo-1)/4,0,1);
    glowText('COMBO ×'+combo, W/2, CEIL+16, 20+combo*0.6, '#ff8ae0','center', 16+a*20);
    ctx.restore();
  }
  if(slowT>0){
    text('SLOW', W-70, 38, 13, '#7bff6a','center',800);
  }
  if(paddle.laser>0){
    text('LASER '+paddle.laser.toFixed(1), W-70, 17, 12, '#ffd166','center',800);
  }
  if(paddle.wide>0){
    text('WIDE', W-70, 55+0, 0, 'transparent','center',800);
  }
}

function panel(alpha){
  ctx.fillStyle='rgba(4,6,14,'+alpha+')';
  ctx.fillRect(0,0,W,H);
}
function drawOverlays(){
  if(state==='menu'){
    panel(.72);
    ctx.save();
    const pulse=1+Math.sin(t*2.4)*0.02;
    ctx.translate(W/2,H/2-70); ctx.scale(pulse,pulse);
    const g=ctx.createLinearGradient(-260,0,260,0);
    g.addColorStop(0,'#ff4d8d'); g.addColorStop(.5,'#ffd166'); g.addColorStop(1,'#4dc9ff');
    ctx.shadowColor='#5c8cff'; ctx.shadowBlur=40;
    ctx.font='800 74px ui-monospace, "SF Mono", Menlo, Consolas, monospace';
    ctx.textAlign='center'; ctx.textBaseline='middle';
    ctx.fillStyle=g;
    ctx.fillText('NEON BREAKOUT',0,0);
    ctx.shadowBlur=0;
    ctx.restore();

    text('6 LEVELS  •  POWER-UPS  •  COMBO MULTIPLIER  •  EXPLOSIVE BRICKS', W/2, H/2-8, 14, '#8fa5e0','center',700);

    const blink=0.55+0.45*Math.sin(t*4.5);
    ctx.globalAlpha=blink;
    glowText('CLICK OR PRESS SPACE TO START', W/2, H/2+60, 26, '#7cffd0','center',18);
    ctx.globalAlpha=1;

    text('MOUSE  /  ← →  /  A D   to move', W/2, H/2+120, 15, '#9fb2e6','center',700);
    text('SPACE to launch & fire   •   P pause   •   M mute', W/2, H/2+148, 15, '#9fb2e6','center',700);
    text('HIGH SCORE  '+String(hi).padStart(6,'0'), W/2, H/2+200, 16, '#ffd166','center',800);
  }
  else if(state==='pause'){
    panel(.6);
    glowText('PAUSED', W/2, H/2-16, 56, '#4dc9ff','center',30);
    text('Press P to resume', W/2, H/2+42, 18, '#9fb2e6','center',700);
  }
  else if(state==='clear'){
    const k=clamp((2.4-clearT)/0.3,0,1);
    ctx.save(); ctx.globalAlpha=k;
    panel(.35);
    glowText(levelIndex>=LEVELS.length-1?'ALL LEVELS CLEARED!':'LEVEL CLEAR', W/2, H/2-30, 58, '#7bff6a','center',34);
    const bonus=400+levelIndex*250+(lives*100);
    text('BONUS +'+bonus+'   •   SCORE '+String(score).padStart(6,'0'), W/2, H/2+34, 20, '#ffd166','center',800);
    text(levelIndex>=LEVELS.length-1?'':'Next level incoming…', W/2, H/2+72, 15, '#9fb2e6','center',700);
    ctx.restore();
  }
  else if(state==='over'){
    panel(.78);
    glowText('GAME OVER', W/2, H/2-70, 66, '#ff4d8d','center',34);
    text('SCORE  '+String(score).padStart(6,'0'), W/2, H/2, 30, '#ffffff','center',800);
    text('BEST COMBO ×'+bestCombo+'   •   REACHED LEVEL '+(levelIndex+1), W/2, H/2+44, 16, '#9fb2e6','center',700);
    if(score>=hi && score>0) glowText('NEW HIGH SCORE!', W/2, H/2+84, 22, '#ffd166','center',20);
    else text('HIGH SCORE  '+String(hi).padStart(6,'0'), W/2, H/2+84, 17, '#7f92cc','center',700);
    const blink=0.55+0.45*Math.sin(t*4.5);
    ctx.globalAlpha=blink;
    text('PRESS R OR CLICK TO PLAY AGAIN', W/2, H/2+140, 20, '#7cffd0','center',800);
    ctx.globalAlpha=1;
  }
  else if(state==='win'){
    panel(.7);
    glowText('YOU WIN!', W/2, H/2-80, 72, '#ffd166','center',40);
    for(let i=0;i<3;i++){
      if(Math.random()<0.06) burst(rnd(80,W-80), rnd(80,H-80), pick(['#ff4d8d','#4dc9ff','#7bff6a','#ffd166']), 26, 420, 400);
    }
    text('FINAL SCORE  '+String(score).padStart(6,'0'), W/2, H/2-6, 32, '#ffffff','center',800);
    text('Best combo ×'+bestCombo+'  •  '+lives+' lives left', W/2, H/2+42, 17, '#9fb2e6','center',700);
    glowText('HIGH SCORE  '+String(hi).padStart(6,'0'), W/2, H/2+86, 22, '#7cffd0','center',20);
    const blink=0.55+0.45*Math.sin(t*4.5);
    ctx.globalAlpha=blink;
    text('PRESS R OR CLICK TO PLAY AGAIN', W/2, H/2+150, 20, '#ffd166','center',800);
    ctx.globalAlpha=1;
  }

  // in-game prompts
  if(state==='play'){
    if(bannerT>0){
      const a=clamp(bannerT/0.5,0,1)*clamp((1.9-bannerT)/0.3,0,1);
      ctx.save(); ctx.globalAlpha=a;
      const L=LEVELS[levelIndex];
      glowText('LEVEL '+(levelIndex+1), W/2, H/2-40, 34, '#4dc9ff','center',26);
      text(L.name.toUpperCase(), W/2, H/2+4, 24, '#ffffff','center',800);
      ctx.restore();
    }
    if(balls.length && balls.some(b=>b.attached)){
      const blink=0.55+0.45*Math.sin(t*5);
      ctx.globalAlpha=blink;
      text('PRESS SPACE / CLICK TO LAUNCH', W/2, H-96, 17, '#7cffd0','center',800);
      ctx.globalAlpha=1;
    }
    if(muted){
      text('MUTED (M)', W-24, H-20, 12, '#6d7fb8','right',700);
    }
  }
}

/* ============================ INPUT ============================ */
function canvasPos(e){
  const r=canvas.getBoundingClientRect();
  const cx=(e.touches? e.touches[0].clientX : e.clientX);
  return (cx-r.left)*(W/r.width);
}
canvas.addEventListener('mousemove',e=>{
  if(state==='menu'||state==='over'||state==='win') return;
  paddle.x=clamp(canvasPos(e), paddle.w/2+4, W-paddle.w/2-4);
});
canvas.addEventListener('mousedown',e=>{ ac(); handleClick(); });
canvas.addEventListener('touchstart',e=>{ e.preventDefault(); ac(); paddle.x=clamp(canvasPos(e),paddle.w/2+4,W-paddle.w/2-4); handleClick(); },{passive:false});
canvas.addEventListener('touchmove',e=>{ e.preventDefault(); paddle.x=clamp(canvasPos(e),paddle.w/2+4,W-paddle.w/2-4); },{passive:false});
canvas.addEventListener('touchend',e=>e.preventDefault(),{passive:false});

function handleClick(){
  if(state==='menu'){ startGame(); sfx.launch(); }
  else if(state==='play'){ if(!launchBalls()) fireLaser(); }
  else if(state==='clear'){ clearT=Math.min(clearT,0.05); }
  else if(state==='over'||state==='win'){ startGame(); }
  else if(state==='pause'){ state='play'; }
}

window.addEventListener('keydown',e=>{
  const k=e.key;
  if([' ','ArrowLeft','ArrowRight','ArrowUp','ArrowDown'].includes(k)) e.preventDefault();
  keys[k]=true;
  ac();
  if(k==='p'||k==='P'){ if(state==='play') state='pause'; else if(state==='pause') state='play'; return; }
  if(k==='m'||k==='M'){ muted=!muted; return; }
  if(k==='r'||k==='R'){ if(state==='over'||state==='win'||state==='play'){ startGame(); } return; }
  if(k===' '||k==='Enter'){
    if(state==='menu') startGame();
    else if(state==='play'){ if(!launchBalls()) fireLaser(); }
    else if(state==='clear') clearT=Math.min(clearT,0.05);
    else if(state==='over'||state==='win') startGame();
    else if(state==='pause') state='play';
  }
  if((k==='ArrowLeft'||k==='ArrowRight'||k==='a'||k==='d'||k==='A'||k==='D') && state==='play'){
    // keyboard takes over from mouse
  }
});
window.addEventListener('keyup',e=>{ keys[e.key]=false; });
window.addEventListener('blur',()=>{ if(state==='play') state='pause'; });

/* ============================ LOOP ============================ */
let last=performance.now();
function loop(now){
  let dt=(now-last)/1000; last=now;
  if(dt>0.034) dt=0.034;
  update(dt);
  render();
  requestAnimationFrame(loop);
}
loadLevel(0);
state='menu';
requestAnimationFrame(loop);

})();
</script>
</body>
</html>

Compare

Other runs