• Updated 25 Nov, 00:22 UTC
  • Next run 25 Nov, 05:17 UTCNext 25 Nov 05:17
  • Last 7 days: 6 new models · 62 runs7 d: 6 models · 62 runs
Playable Breakout

MiMo-V2.6-Flash-MOPDXiaomi

Network offOpen alone (new tab)

Run details

Model
xiaomi/mimo-v2.6-flash-mopd
Route
OpenRouter API
Served by
Featherless
Effort
model default
Limits
60 min · 32,768 output tokens (model max)
Date
24 Nov 2026
Time
1 min 39 s
Size
29 kB
Tokens
83 in, 24,650 out (9,821 thinking)
List price
$0.010 at today's price ($0.15 in / $0.42 out per M)
Paid
$0.010

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

29 kB 854 lines Raw

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>BREAKOUT · Juice Edition</title>
<style>
  *{box-sizing:border-box}
  html,body{height:100%;margin:0;background:#05060d;color:#e8ecff;
    font-family:"Trebuchet MS",Verdana,Geneva,sans-serif;overflow:hidden;
    -webkit-user-select:none;user-select:none}
  #app{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;padding:12px}
  #stage{position:relative;width:min(96vw,calc(94vh * 1.3333));aspect-ratio:4/3;
    border-radius:14px;overflow:hidden;
    box-shadow:0 0 70px rgba(70,110,255,.28),0 0 0 2px #1c2440,0 0 0 6px #0b0f1e}
  canvas{display:block;width:100%;height:100%;cursor:crosshair;touch-action:none}
  #hint{font-size:11px;letter-spacing:.2em;text-transform:uppercase;opacity:.5;text-align:center}
  #hint b{color:#7fd7ff;font-weight:normal}
</style>
</head>
<body>
<div id="app">
  <div id="stage"><canvas id="game" width="800" height="600"></canvas></div>
  <div id="hint"><b>&larr; &rarr;</b> / <b>A D</b> / <b>Mouse</b> move &nbsp;·&nbsp; <b>Space</b> / <b>Click</b> launch &nbsp;·&nbsp; <b>P</b> pause &nbsp;·&nbsp; <b>M</b> mute</div>
</div>
<script>
(function(){
"use strict";

/* ============================ CANVAS ============================ */
const cv=document.getElementById('game'), ctx=cv.getContext('2d');
const W=800,H=600;

/* ============================ AUDIO ============================= */
let actx=null,master=null,muted=false,noiseBuf=null;
function initAudio(){
  if(actx) return;
  try{
    actx=new (window.AudioContext||window.webkitAudioContext)();
    master=actx.createGain(); master.gain.value=0.32; master.connect(actx.destination);
    const len=Math.floor(actx.sampleRate*0.6);
    noiseBuf=actx.createBuffer(1,len,actx.sampleRate);
    const d=noiseBuf.getChannelData(0);
    for(let i=0;i<len;i++) d[i]=Math.random()*2-1;
  }catch(e){actx=null;}
}
function resumeAudio(){ if(actx&&actx.state==='suspended') actx.resume(); }
function tone(f1,f2,dur,type,vol){
  if(!actx||muted) return;
  const t=actx.currentTime;
  const o=actx.createOscillator(),g=actx.createGain();
  o.type=type||'square';
  o.frequency.setValueAtTime(f1,t);
  if(f2) o.frequency.exponentialRampToValueAtTime(Math.max(25,f2),t+dur);
  g.gain.setValueAtTime(0.0001,t);
  g.gain.exponentialRampToValueAtTime(vol||0.25,t+0.012);
  g.gain.exponentialRampToValueAtTime(0.0001,t+dur);
  o.connect(g);g.connect(master);o.start(t);o.stop(t+dur+0.03);
}
function noiseB(dur,vol,freq,type){
  if(!actx||muted||!noiseBuf) return;
  const t=actx.currentTime;
  const s=actx.createBufferSource(); s.buffer=noiseBuf;
  const f=actx.createBiquadFilter(); f.type=type||'bandpass';
  f.frequency.value=freq||1500; f.Q.value=0.9;
  const g=actx.createGain();
  g.gain.setValueAtTime(vol||0.25,t);
  g.gain.exponentialRampToValueAtTime(0.0001,t+dur);
  s.connect(f);f.connect(g);g.connect(master);s.start(t);s.stop(t+dur+0.02);
}
const S={
  paddle(){tone(280,540,0.07,'square',0.22);},
  wall(){tone(620,430,0.05,'sine',0.15);},
  brick(c){tone(380+c*38,760+c*55,0.07,'square',0.20); noiseB(0.05,0.12,2400);},
  tough(){tone(190,120,0.09,'sawtooth',0.18); noiseB(0.08,0.18,700);},
  metal(){tone(140,110,0.05,'square',0.12);},
  boom(){noiseB(0.35,0.45,320,'lowpass'); tone(170,38,0.34,'sawtooth',0.28);},
  power(){tone(520,880,0.09,'square',0.22); setTimeout(()=>tone(760,1240,0.12,'square',0.20),70);},
  launch(){tone(220,640,0.10,'triangle',0.22);},
  lose(){tone(320,55,0.65,'sawtooth',0.28); noiseB(0.45,0.2,420,'lowpass');},
  level(){[440,554,659,880].forEach((f,i)=>setTimeout(()=>tone(f,f*1.5,0.16,'square',0.22),i*85));},
  over(){[440,370,294,196].forEach((f,i)=>setTimeout(()=>tone(f,f*0.7,0.3,'sawtooth',0.22),i*140));},
  combo(n){tone(520+n*55,940+n*70,0.06,'triangle',0.18);}
};

/* ============================ LEVELS ============================ */
const LEVELS=[
[
".............",
".11111111111.",
".11111111111.",
".22222222222.",
".22222222222.",
".33333333333.",
".33333333333."
],
[
".....111.....",
"....11111....",
"...1111111...",
"..111111111..",
".11111111111.",
"..222222222..",
"...2222222...",
"....22222....",
".....222....."
],
[
".T111111111T.",
".11B11111B11.",
".11111111111.",
".22222222222.",
".2B2222222B2.",
".22222222222.",
".33333333333."
],
[
"1.1.1.1.1.1.1",
".T.T.T.T.T.T.",
"2.2.2.2.2.2.2",
".B.B.B.B.B.B.",
"3.3.3.3.3.3.3",
".4.4.4.4.4.4.",
"4.4.4.4.4.4.4"
],
[
"XXXXXXXXXXXXX",
"X11111111111X",
"X1B222222B11X",
"X11111111111X",
"X22222222222X",
"X2B333333B22X",
"X22222222222X"
],
[
".5.5.5.5.5.5.",
"5555555555555",
".B.B.B.B.B.B.",
"4444444444444",
".T.T.T.T.T.T.",
"3333333333333",
".2.2.2.2.2.2.",
"2222222222222",
".1.1.1.1.1.1.",
"1111111111111"
]
];
const COLORS=['#ff4d6d','#ff9f1c','#ffd166','#06d6a0','#4cc9f0','#b388ff'];

/* ============================ CONFIG ============================ */
const COLS=13,MARGIN=40,HGAP=6,VGAP=6,TOP=78,BH=22;
const BW=(W-MARGIN*2-HGAP*(COLS-1))/COLS;

const PU=[
  {k:'E',c:'#4cc9f0',n:'WIDE PADDLE'},
  {k:'M',c:'#06d6a0',n:'MULTIBALL'},
  {k:'S',c:'#ffd166',n:'SLOW MOTION'},
  {k:'D',c:'#b388ff',n:'ROW BLAST'},
  {k:'L',c:'#ff4d6d',n:'EXTRA LIFE'}
];
const PU_W=[30,24,20,14,12];

/* ============================ STATE ============================= */
const G={
  state:'menu', paused:false, t:0, timer:0,
  score:0, best:0, lives:3, level:0, combo:0,
  bricks:[], grid:{}, remain:0,
  balls:[], parts:[], texts:[], pus:[], stars:[],
  paddle:{x:W/2,y:H-46,w:110,h:16,baseW:110,maxW:178,squash:0,timer:0},
  serving:false, shake:0, freeze:0, flash:0, hurt:0,
  speedMul:1, baseSpeed:330, banner:null, mouseMode:false, mouseX:W/2
};
for(let i=0;i<70;i++) G.stars.push({x:Math.random()*W,y:Math.random()*H,s:Math.random()*1.6+.4,v:8+Math.random()*26,p:Math.random()*6.28});

const keys={};

/* ======================== 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 pad6(n){return String(n).padStart(6,'0');}
function shake(n){ if(n>G.shake) G.shake=n; }
function brickAt(r,c){ return G.grid[r+','+c]; }

function burst(x,y,color,n,spd,grav){
  for(let i=0;i<n;i++){
    const a=Math.random()*Math.PI*2, s=spd*(0.25+Math.random()*0.75);
    G.parts.push({x:x,y:y,vx:Math.cos(a)*s,vy:Math.sin(a)*s,
      life:0.45+Math.random()*0.55,max:1,color:color,
      size:1.6+Math.random()*3.4,grav:grav===undefined?300:grav});
  }
  if(G.parts.length>520) G.parts.splice(0,G.parts.length-520);
}
function popup(x,y,txt,color,sc){
  G.texts.push({x:x,y:y,vy:-52,life:1,max:1,txt:txt,color:color,sc:sc||1});
}
function banner(txt,color){
  G.banner={txt:txt,color:color,life:1.5};
}

/* ======================== LEVEL BUILD ========================== */
function buildLevel(i){
  const map=LEVELS[i];
  G.bricks.length=0; G.grid={}; G.remain=0;
  for(let r=0;r<map.length;r++){
    const row=map[r];
    for(let c=0;c<COLS;c++){
      const ch=row[c]||'.';
      if(ch==='.') continue;
      const b={r:r,c:c,x:MARGIN+c*(BW+HGAP),y:TOP+r*(BH+VGAP),w:BW,h:BH,
        alive:true,hp:1,flash:0,pop:0,type:'normal',color:'#fff',metal:false};
      if(ch==='X'){b.type='metal';b.metal=true;b.hp=999;b.color='#7f8bad';}
      else if(ch==='B'){b.type='boom';b.color='#ff9f1c';}
      else if(ch==='T'){b.type='tough';b.hp=2;b.color='#9fb0d0';}
      else {b.color=COLORS[(+ch)-1]||'#fff';}
      if(!b.metal) G.remain++;
      G.bricks.push(b); G.grid[r+','+c]=b;
    }
  }
}

/* ======================== GAME FLOW ============================ */
function startGame(){
  G.score=0;G.lives=3;G.level=0;G.combo=0;G.speedMul=1;
  G.state='play';G.paused=false;G.hurt=0;G.flash=0;
  G.pus.length=0;G.parts.length=0;G.texts.length=0;
  G.paddle.w=G.paddle.baseW;G.paddle.timer=0;
  buildLevel(0); serve();
  banner('LEVEL 1','#4cc9f0');
}
function serve(){
  G.paddleHits=0;
  G.balls=[{x:G.paddle.x,y:G.paddle.y-12,vx:0,vy:0,r:8,trail:[]}];
  G.serving=true;
}
function launch(){
  if(!G.serving||!G.balls.length) return;
  G.serving=false;
  const b=G.balls[0];
  const off=Math.max(-1,Math.min(1,(b.x-G.paddle.x)/(G.paddle.w/2)));
  const ang=-Math.PI/2+off*1.02;
  const sp=G.baseSpeed;
  b.vx=Math.cos(ang)*sp; b.vy=Math.sin(ang)*sp;
  S.launch();
}
function levelClear(){
  if(G.state!=='play') return;
  G.state='levelclear'; G.timer=1.9; G.flash=1;
  G.balls.length=0; G.pus.length=0;
  S.level();
  for(let i=0;i<7;i++)
    setTimeout(()=>{ if(G.state==='levelclear')
      burst(120+Math.random()*(W-240),140+Math.random()*220,
        COLORS[(Math.random()*6)|0],26,300,180); },i*130);
}
function nextLevel(){
  G.level++;
  if(G.level>=LEVELS.length){ G.state='win'; G.best=Math.max(G.best,G.score); S.over(); return; }
  G.combo=0; G.speedMul=1; G.pus.length=0;
  G.paddle.w=G.paddle.baseW; G.paddle.timer=0;
  buildLevel(G.level); serve();
  G.state='play'; G.flash=1;
  banner('LEVEL '+(G.level+1),COLORS[G.level%6]);
}
function loseBall(){
  S.lose(); shake(16); G.hurt=1; G.combo=0; G.speedMul=1;
  G.paddle.w=G.paddle.baseW; G.paddle.timer=0;
  G.lives--;
  burst(G.paddle.x,G.paddle.y,'#ff4d6d',34,300,240);
  if(G.lives<=0){
    G.state='gameover'; G.best=Math.max(G.best,G.score); G.balls.length=0; S.over();
  } else serve();
}

/* ======================== BRICK DAMAGE ========================= */
function damageBrick(b,dmg,chain){
  if(!b||!b.alive) return;
  if(b.metal){
    b.flash=1; b.pop=1; shake(2);
    burst(b.x+b.w/2,b.y+b.h/2,'#cfe0ff',5,120,200);
    S.metal(); return;
  }
  b.hp-=dmg; b.flash=1; b.pop=1;
  if(b.hp<=0){ destroyBrick(b,chain); }
  else{
    S.tough(); shake(2.5);
    burst(b.x+b.w/2,b.y+b.h/2,'#cfe0ff',8,150,240);
  }
}
function destroyBrick(b,chain){
  if(!b.alive) return;
  b.alive=false;
  if(!b.metal) G.remain--;
  G.combo++;
  const mult=1+Math.min(7,Math.floor(G.combo/3));
  const base=b.type==='boom'?120:(b.type==='tough'?150:50);
  const pts=base*mult;
  G.score+=pts;
  popup(b.x+b.w/2,b.y+b.h/2,'+'+pts,b.color,mult>1?1.2:1);
  if(mult>1) S.combo(mult);
  if(b.type==='boom'){
    G.freeze=Math.max(G.freeze,0.055); shake(11);
    burst(b.x+b.w/2,b.y+b.h/2,'#ffd166',30,340,180);
    burst(b.x+b.w/2,b.y+b.h/2,'#ff9f1c',22,240,140);
    S.boom();
    for(let dr=-1;dr<=1;dr++)for(let dc=-1;dc<=1;dc++){
      if(!dr&&!dc) continue;
      const nb=brickAt(b.r+dr,b.c+dc);
      if(nb&&nb.alive) damageBrick(nb,1,true);
    }
  }else{
    shake(b.type==='tough'?6:3.5);
    burst(b.x+b.w/2,b.y+b.h/2,b.color,14,200,300);
    S.brick(G.combo);
  }
  if(!chain && Math.random()<0.14) dropPowerup(b.x+b.w/2,b.y+b.h/2);
  if(G.remain<=0 && G.state==='play') levelClear();
}

/* ======================== POWERUPS ============================= */
function pickPU(){
  let tot=0; for(const p of PU_W) tot+=p;
  let r=Math.random()*tot;
  for(let i=0;i<PU_W.length;i++){ r-=PU_W[i]; if(r<=0) return PU[i]; }
  return PU[0];
}
function dropPowerup(x,y){ G.pus.push({x:x,y:y,vy:132,t:pickPU(),rot:0}); }
function applyPU(t){
  S.power(); shake(5);
  banner(t.n,t.c);
  popup(G.paddle.x,G.paddle.y-30,t.n,t.c,1.15);
  if(t.k==='E'){ G.paddle.timer=13; }
  else if(t.k==='S'){ G.speedMul=0.72; }
  else if(t.k==='L'){ G.lives=Math.min(6,G.lives+1); }
  else if(t.k==='M'){
    const add=[];
    for(const b of G.balls){
      if(G.balls.length+add.length>=8) break;
      const sp=Math.hypot(b.vx,b.vy)||G.baseSpeed;
      for(let i=0;i<2;i++){
        if(G.balls.length+add.length>=8) break;
        const a=Math.atan2(b.vy,b.vx)+(i?0.55:-0.55);
        add.push({x:b.x,y:b.y,vx:Math.cos(a)*sp,vy:Math.sin(a)*sp,r:b.r,trail:[]});
      }
    }
    for(const b of add) G.balls.push(b);
  }
  else if(t.k==='D'){
    const rows={};
    for(const b of G.bricks) if(b.alive&&!b.metal) rows[b.r]=1;
    const keys2=Object.keys(rows);
    if(keys2.length){
      const r=keys2[(Math.random()*keys2.length)|0];
      for(const b of G.bricks) if(b.alive&&b.r===+r&&!b.metal) destroyBrick(b,true);
      shake(10); G.freeze=0.05;
      burst(W/2,TOP+ (+r)*(BH+VGAP)+BH/2,'#b388ff',40,340,120);
    }
  }
}

/* ======================== UPDATE =============================== */
function update(dt){
  G.t+=dt;
  if(G.shake>0) G.shake=Math.max(0,G.shake-dt*34);
  if(G.flash>0) G.flash=Math.max(0,G.flash-dt*2.2);
  if(G.hurt>0) G.hurt=Math.max(0,G.hurt-dt*1.6);
  if(G.banner){ G.banner.life-=dt; if(G.banner.life<=0) G.banner=null; }
  if(G.paused) return;
  if(G.freeze>0){ G.freeze-=dt; return; }

  for(const s of G.stars){ s.y+=s.v*dt; s.p+=dt*2; if(s.y>H){s.y=-3;s.x=Math.random()*W;} }
  updateParts(dt); updateTexts(dt);

  if(G.state==='levelclear'){
    G.timer-=dt;
    if(G.timer<=0) nextLevel();
    return;
  }
  if(G.state!=='play') return;

  const P=G.paddle;
  /* paddle */
  const targetW=P.timer>0?P.maxW:P.baseW;
  P.w+=(targetW-P.w)*Math.min(1,dt*5);
  if(P.timer>0){ P.timer-=dt; if(P.timer<=0) P.timer=0; }
  P.squash+=(0-P.squash)*Math.min(1,dt*11);

  const spd=640;
  if(keys['arrowleft']||keys['a']){ P.x-=spd*dt; G.mouseMode=false; }
  else if(keys['arrowright']||keys['d']){ P.x+=spd*dt; G.mouseMode=false; }
  else if(G.mouseMode){ P.x+=(G.mouseX-P.x)*Math.min(1,dt*20); }
  P.x=Math.max(P.w/2,Math.min(W-P.w/2,P.x));

  /* speed easing */
  G.speedMul+=(1-G.speedMul)*Math.min(1,dt*0.16);
  const target=G.baseSpeed*G.speedMul;

  /* balls */
  for(let i=G.balls.length-1;i>=0;i--){
    const b=G.balls[i];
    if(G.serving){ b.x=P.x; b.y=P.y-12; b.trail.length=0; continue; }

    const steps=Math.max(1,Math.ceil((Math.hypot(b.vx,b.vy)*dt)/5));
    const sdt=dt/steps;
    for(let s=0;s<steps;s++){
      b.x+=b.vx*sdt; b.y+=b.vy*sdt;
      /* walls */
      if(b.x-b.r<0){ b.x=b.r; b.vx=Math.abs(b.vx); S.wall(); shake(1.5); }
      if(b.x+b.r>W){ b.x=W-b.r; b.vx=-Math.abs(b.vx); S.wall(); shake(1.5); }
      if(b.y-b.r<0){ b.y=b.r; b.vy=Math.abs(b.vy); S.wall(); shake(1.5); }
      /* paddle */
      if(b.vy>0 && b.y+b.r>=P.y && b.y-b.r<=P.y+P.h &&
         b.x>=P.x-P.w/2-b.r && b.x<=P.x+P.w/2+b.r){
        b.y=P.y-b.r;
        const off=Math.max(-1,Math.min(1,(b.x-P.x)/(P.w/2)));
        const ang=-Math.PI/2+off*1.05;
        const sp=Math.hypot(b.vx,b.vy)||target;
        b.vx=Math.cos(ang)*sp; b.vy=Math.sin(ang)*sp;
        P.squash=0.2; S.paddle(); shake(2.5);
        G.combo=0;
        burst(b.x,P.y,'#4cc9f0',7,140,120);
        continue;
      }
      /* bricks */
      for(let k=0;k<G.bricks.length;k++){
        const br=G.bricks[k];
        if(!br.alive) continue;
        if(b.x+b.r<br.x||b.x-b.r>br.x+br.w||b.y+b.r<br.y||b.y-b.r>br.y+br.h) continue;
        const cx=Math.max(br.x,Math.min(b.x,br.x+br.w));
        const cy=Math.max(br.y,Math.min(b.y,br.y+br.h));
        const dx=b.x-cx, dy=b.y-cy;
        if(dx*dx+dy*dy>b.r*b.r) continue;
        const ox=(b.r+br.w/2)-Math.abs(b.x-(br.x+br.w/2));
        const oy=(b.r+br.h/2)-Math.abs(b.y-(br.y+br.h/2));
        if(ox<oy){ b.vx=b.x<br.x+br.w/2?-Math.abs(b.vx):Math.abs(b.vx); b.x+=(b.vx>0?ox:-ox); }
        else{ b.vy=b.y<br.y+br.h/2?-Math.abs(b.vy):Math.abs(b.vy); b.y+=(b.vy>0?oy:-oy); }
        damageBrick(br,1,false);
        break;
      }
      if(b.y-b.r>H+30) break;
    }
    /* normalize speed */
    const sp=Math.hypot(b.vx,b.vy)||1;
    const ns=sp+(target-sp)*Math.min(1,dt*3);
    b.vx=b.vx/sp*ns; b.vy=b.vy/sp*ns;
    if(Math.abs(b.vy)<ns*0.26){ b.vy=(b.vy<0?-1:1)*ns*0.26;
      const hx=Math.sqrt(Math.max(0,ns*ns-b.vy*b.vy));
      b.vx=(b.vx<0?-1:1)*hx; }
    b.trail.push({x:b.x,y:b.y});
    if(b.trail.length>14) b.trail.shift();
    if(b.y-b.r>H+40){ G.balls.splice(i,1); }
  }
  if(!G.serving && G.balls.length===0 && G.state==='play') loseBall();

  /* powerups */
  for(let i=G.pus.length-1;i>=0;i--){
    const p=G.pus[i];
    p.y+=p.vy*dt; p.rot+=dt*3.4;
    if(p.y>H+20){ G.pus.splice(i,1); continue; }
    if(p.y+p.vy*dt>P.y-4 && p.y<=P.y+P.h && p.x>=P.x-P.w/2-14 && p.x<=P.x+P.w/2+14){
      applyPU(p.t); G.pus.splice(i,1);
    }
  }
}
function updateParts(dt){
  for(let i=G.parts.length-1;i>=0;i--){
    const p=G.parts[i];
    p.x+=p.vx*dt; p.y+=p.vy*dt; p.vy+=p.grav*dt;
    p.vx*=(1-dt*1.4);
    p.life-=dt;
    if(p.life<=0) G.parts.splice(i,1);
  }
}
function updateTexts(dt){
  for(let i=G.texts.length-1;i>=0;i--){
    const t=G.texts[i];
    t.y+=t.vy*dt; t.vy*=(1-dt*2.2); t.life-=dt*1.25;
    if(t.life<=0) G.texts.splice(i,1);
  }
}

/* ======================== RENDER =============================== */
function drawBG(){
  const g=ctx.createLinearGradient(0,0,0,H);
  g.addColorStop(0,'#080b18'); g.addColorStop(0.55,'#0d1226'); g.addColorStop(1,'#151c38');
  ctx.fillStyle=g; ctx.fillRect(0,0,W,H);

  ctx.strokeStyle='rgba(90,130,255,0.055)'; ctx.lineWidth=1;
  ctx.beginPath();
  for(let x=0;x<=W;x+=40){ ctx.moveTo(x+.5,0); ctx.lineTo(x+.5,H); }
  for(let y=0;y<=H;y+=40){ ctx.moveTo(0,y+.5); ctx.lineTo(W,y+.5); }
  ctx.stroke();

  for(const s of G.stars){
    const a=0.25+0.35*Math.abs(Math.sin(s.p));
    ctx.fillStyle='rgba(180,210,255,'+a.toFixed(3)+')';
    ctx.fillRect(s.x,s.y,s.s,s.s);
  }
  const vg=ctx.createRadialGradient(W/2,H/2,H*0.35,W/2,H/2,H*0.85);
  vg.addColorStop(0,'rgba(0,0,0,0)'); vg.addColorStop(1,'rgba(0,0,0,0.55)');
  ctx.fillStyle=vg; ctx.fillRect(0,0,W,H);
}
function drawBricks(){
  for(const b of G.bricks){
    if(!b.alive) continue;
    const s=1+b.pop*0.16;
    ctx.save();
    ctx.translate(b.x+b.w/2,b.y+b.h/2); ctx.scale(s,s); ctx.translate(-(b.x+b.w/2),-(b.y+b.h/2));
    let col=b.color;
    if(b.metal) col='#7f8bad';
    if(b.type==='tough'&&b.hp<=1) col='#5d6a8c';

    ctx.shadowColor=col; ctx.shadowBlur=b.type==='boom'?16+Math.sin(G.t*9)*7:7;
    const g=ctx.createLinearGradient(b.x,b.y,b.x,b.y+b.h);
    g.addColorStop(0,shade(col,0.35)); g.addColorStop(0.5,col); g.addColorStop(1,shade(col,-0.35));
    ctx.fillStyle=g;
    rr(b.x,b.y,b.w,b.h,5); ctx.fill();
    ctx.shadowBlur=0;

    ctx.fillStyle='rgba(255,255,255,0.28)';
    rr(b.x+2,b.y+2,b.w-4,b.h*0.36,3); ctx.fill();
    ctx.strokeStyle='rgba(0,0,0,0.35)'; ctx.lineWidth=1;
    rr(b.x+.5,b.y+.5,b.w-1,b.h-1,5); ctx.stroke();

    if(b.type==='boom'){
      ctx.fillStyle='#3a1a00';
      ctx.font='bold 13px Verdana'; ctx.textAlign='center'; ctx.textBaseline='middle';
      ctx.fillText('✸',b.x+b.w/2,b.y+b.h/2+1);
    }
    if(b.type==='tough'&&b.hp<=1){
      ctx.strokeStyle='rgba(0,0,0,0.5)'; ctx.lineWidth=1.4;
      ctx.beginPath();
      ctx.moveTo(b.x+6,b.y+3); ctx.lineTo(b.x+b.w*0.45,b.y+b.h*0.55); ctx.lineTo(b.x+b.w*0.3,b.y+b.h-3);
      ctx.moveTo(b.x+b.w*0.45,b.y+b.h*0.55); ctx.lineTo(b.x+b.w-6,b.y+4);
      ctx.moveTo(b.x+b.w*0.45,b.y+b.h*0.55); ctx.lineTo(b.x+b.w*0.7,b.y+b.h-3);
      ctx.stroke();
    }
    if(b.metal){
      ctx.fillStyle='rgba(255,255,255,0.35)';
      ctx.beginPath(); ctx.arc(b.x+5,b.y+b.h/2,1.6,0,6.3); ctx.fill();
      ctx.beginPath(); ctx.arc(b.x+b.w-5,b.y+b.h/2,1.6,0,6.3); ctx.fill();
    }
    if(b.flash>0){
      ctx.globalAlpha=b.flash;
      ctx.fillStyle='#ffffff'; rr(b.x,b.y,b.w,b.h,5); ctx.fill();
      ctx.globalAlpha=1;
    }
    ctx.restore();
    b.flash=Math.max(0,b.flash-0.09);
    b.pop=Math.max(0,b.pop-0.09);
  }
}
function shade(hex,amt){
  const c=hex.replace('#','');
  let r=parseInt(c.substr(0,2),16),g=parseInt(c.substr(2,2),16),b=parseInt(c.substr(4,2),16);
  r=Math.max(0,Math.min(255,Math.round(r+255*amt)));
  g=Math.max(0,Math.min(255,Math.round(g+255*amt)));
  b=Math.max(0,Math.min(255,Math.round(b+255*amt)));
  return 'rgb('+r+','+g+','+b+')';
}
function drawPaddle(){
  const P=G.paddle;
  ctx.save();
  ctx.translate(P.x,P.y+P.h/2);
  ctx.scale(1+P.squash,1-P.squash*0.7);
  ctx.translate(-P.x,-(P.y+P.h/2));

  ctx.shadowColor='#4cc9f0'; ctx.shadowBlur=18;
  const g=ctx.createLinearGradient(P.x,P.y,P.x,P.y+P.h);
  g.addColorStop(0,'#e6f8ff'); g.addColorStop(0.45,'#4cc9f0'); g.addColorStop(1,'#1b6fa8');
  ctx.fillStyle=g;
  rr(P.x-P.w/2,P.y,P.w,P.h,8); ctx.fill();
  ctx.shadowBlur=0;
  ctx.fillStyle='rgba(255,255,255,0.5)';
  rr(P.x-P.w/2+4,P.y+3,P.w-8,4,3); ctx.fill();
  ctx.strokeStyle='rgba(255,255,255,0.55)'; ctx.lineWidth=1.2;
  rr(P.x-P.w/2+.5,P.y+.5,P.w-1,P.h-1,8); ctx.stroke();
  ctx.restore();

  if(P.timer>0){
    ctx.fillStyle='rgba(76,201,240,0.85)';
    ctx.font='bold 10px Verdana'; ctx.textAlign='center';
    ctx.fillText('WIDE '+P.timer.toFixed(1),P.x,P.y-8);
  }
}
function drawBalls(){
  for(const b of G.balls){
    for(let i=0;i<b.trail.length;i++){
      const p=b.trail[i], a=(i+1)/b.trail.length;
      ctx.globalAlpha=a*0.32;
      ctx.fillStyle='#7fd7ff';
      ctx.beginPath(); ctx.arc(p.x,p.y,b.r*a*0.95,0,6.3); ctx.fill();
    }
    ctx.globalAlpha=1;
    ctx.shadowColor='#9ff0ff'; ctx.shadowBlur=16;
    const g=ctx.createRadialGradient(b.x-2,b.y-3,1,b.x,b.y,b.r);
    g.addColorStop(0,'#ffffff'); g.addColorStop(0.6,'#c9f4ff'); g.addColorStop(1,'#4cc9f0');
    ctx.fillStyle=g;
    ctx.beginPath(); ctx.arc(b.x,b.y,b.r,0,6.3); ctx.fill();
    ctx.shadowBlur=0;
  }
}
function drawPUs(){
  for(const p of G.pus){
    ctx.save();
    ctx.translate(p.x,p.y); ctx.rotate(Math.sin(p.rot)*0.35);
    ctx.shadowColor=p.t.c; ctx.shadowBlur=16;
    ctx.fillStyle=p.t.c;
    rr(-16,-11,32,22,11); ctx.fill();
    ctx.shadowBlur=0;
    ctx.fillStyle='rgba(0,0,0,0.75)';
    ctx.font='bold 14px Verdana'; ctx.textAlign='center'; ctx.textBaseline='middle';
    ctx.fillText(p.t.k,0,1);
    ctx.restore();
    ctx.globalAlpha=0.5;
    ctx.fillStyle=p.t.c;
    ctx.beginPath(); ctx.arc(p.x,p.y+16+Math.sin(G.t*8)*3,2.4,0,6.3); ctx.fill();
    ctx.globalAlpha=1;
  }
}
function drawParts(){
  ctx.save(); ctx.globalCompositeOperation='lighter';
  for(const p of G.parts){
    const a=Math.max(0,p.life/p.max);
    ctx.globalAlpha=a;
    ctx.fillStyle=p.color;
    ctx.fillRect(p.x-p.size/2,p.y-p.size/2,p.size,p.size);
  }
  ctx.restore(); ctx.globalAlpha=1;
}
function drawTexts(){
  for(const t of G.texts){
    const a=Math.max(0,t.life);
    ctx.globalAlpha=a;
    ctx.font='bold '+(Math.round(15*t.sc))+'px Verdana';
    ctx.textAlign='center';
    ctx.lineWidth=3; ctx.strokeStyle='rgba(0,0,0,0.7)';
    ctx.strokeText(t.txt,t.x,t.y);
    ctx.fillStyle=t.color;
    ctx.fillText(t.txt,t.x,t.y);
  }
  ctx.globalAlpha=1;
}
function drawHUD(){
  ctx.textAlign='left'; ctx.textBaseline='alphabetic';
  ctx.font='bold 11px Verdana'; ctx.fillStyle='#7f8bad';
  ctx.fillText('SCORE',20,24);
  ctx.font='bold 22px Verdana'; ctx.fillStyle='#ffffff';
  ctx.fillText(pad6(G.score),20,48);

  ctx.textAlign='center';
  ctx.font='bold 11px Verdana'; ctx.fillStyle='#7f8bad';
  ctx.fillText('LEVEL',W/2,24);
  ctx.font='bold 20px Verdana'; ctx.fillStyle=COLORS[G.level%6];
  ctx.fillText((G.level+1)+' / '+LEVELS.length,W/2,47);

  if(G.combo>=3){
    const m=1+Math.min(7,Math.floor(G.combo/3));
    const pu=1+Math.sin(G.t*10)*0.06;
    ctx.save(); ctx.translate(W/2,66); ctx.scale(pu,pu);
    ctx.font='bold 13px Verdana'; ctx.textAlign='center';
    ctx.fillStyle='#ffd166';
    ctx.shadowColor='#ffd166'; ctx.shadowBlur=12;
    ctx.fillText('COMBO ×'+m,G.combo,0);
    ctx.restore(); ctx.shadowBlur=0;
  }

  ctx.textAlign='right';
  ctx.font='bold 11px Verdana'; ctx.fillStyle='#7f8bad';
  ctx.fillText('LIVES',W-20,24);
  for(let i=0;i<G.lives;i++){
    const x=W-24-i*26;
    ctx.fillStyle='#4cc9f0';
    rr(x-20,34,20,7,3.5); ctx.fill();
    ctx.fillStyle='rgba(255,255,255,0.5)';
    rr(x-18,35.5,16,2,1); ctx.fill();
  }
  if(G.best>0){
    ctx.font='bold 11px Verdana'; ctx.fillStyle='#5d6a8c';
    ctx.fillText('BEST '+pad6(G.best),W-20,58);
  }
}
function bigText(txt,y,size,color,glow){
  ctx.save();
  ctx.textAlign='center'; ctx.textBaseline='middle';
  ctx.font='bold '+size+'px Verdana';
  if(glow){ ctx.shadowColor=color; ctx.shadowBlur=26; }
  ctx.lineWidth=Math.max(3,size*0.09); ctx.strokeStyle='rgba(0,0,0,0.75)';
  ctx.strokeText(txt,W/2,y);
  ctx.fillStyle=color; ctx.fillText(txt,W/2,y);
  ctx.restore();
}
function panel(x,y,w,h){
  ctx.fillStyle='rgba(6,9,20,0.86)';
  rr(x,y,w,h,16); ctx.fill();
  ctx.strokeStyle='rgba(120,160,255,0.35)'; ctx.lineWidth=2;
  rr(x,y,w,h,16); ctx.stroke();
}
function drawOverlays(){
  if(G.banner){
    const a=Math.min(1,G.banner.life*2);
    ctx.globalAlpha=a;
    bigText(G.banner.txt,150,34,G.banner.color,true);
    ctx.globalAlpha=1;
  }
  if(G.state==='levelclear'){
    ctx.fillStyle='rgba(4,7,16,0.45)'; ctx.fillRect(0,0,W,H);
    bigText('LEVEL CLEAR!',H/2-16,52,'#06d6a0',true);
    bigText('+'+G.score,H/2+34,22,'#ffd166',false);
  }
  if(G.state==='menu'){
    ctx.fillStyle='rgba(4,7,16,0.55)'; ctx.fillRect(0,0,W,H);
    const pu=1+Math.sin(G.t*2.4)*0.03;
    ctx.save(); ctx.translate(W/2,178); ctx.scale(pu,pu);
    ctx.font='bold 74px Verdana'; ctx.textAlign='center'; ctx.textBaseline='middle';
    ctx.shadowColor='#4cc9f0'; ctx.shadowBlur=34;
    ctx.lineWidth=8; ctx.strokeStyle='#0a1024';
    ctx.strokeText('BREAKOUT',0,0);
    const g=ctx.createLinearGradient(0,-40,0,40);
    g.addColorStop(0,'#ffffff'); g.addColorStop(0.5,'#4cc9f0'); g.addColorStop(1,'#b388ff');
    ctx.fillStyle=g; ctx.fillText('BREAKOUT',0,0);
    ctx.restore(); ctx.shadowBlur=0;

    ctx.textAlign='center';
    ctx.font='bold 15px Verdana'; ctx.fillStyle='#ffd166';
    ctx.fillText('JUICE EDITION · 6 LEVELS · POWER-UPS · COMBOS',W/2,232);

    panel(W/2-235,268,470,150);
    ctx.font='bold 14px Verdana'; ctx.fillStyle='#c9d6ff'; ctx.textAlign='center';
    const lines=[
      '← →  /  A D  /  MOUSE   — move the paddle',
      'SPACE  /  CLICK   — launch the ball',
      'P — pause      M — mute',
      '',
      'Catch power-ups · chain the orange bombs · build combos!'
    ];
    lines.forEach((l,i)=>ctx.fillText(l,W/2,300+i*26));

    const a=0.55+0.45*Math.sin(G.t*4);
    ctx.globalAlpha=a;
    ctx.font='bold 20px Verdana'; ctx.fillStyle='#06d6a0';
    ctx.fillText('PRESS SPACE OR CLICK TO START',W/2,468);
    ctx.globalAlpha=1;
    if(G.best>0){ ctx.font='bold 13px Verdana'; ctx.fillStyle='#7f8bad';
      ctx.fillText('BEST SCORE  '+pad6(G.best),W/2,500); }
  }
  if(G.paused){
    ctx.fillStyle='rgba(4,7,16,0.7)'; ctx.fillRect(0,0,W,H);
    bigText('PAUSED',H/2-10,52,'#4cc9f0',true);
    ctx.textAlign='center'; ctx.font='bold 15px Verdana'; ctx.fillStyle='#9fb0d0';
    ctx.fillText('Press P or click to resume',W/2,H/2+34);
  }
  if(G.state==='gameover'||G.state==='win'){
    ctx.fillStyle='rgba(4,7,16,0.72)'; ctx.fillRect(0,0,W,H);
    panel(W/2-210,150,420,270);
    bigText(G.state==='win'?'YOU WIN!':'GAME OVER',210,46,
      G.state==='win'?'#06d6a0':'#ff4d6d',true);
    ctx.textAlign='center';
    ctx.font='bold 13px Verdana'; ctx.fillStyle='#7f8bad';
    ctx.fillText('FINAL SCORE',W/2,262);
    ctx.font='bold 40px Verdana'; ctx.fillStyle='#ffffff';
    ctx.fillText(pad6(G.score),W/2,304);
    ctx.font='bold 13px Verdana'; ctx.fillStyle='#9fb0d0';
    ctx.fillText('REACHED LEVEL '+(G.level+1)+' / '+LEVELS.length,W/2,336);
    ctx.fillStyle='#ffd166';
    ctx.fillText('BEST  '+pad6(G.best),W/2,360);
    const a=0.55+0.45*Math.sin(G.t*4);
    ctx.globalAlpha=a; ctx.fillStyle='#06d6a0'; ctx.font='bold 16px Verdana';
    ctx.fillText('PRESS SPACE OR CLICK TO PLAY AGAIN',W/2,396);
    ctx.globalAlpha=1;
  }
}
function render(){
  drawBG();
  const sh=G.shake;
  const ox=sh?(Math.random()*2-1)*sh:0, oy=sh?(Math.random()*2-1)*sh:0;
  ctx.save(); ctx.translate(ox,oy);
  drawBricks();
  drawPUs();
  if(G.state==='play'||G.state==='levelclear') drawPaddle();
  drawBalls();
  drawParts();
  drawTexts();
  ctx.restore();

  if(G.state!=='menu') drawHUD();
  drawOverlays();

  if(G.flash>0){
    ctx.globalAlpha=G.flash*0.55;
    ctx.fillStyle='#ffffff'; ctx.fillRect(0,0,W,H);
    ctx.globalAlpha=1;
  }
  if(G.hurt>0){
    const g=ctx.createRadialGradient(W/2,H/2,H*0.25,W/2,H/2,H*0.8);
    g.addColorStop(0,'rgba(255,0,60,0)');
    g.addColorStop(1,'rgba(255,30,70,'+(G.hurt*0.6).toFixed(3)+')');
    ctx.fillStyle=g; ctx.fillRect(0,0,W,H);
  }
}

/* ======================== INPUT ================================ */
function handleAction(){
  initAudio(); resumeAudio();
  if(G.state==='menu'||G.state==='gameover'||G.state==='win'){ startGame(); return; }
  if(G.paused){ G.paused=false; return; }
  if(G.state==='play'&&G.serving) launch();
}
addEventListener('keydown',function(e){
  const k=(e.key||'').toLowerCase();
  if(['arrowleft','arrowright','arrowup','arrowdown',' ','spacebar'].indexOf(k)>=0) e.preventDefault();
  initAudio(); resumeAudio();
  keys[k]=true;
  if(k==='m'){ muted=!muted; if(!muted) tone(660,880,0.08,'sine',0.2); }
  if(k==='p'){
    if(G.state==='play'||G.state==='levelclear') G.paused=!G.paused;
  }
  if(k===' '||k==='spacebar'||k==='enter') handleAction();
  if(k==='r'&&(G.state==='gameover'||G.state==='win')) startGame();
});
addEventListener('keyup',function(e){ keys[(e.key||'').toLowerCase()]=false; });
function mousePos(e){
  const r=cv.getBoundingClientRect();
  G.mouseX=(e.clientX-r.left)*(W/r.width);
}
cv.addEventListener('pointermove',function(e){ mousePos(e); G.mouseMode=true; });
cv.addEventListener('pointerdown',function(e){ mousePos(e); G.mouseMode=true; handleAction(); });
window.addEventListener('blur',function(){
  if(G.state==='play'&&!G.paused) G.paused=true;
  keys['arrowleft']=keys['arrowright']=keys['a']=keys['d']=false;
});

/* ======================== LOOP ================================= */
let last=performance.now();
function loop(now){
  let dt=(now-last)/1000; last=now;
  if(dt>0.05) dt=0.05;
  update(dt);
  render();
  requestAnimationFrame(loop);
}
requestAnimationFrame(loop);

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

Compare

Other runs