Run details
- Model
- z-ai/glm-5.4
- Route
- OpenRouter API
- Served by
- Modal
- Effort
- max (OpenRouter default)
- Limits
- 60 min · 681,818 output tokens ($3.00 cap at $4.40/M)
- Date
- 2 Dec 2026
- Time
- 2 min 49 s
- Size
- 30 kB
- Tokens
- 88 in, 38,697 out (27,450 thinking)
- List price
- $0.17 at today's price ($1.40 in / $4.40 out per M)
- Paid
- $0.17
Prompt
Make a Breakout game I can play right now with the keyboard or the mouse. Give it several levels, a score and some juice. It must be one complete, self-contained HTML file: inline all CSS and JavaScript, and make no network requests of any kind (no CDNs, web fonts or remote images). Reply with the file in a single ```html code block.
Source
30 kB 794 lines Raw
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BREAKOUT — Riso Edition</title>
<style>
:root{ --paper:#F4EDDE; --ink:#211D16; --accent:#E64B35; }
*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
margin:0; background:var(--ink); min-height:100vh;
display:grid; place-items:center; padding:28px 20px;
font-family: ui-monospace,"SF Mono","Cascadia Mono",Consolas,"Courier New",monospace;
}
#stage{ width:min(94vw, 900px); }
canvas{
display:block; width:100%; aspect-ratio:900/640;
background:var(--paper); border-radius:6px;
box-shadow:12px 12px 0 0 var(--accent);
touch-action:none;
}
#hint{
display:flex; justify-content:space-between; gap:16px; flex-wrap:wrap;
margin:18px 2px 0; color:rgba(244,237,222,.55);
font-size:11px; letter-spacing:.14em; text-transform:uppercase;
}
</style>
</head>
<body>
<main id="stage">
<canvas id="game" width="900" height="640"></canvas>
<p id="hint">
<span>move — mouse or arrow keys · launch — space / click · p — pause · m — sound</span>
<span>breakout · riso print · six stages</span>
</p>
</main>
<script>
'use strict';
/* ============================== setup ============================== */
const cv = document.getElementById('game');
const ctx = cv.getContext('2d');
const W = 900, H = 640;
const F = { x:20, y:64, w:860 }; // playfield walls (bottom open)
const BR = 7; // ball radius
const MAXSP = 640;
const C = { paper:'#F4EDDE', ink:'#211D16', accent:'#E64B35',
amber:'#EDA412', teal:'#178576', slate:'#5C6672', gold:'#D9A33C' };
let dpr = 1;
function fit(){ dpr = Math.min(window.devicePixelRatio||1, 2);
cv.width = W*dpr; cv.height = H*dpr; ctx.setTransform(dpr,0,0,dpr,0,0); }
fit(); addEventListener('resize', fit);
const TAU = Math.PI*2;
const clamp = (v,a,b)=>Math.max(a,Math.min(b,v));
const rand = (a,b)=>a+Math.random()*(b-a);
function easeOutBack(p){ const c1=1.70158, c3=c1+1; return 1+c3*Math.pow(p-1,3)+c1*Math.pow(p-1,2); }
function rrPath(x,y,w,h,r){ ctx.beginPath(); ctx.moveTo(x+r,y);
ctx.arcTo(x+w,y,x+w,y+h,r); ctx.arcTo(x+w,y+h,x,y+h,r);
ctx.arcTo(x,y+h,x,y,r); ctx.arcTo(x,y,x+w,y,r); ctx.closePath(); }
function circle(x,y,r){ ctx.beginPath(); ctx.arc(x,y,r,0,TAU); ctx.fill(); }
function text(s,x,y,size,o={}){
ctx.save();
ctx.globalAlpha = o.alpha ?? 1;
ctx.fillStyle = o.color ?? C.ink;
ctx.font = `${o.weight??700} ${size}px ui-monospace,"SF Mono","Cascadia Mono",Consolas,"Courier New",monospace`;
ctx.letterSpacing = (o.ls??0)+'px';
ctx.textAlign = o.align ?? 'center';
ctx.textBaseline = 'alphabetic';
ctx.fillText(s,x,y); ctx.restore();
}
/* dot grid (built once as a path, stays crisp) */
const dots = new Path2D();
for(let y=F.y+18; y<H-10; y+=30) for(let x=F.x+18; x<F.x+F.w-6; x+=30){
dots.moveTo(x+1.2,y); dots.arc(x,y,1.2,0,TAU);
}
/* static paper grain pattern */
const grain = (()=>{ const g=document.createElement('canvas'); g.width=g.height=140;
const gc=g.getContext('2d');
for(let i=0;i<2600;i++){ gc.fillStyle=`rgba(33,29,22,${Math.random()*0.05})`;
gc.fillRect(Math.random()*140, Math.random()*140, 1.3, 1.3); }
return ctx.createPattern(g,'repeat'); })();
/* ============================== levels ============================== */
const BT = {
r:{ color:C.accent, hp:1, pts:10 },
o:{ color:C.amber, hp:1, pts:15 },
t:{ color:C.teal, hp:1, pts:20 },
s:{ color:C.slate, hp:2, pts:40 },
g:{ color:C.gold, hp:3, pts:80 },
};
const LEVELS = [
{ name:'WARM-UP', rows:[
'..rrrrrrrr..',
'.rrrrrrrrrr.',
'.oooooooooo.',
'..oooooooo..' ]},
{ name:'THE DIAMOND', rows:[
'.....tt.....',
'....tttt....',
'...tttttt...',
'..tttttttt..',
'...oooooo...',
'....oooo....',
'.....oo.....' ]},
{ name:'CHECKMATE', rows:[
's.s.s.s.s.s.',
'.r.r.r.r.r.r',
's.s.s.s.s.s.',
'.o.o.o.o.o.o',
's.s.s.s.s.s.',
'.t.t.t.t.t.t' ]},
{ name:'THE FORTRESS', rows:[
'..ssssssss..',
'.s..ssss..s.',
's...gggg...s',
's..gggggg..s',
's...gggg...s',
'.s..ssss..s.',
'..ssssssss..' ]},
{ name:'INVADER', rows:[
'.o........o.',
'..o......o..',
'.tttttttttt.',
'.tt.tttt.tt.',
'tttttttttttt',
't.tttttttt.t',
't.t......t.t',
'...tt..tt...' ]},
{ name:'THE VAULT', rows:[
'.s..ssss..s.',
'ss.sggggs.ss',
'ss.gggggg.ss',
'ss.sggggs.ss',
'.s..ssss..s.',
'....rrrr....' ]},
];
/* pixel glyphs for the title (4×5) */
const GLYPH = {
B:['1110','1001','1110','1001','1110'], R:['1110','1001','1110','1010','1001'],
E:['1111','1000','1110','1000','1111'], A:['0110','1001','1111','1001','1001'],
K:['1001','1010','1100','1010','1001'], O:['0110','1001','1001','1001','0110'],
U:['1001','1001','1001','1001','0110'], T:['1111','0110','0110','0110','0110'],
};
/* ============================== state ============================== */
let state='menu', pausedFrom='play';
let score=0, dispScore=0, lives=3, level=0, combo=0, comboPop=0;
let hi = 0; try{ hi = +localStorage.getItem('riso-breakout-hi') || 0; }catch(e){}
function saveHi(){ try{ localStorage.setItem('riso-breakout-hi', hi); }catch(e){} }
let bricks=[], balls=[], parts=[], rings=[], floats=[], pows=[], titleCells=[];
let shake=0, flash=0, hitstop=0, slowT=0, tNow=0, watermark='';
let introT=0, serveT=0, clearT=0, breakT=0, maxBt=0, lastTick=0;
const paddle = { x:W/2, y:596, w:110, h:14, pop:0, tilt:0, vel:0, wideT:0 };
/* ============================== audio ============================== */
let AC=null, muted=false, noiseBuf=null;
function initAudio(){
if(!AC){ try{ AC = new (window.AudioContext||window.webkitAudioContext)(); }catch(e){} }
if(AC && AC.state==='suspended') AC.resume();
}
function tone(f,dur,type='square',vol=0.12,slide=0,when=0){
if(muted||!AC) return;
const t0 = AC.currentTime + when;
const o = AC.createOscillator(), g = AC.createGain();
o.type = type; o.frequency.setValueAtTime(f,t0);
if(slide) o.frequency.exponentialRampToValueAtTime(Math.max(slide,1), t0+dur);
g.gain.setValueAtTime(vol,t0);
g.gain.exponentialRampToValueAtTime(0.0008, t0+dur);
o.connect(g).connect(AC.destination); o.start(t0); o.stop(t0+dur+0.03);
}
function noiseHit(dur=0.12, vol=0.15, when=0){
if(muted||!AC) return;
if(!noiseBuf){ noiseBuf = AC.createBuffer(1, AC.sampleRate*0.3|0, AC.sampleRate);
const d = noiseBuf.getChannelData(0);
for(let i=0;i<d.length;i++) d[i]=Math.random()*2-1; }
const t0 = AC.currentTime + when;
const s = AC.createBufferSource(); s.buffer = noiseBuf;
const f = AC.createBiquadFilter(); f.type='highpass'; f.frequency.value=700;
const g = AC.createGain();
g.gain.setValueAtTime(vol,t0); g.gain.exponentialRampToValueAtTime(0.001, t0+dur);
s.connect(f).connect(g).connect(AC.destination); s.start(t0); s.stop(t0+dur);
}
const sfx = {
wall: ()=>tone(150,0.045,'square',0.07),
paddle:()=>{ tone(196,0.07,'square',0.11); tone(92,0.05,'sine',0.10); },
launch:()=>tone(520,0.06,'triangle',0.10,680),
clink: ()=>{ tone(720,0.05,'triangle',0.08); tone(1080,0.04,'triangle',0.05); },
breakBrick(hp){ noiseHit(0.10,0.14);
tone(300+Math.min(combo,10)*42,0.08,'square',0.10);
if(hp>=3) tone(660,0.16,'triangle',0.12,1320); },
catch: ()=>[392,523,659,784].forEach((f,i)=>tone(f,0.12,'triangle',0.11,0,i*0.06)),
lose: ()=>{ tone(280,0.35,'sawtooth',0.12,70); noiseHit(0.25,0.10); },
clear: ()=>{ [523,659,784,1046].forEach((f,i)=>tone(f,0.14,'triangle',0.12,0,i*0.09));
tone(1318,0.3,'triangle',0.12,0,0.36); },
win: ()=>[523,659,784,1046,784,1046,1318].forEach((f,i)=>tone(f,0.16,'triangle',0.12,0,i*0.1)),
over: ()=>{ tone(220,0.4,'sawtooth',0.10,110); tone(110,0.6,'sawtooth',0.09,55,0.15); },
boom: ()=>{ noiseHit(0.3,0.2); tone(90,0.25,'sine',0.2,45); },
};
/* ============================== input ============================== */
const keys = { L:false, R:false };
let mouseX = W/2, mouseOn = false;
cv.addEventListener('pointermove', e=>{
const r = cv.getBoundingClientRect();
mouseX = (e.clientX-r.left)/r.width*W; mouseOn = true;
});
cv.addEventListener('pointerdown', e=>{
initAudio();
const r = cv.getBoundingClientRect();
const mx = (e.clientX-r.left)/r.width*W, my = (e.clientY-r.top)/r.height*H;
if(mx > F.x+F.w-180 && my > H-32){ toggleMute(); return; } // mute label hit-box
action();
});
addEventListener('keydown', e=>{
if(['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','Space'].includes(e.code)) e.preventDefault();
if(e.repeat) return;
initAudio();
if(e.code==='ArrowLeft'||e.code==='KeyA') keys.L = true;
if(e.code==='ArrowRight'||e.code==='KeyD') keys.R = true;
if(e.code==='Space') action();
if(e.code==='KeyP'||e.code==='Escape') togglePause();
if(e.code==='KeyM') toggleMute();
});
addEventListener('keyup', e=>{
if(e.code==='ArrowLeft'||e.code==='KeyA') keys.L = false;
if(e.code==='ArrowRight'||e.code==='KeyD') keys.R = false;
});
addEventListener('blur', ()=>{ if(['play','serve','intro'].includes(state)){ pausedFrom=state; state='pause'; } });
function toggleMute(){ muted = !muted; if(!muted) tone(660,0.06,'triangle',0.08); }
function togglePause(){
if(state==='pause'){ state = pausedFrom; }
else if(['play','serve','intro'].includes(state)){ pausedFrom = state; state = 'pause'; }
}
function action(){
switch(state){
case 'menu': beginTitleBreak(); break;
case 'serve': launch(); state='play'; break;
case 'intro': introT = 99; break;
case 'clear': if(clearT > 0.5) nextLevel(); break;
case 'over':
case 'win': toMenu(); break;
case 'pause': togglePause(); break;
}
}
/* ============================== title (brick letters) ============================== */
function buildTitle(){
titleCells = [];
const stepX=22, stepY=26, word='BREAKOUT';
const cols = word.length*4 + (word.length-1);
const x0 = (W - (cols*stepX-3))/2, y0 = 128;
const colr = [C.accent,C.amber,C.teal,C.slate,C.accent,C.amber,C.teal,C.ink];
word.split('').forEach((ch,li)=>{
GLYPH[ch].forEach((row,r)=>{ [...row].forEach((bit,cc)=>{
if(bit==='1') titleCells.push({ x:x0+(li*5+cc)*stepX, y:y0+r*stepY,
w:19, h:23, color:colr[li], broken:false, bt:0 });
});});
});
}
function beginTitleBreak(){
state='titleBreak'; breakT=0; maxBt=0;
for(const c of titleCells){
c.broken=false;
c.bt = Math.hypot(c.x+9-W/2, c.y+11-215)/1150 + Math.random()*0.06;
maxBt = Math.max(maxBt, c.bt);
}
shake = 5; sfx.boom();
}
/* ============================== level flow ============================== */
function loadLevel(i){
level = i;
bricks=[]; balls=[]; pows=[]; parts=[]; rings=[]; floats=[];
combo=0; slowT=0; paddle.wideT=0;
const gap=7, bw=(F.w-20-11*gap)/12, bh=24, gy=7, x0=F.x+10, y0=F.y+36;
LEVELS[i].rows.forEach((row,r)=>{ [...row].forEach((ch,c)=>{
if(ch==='.') return;
bricks.push({ x:x0+c*(bw+gap), y:y0+r*(bh+gy), w:bw, h:bh,
type:ch, hp:BT[ch].hp, alive:true, flash:0, in:false,
delay:c*0.035 + r*0.05 });
});});
watermark = String(i+1).padStart(2,'0');
introT = 0; state = 'intro';
}
function nextLevel(){
if(level+1 >= LEVELS.length){ state='win'; hi=Math.max(hi,score); saveHi(); sfx.win(); }
else loadLevel(level+1);
}
function startGame(){ score=0; dispScore=0; lives=3; loadLevel(0); }
function toMenu(){
buildTitle(); watermark='';
bricks=[]; balls=[]; pows=[]; parts=[]; rings=[]; floats=[];
state='menu';
}
function baseSpeed(){ return 320 + level*16; }
function spawnServeBall(){
const b = makeBall(paddle.x, paddle.y-BR-2, 0, baseSpeed());
b.stuck = true; b.vx = b.vy = 0; balls = [b];
}
function launch(){
const ang = (-90 + clamp(paddle.vel,-280,280)/280*38) * Math.PI/180;
for(const b of balls) if(b.stuck){
b.stuck=false; b.sp=baseSpeed();
b.vx=Math.cos(ang)*b.sp; b.vy=Math.sin(ang)*b.sp;
}
sfx.launch();
}
function loseLife(){
lives--; combo=0; slowT=0; flash=1; shake=13; sfx.lose();
if(lives<=0){ state='over'; hi=Math.max(hi,score); saveHi(); sfx.over(); }
else { paddle.wideT=0; serveT=0; state='serve'; spawnServeBall(); }
}
function stageClear(){
for(const b of balls) burstRect(b.x,BR*2? b.y:b.y,0,0,C.accent,0); // noop guard
for(const b of balls){ burstRect(b.x-BR, b.y-BR, BR*2, BR*2, C.accent, 6); }
balls=[]; pows=[]; score+=500; hi=Math.max(hi,score);
floats.push({ x:W/2, y:F.y+250, txt:'STAGE CLEAR +500', life:1.4, life0:1.4,
color:C.ink, size:20 });
state='clear'; clearT=0; shake=6; sfx.clear();
}
/* ============================== gameplay update ============================== */
function makeBall(x,y,ang,sp){
return { x,y, vx:Math.cos(ang)*sp, vy:Math.sin(ang)*sp, sp, stuck:false, trail:[] };
}
function updatePaddle(dt){
const p=paddle, before=p.x;
if(keys.L||keys.R){ p.x += ((keys.R?1:0)-(keys.L?1:0))*640*dt; }
else if(mouseOn){ p.x += (mouseX-p.x)*Math.min(1,dt*16); }
const half=p.w/2+6;
p.x = clamp(p.x, F.x+half, F.x+F.w-half);
p.vel = (p.x-before)/Math.max(dt,1e-4);
p.tilt += (clamp(p.vel/2200,-1,1)*0.10 - p.tilt)*Math.min(1,dt*12);
p.pop *= Math.exp(-9*dt);
const tw = p.wideT>0 ? 165 : 110;
p.w += (tw-p.w)*Math.min(1,dt*8);
if(p.wideT>0) p.wideT -= dt;
}
function updateBall(b, dt){
const sf = slowT>0 ? 0.6 : 1;
b.x += b.vx*sf*dt; b.y += b.vy*sf*dt;
b.trail.push({x:b.x,y:b.y}); if(b.trail.length>9) b.trail.shift();
if(b.x < F.x+BR){ b.x=F.x+BR; b.vx=Math.abs(b.vx); sfx.wall(); shake=Math.max(shake,1.5); sparks(b.x,b.y,3); }
if(b.x > F.x+F.w-BR){ b.x=F.x+F.w-BR; b.vx=-Math.abs(b.vx); sfx.wall(); shake=Math.max(shake,1.5); sparks(b.x,b.y,3); }
if(b.y < F.y+BR){ b.y=F.y+BR; b.vy=Math.abs(b.vy); sfx.wall(); shake=Math.max(shake,1.5); sparks(b.x,b.y,3); }
/* paddle */
const p=paddle;
if(b.vy>0 && b.y+BR>p.y && b.y-BR<p.y+p.h && Math.abs(b.x-p.x)<p.w/2+BR){
const rel = clamp((b.x-p.x)/(p.w/2), -1, 1);
const ang = (-90 + rel*62)*Math.PI/180;
b.sp = Math.min(b.sp+3.5, MAXSP);
b.vx = Math.cos(ang)*b.sp; b.vy = Math.sin(ang)*b.sp;
b.y = p.y - BR - 0.5;
combo=0; p.pop=1; sfx.paddle(); sparks(b.x, p.y, 3);
}
/* bricks */
for(const br of bricks){
if(!br.alive || !br.in) 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 > BR*BR) continue;
const ocx=br.x+br.w/2, ocy=br.y+br.h/2;
const ox=(br.w/2+BR)-Math.abs(b.x-ocx), oy=(br.h/2+BR)-Math.abs(b.y-ocy);
if(ox<oy) b.vx = Math.sign(b.x-ocx)*Math.abs(b.vx);
else b.vy = Math.sign(b.y-ocy)*Math.abs(b.vy);
hitBrick(br, b);
break;
}
}
function hitBrick(br, ball){
const def = BT[br.type];
br.hp--; br.flash=1;
if(br.hp<=0){
br.alive=false; combo++; comboPop=1;
const mult = Math.min(combo,5), gained = def.pts*mult;
score += gained; hi=Math.max(hi,score);
floats.push({ x:br.x+br.w/2, y:br.y+4,
txt:'+'+gained+(mult>1?' ×'+mult:''), life:0.9, life0:0.9,
color: mult>=3 ? C.accent : C.ink, size:13 });
burstRect(br.x, br.y, br.w, br.h, def.color, 10);
rings.push({ x:br.x+br.w/2, y:br.y+br.h/2, r:8, life:0.35, color:def.color });
dropPow(br.x+br.w/2, br.y+br.h/2);
hitstop = def.hp>=3 ? 0.075 : 0.045;
shake = Math.min(shake+(def.hp>=2?3.2:2.1), 9);
sfx.breakBrick(def.hp);
if(bricks.every(k=>!k.alive)) stageClear();
} else {
shake=Math.max(shake,1.2); hitstop=0.02; sfx.clink();
sparks(ball.x, ball.y, 3);
}
}
/* ============================== power-ups ============================== */
const POWC = { W:C.accent, M:C.teal, S:C.slate, L:C.amber };
const POWT = { W:'WIDE!', M:'MULTIBALL!', S:'SLOW-MO', L:'+1 LIFE' };
function dropPow(x,y){
if(Math.random()>0.16) return;
const r=Math.random();
const type = r<0.32?'W' : r<0.58?'M' : r<0.82?'S' : 'L';
pows.push({ x, y, vy:150, type, ph:rand(0,6) });
}
function updatePows(dt){
for(let i=pows.length-1;i>=0;i--){
const p=pows[i];
p.y += p.vy*dt; p.vy = Math.min(p.vy+140*dt, 240);
p.x += Math.sin(tNow*3+p.ph)*20*dt;
const caught = p.y+9>paddle.y && p.y<paddle.y+paddle.h+6 &&
Math.abs(p.x-paddle.x)<paddle.w/2+14;
if(caught){ applyPow(p.type); pows.splice(i,1); }
else if(p.y>H+24) pows.splice(i,1);
}
}
function applyPow(type){
if(type==='W') paddle.wideT=10;
if(type==='S') slowT=8;
if(type==='L') lives=Math.min(lives+1,5);
if(type==='M') doMulti();
floats.push({ x:paddle.x, y:paddle.y-26, txt:POWT[type],
life:0.9, life0:0.9, color:POWC[type], size:15 });
sfx.catch();
}
function doMulti(){
let src = balls.find(b=>!b.stuck);
if(!src){
const ang = -90*Math.PI/180;
src = balls[0] || makeBall(paddle.x, paddle.y-9, ang, baseSpeed());
if(!balls.length) balls.push(src);
if(src.stuck){ src.stuck=false; src.sp=baseSpeed();
src.vx=Math.cos(ang)*src.sp; src.vy=Math.sin(ang)*src.sp; }
if(state==='serve') state='play';
}
if(balls.length>=6) return;
for(const da of [-0.42, 0.42]){
const a = Math.atan2(src.vy,src.vx)+da;
balls.push(makeBall(src.x, src.y, a, src.sp));
}
}
/* ============================== particles ============================== */
function burstRect(x,y,w,h,color,n){
const cx=x+w/2, cy=y+h/2;
for(let i=0;i<n;i++) parts.push({
x:cx+rand(-w*0.3,w*0.3), y:cy+rand(-h*0.4,h*0.4),
vx:rand(-220,220), vy:rand(-260,60),
w:rand(3,10), h:rand(3,7), rot:rand(0,TAU), vr:rand(-12,12),
life:rand(0.45,0.85), life0:0.85,
color:Math.random()<0.75?color:C.ink, shape:'rect' });
for(let i=0;i<4;i++){ const a=rand(0,TAU), sp=rand(180,420);
parts.push({ x:cx, y:cy, vx:Math.cos(a)*sp, vy:Math.sin(a)*sp,
life:rand(0.14,0.28), life0:0.28,
color:Math.random()<0.5?C.ink:color, shape:'line' }); }
}
function sparks(x,y,n){
for(let i=0;i<n;i++){ const a=rand(0,TAU), sp=rand(120,300);
parts.push({ x, y, vx:Math.cos(a)*sp, vy:Math.sin(a)*sp,
life:rand(0.1,0.22), life0:0.22, color:C.ink, shape:'line' }); }
}
function updParts(dt){
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.x+=p.vx*dt; p.y+=p.vy*dt;
if(p.shape==='rect'){ p.vy+=880*dt; p.vx*=Math.exp(-1.2*dt); p.rot+=p.vr*dt; }
else { p.vx*=Math.exp(-6*dt); p.vy*=Math.exp(-6*dt); }
}
for(let i=rings.length-1;i>=0;i--){
const r=rings[i]; r.life-=dt; r.r+=260*dt;
if(r.life<=0) rings.splice(i,1);
}
for(let i=floats.length-1;i>=0;i--){
const f=floats[i]; f.life-=dt; f.y-=46*dt;
if(f.life<=0) floats.splice(i,1);
}
}
/* ============================== main update ============================== */
function update(dt){
tNow += dt;
shake *= Math.exp(-5.5*dt); if(shake<0.05) shake=0;
flash *= Math.exp(-4*dt);
comboPop *= Math.exp(-6*dt);
dispScore += (score-dispScore)*Math.min(1,dt*8);
for(const b of bricks) b.flash *= Math.exp(-10*dt);
updParts(dt);
switch(state){
case 'menu': break;
case 'titleBreak': {
breakT += dt;
for(const c of titleCells){
if(c.broken || breakT < c.bt) continue;
c.broken = true;
burstRect(c.x, c.y, c.w, c.h, c.color, 7);
rings.push({ x:c.x+9, y:c.y+11, r:5, life:0.3, color:c.color });
shake = Math.min(shake+0.5, 9);
if(tNow-lastTick>0.045){ tone(240+breakT*520, 0.045, 'triangle', 0.07); lastTick=tNow; }
}
if(breakT > maxBt+0.6) startGame();
break;
}
case 'intro': {
updatePaddle(dt);
introT += dt;
for(const b of bricks) if(!b.in && introT-b.delay>=0.22) b.in=true;
const maxD = Math.max(...bricks.map(b=>b.delay), 0);
if(introT > maxD+0.3){ state='serve'; serveT=0; spawnServeBall(); }
break;
}
case 'serve': {
updatePaddle(dt); serveT += dt; updatePows(dt);
for(const b of balls) if(b.stuck){ b.x=paddle.x; b.y=paddle.y-BR-2; }
break;
}
case 'play': {
updatePaddle(dt);
if(slowT>0) slowT -= dt;
updatePows(dt);
for(let i=balls.length-1;i>=0;i--){
const b=balls[i];
if(b.stuck){ b.x=paddle.x; b.y=paddle.y-BR-2; }
else updateBall(b,dt);
if(b.y > H+26){
burstRect(b.x-BR, H-10, BR*2, BR*2, C.accent, 6);
balls.splice(i,1);
}
}
if(!balls.length) loseLife();
break;
}
case 'clear': {
clearT += dt;
if(clearT > 2.4) nextLevel();
break;
}
}
}
/* ============================== drawing ============================== */
function drawBG(){
ctx.fillStyle=C.paper; ctx.fillRect(0,0,W,H);
ctx.fillStyle='rgba(33,29,22,0.07)'; ctx.fill(dots);
if(watermark) text(watermark, W/2, 505, 210, { alpha:0.045 });
/* riso frame: accent pass offset, ink pass on top (bottom open) */
ctx.lineWidth=5; ctx.lineCap='round';
ctx.save(); ctx.globalAlpha=0.85; ctx.translate(3.5,3.5);
ctx.strokeStyle=C.accent; framePath(); ctx.stroke(); ctx.restore();
ctx.strokeStyle=C.ink; framePath(); ctx.stroke();
/* the pit */
ctx.save(); ctx.strokeStyle=C.ink; ctx.globalAlpha=0.13;
ctx.lineWidth=2; ctx.setLineDash([6,12]);
ctx.beginPath(); ctx.moveTo(F.x+8,H-8); ctx.lineTo(F.x+F.w-8,H-8); ctx.stroke();
ctx.restore();
}
function framePath(){
ctx.beginPath();
ctx.moveTo(F.x,H); ctx.lineTo(F.x,F.y); ctx.lineTo(F.x+F.w,F.y); ctx.lineTo(F.x+F.w,H);
}
function drawBrick(b){
const def=BT[b.type];
let sc=1;
if(state==='intro'){ const p=clamp((introT-b.delay)/0.22,0,1); sc=p<=0?0.0001:easeOutBack(p); }
if(sc<=0.02) return;
ctx.save();
ctx.translate(b.x+b.w/2, b.y+b.h/2); ctx.scale(sc,sc);
ctx.fillStyle=def.color; rrPath(-b.w/2+3,-b.h/2+3,b.w,b.h,4); ctx.fill();
ctx.strokeStyle=C.ink; ctx.lineWidth=2.5; rrPath(-b.w/2,-b.h/2,b.w,b.h,4); ctx.stroke();
if(b.type==='s'){ ctx.fillStyle=C.ink; circle(-b.w/2+9,0,2); circle(b.w/2-9,0,2); }
if(b.type==='g'){
ctx.strokeStyle='rgba(244,237,222,0.85)'; ctx.lineWidth=2;
ctx.beginPath(); ctx.moveTo(-b.w/2+10,4); ctx.lineTo(-b.w/2+17,-4); ctx.stroke();
ctx.beginPath(); ctx.moveTo(-b.w/2+16,4); ctx.lineTo(-b.w/2+20,-1); ctx.stroke();
}
const dmg = def.hp - b.hp;
if(dmg>0){
ctx.strokeStyle=C.ink; ctx.lineWidth=1.5; ctx.lineJoin='round';
ctx.beginPath(); ctx.moveTo(3,-b.h/2); ctx.lineTo(-2,-3); ctx.lineTo(4,1); ctx.lineTo(-2,b.h/2);
if(dmg>=2){ ctx.moveTo(-2,-3); ctx.lineTo(-12,-6); ctx.moveTo(4,1); ctx.lineTo(14,5); }
ctx.stroke();
}
if(b.flash>0){
ctx.globalAlpha=Math.min(b.flash,1)*0.85; ctx.fillStyle=C.paper;
rrPath(-b.w/2,-b.h/2,b.w,b.h,4); ctx.fill(); ctx.globalAlpha=1;
}
ctx.restore();
}
function drawMiniBrick(c){
const bob = state==='menu' ? Math.sin(tNow*2.2 + c.x*0.018)*5 : 0;
ctx.save(); ctx.translate(c.x+c.w/2, c.y+c.h/2+bob);
ctx.fillStyle=c.color; rrPath(-c.w/2+2,-c.h/2+2,c.w,c.h,3); ctx.fill();
ctx.strokeStyle=C.ink; ctx.lineWidth=2; rrPath(-c.w/2,-c.h/2,c.w,c.h,3); ctx.stroke();
ctx.restore();
}
function drawPaddle(){
const p=paddle;
const sx=1+p.pop*0.22, sy=1-p.pop*0.4;
ctx.save();
ctx.translate(p.x, p.y+p.h/2); ctx.rotate(p.tilt); ctx.scale(sx,sy);
ctx.fillStyle=C.accent; rrPath(-p.w/2+3,-p.h/2+3,p.w,p.h,p.h/2); ctx.fill();
ctx.fillStyle=C.ink; rrPath(-p.w/2,-p.h/2,p.w,p.h,p.h/2); ctx.fill();
ctx.fillStyle=C.paper; circle(0,0,2.5);
ctx.restore();
}
function drawBalls(){
for(const b of balls){
const n=b.trail.length;
for(let i=0;i<n;i++){
const tr=b.trail[i], k=(i+1)/n;
ctx.globalAlpha=k*0.28; ctx.fillStyle=C.accent;
circle(tr.x,tr.y,BR*(0.35+0.55*k));
}
ctx.globalAlpha=1;
const st = b.stuck?0:Math.min(b.sp/2600,0.22);
ctx.save();
ctx.translate(b.x,b.y); ctx.rotate(Math.atan2(b.vy,b.vx)); ctx.scale(1+st,1-st*0.7);
ctx.fillStyle=C.accent; circle(2.2,2.2,BR);
ctx.fillStyle=C.ink; circle(0,0,BR);
ctx.restore();
}
if(state==='serve'){ /* aim hint */
const b=balls[0]; if(!b) return;
const ang=(-90+clamp(paddle.vel,-280,280)/280*38)*Math.PI/180;
const dx=Math.cos(ang), dy=Math.sin(ang);
for(let k=1;k<=7;k++){
ctx.globalAlpha=(1-k/8)*0.45; ctx.fillStyle=C.ink;
circle(b.x+dx*24*k, b.y+dy*24*k, 2);
}
ctx.globalAlpha=1;
}
}
function drawPows(){
for(const p of pows){
ctx.save();
ctx.translate(p.x,p.y); ctx.rotate(Math.sin(tNow*4+p.ph)*0.12);
ctx.fillStyle=POWC[p.type]; rrPath(-16+2.5,-9+2.5,32,18,9); ctx.fill();
ctx.fillStyle=C.paper; rrPath(-16,-9,32,18,9); ctx.fill();
ctx.strokeStyle=C.ink; ctx.lineWidth=2.5; rrPath(-16,-9,32,18,9); ctx.stroke();
text(p.type==='L'?'+':p.type, 0, 4.5, 12, { color:C.ink });
ctx.restore();
}
}
function drawParts(){
for(const p of parts){
const a=Math.max(p.life/p.life0,0);
if(p.shape==='rect'){
ctx.save(); ctx.translate(p.x,p.y); ctx.rotate(p.rot);
ctx.globalAlpha=a; ctx.fillStyle=p.color;
ctx.fillRect(-p.w/2,-p.h/2,p.w,p.h); ctx.restore();
} else {
ctx.globalAlpha=a; ctx.strokeStyle=p.color; ctx.lineWidth=2;
ctx.beginPath(); ctx.moveTo(p.x,p.y);
ctx.lineTo(p.x-p.vx*0.035, p.y-p.vy*0.035); ctx.stroke();
}
}
ctx.globalAlpha=1;
for(const r of rings){
const a=Math.max(r.life/0.35,0);
ctx.globalAlpha=a; ctx.strokeStyle=r.color; ctx.lineWidth=3*a;
ctx.beginPath(); ctx.arc(r.x,r.y,r.r,0,TAU); ctx.stroke();
}
ctx.globalAlpha=1;
}
function drawFloats(){
for(const f of floats){
const age=1-f.life/f.life0, sc=easeOutBack(Math.min(age*3,1));
ctx.save(); ctx.translate(f.x,f.y); ctx.scale(sc,sc);
text(f.txt, 0, 0, f.size||13, { color:f.color, alpha:clamp(f.life/f.life0*1.6,0,1) });
ctx.restore();
}
}
function drawHUD(){
text('SCORE', 24, 20, 10, { align:'left', ls:3, alpha:0.5 });
text(String(Math.round(dispScore)).padStart(6,'0'), 24, 44, 24, { align:'left', ls:2 });
if(combo>=2){
ctx.save(); ctx.translate(178,44); ctx.scale(1+comboPop*0.5,1+comboPop*0.5);
text('×'+combo, 0, 0, 18, { color:C.accent, align:'left' });
ctx.restore();
}
text('HI '+String(hi).padStart(6,'0'), W/2, 18, 10, { alpha:0.5, ls:3 });
const nm = (state==='menu'||state==='titleBreak')
? '— RISO BREAKOUT —'
: `STAGE ${level+1} — ${LEVELS[level].name}`;
text(nm, W/2, 40, 12, { ls:3 });
for(let i=0;i<lives;i++){
const x=864-i*22;
ctx.fillStyle=C.accent; circle(x+2,38,6);
ctx.fillStyle=C.ink; circle(x,36,6);
}
text('[M] SOUND '+(muted?'OFF':'ON'), F.x+F.w-10, H-18, 9, { align:'right', alpha:0.35, ls:1 });
}
function panel(w,h){
const x=(W-w)/2, y=(H-h)/2;
ctx.fillStyle=C.accent; rrPath(x+6,y+6,w,h,8); ctx.fill();
ctx.fillStyle=C.paper; rrPath(x,y,w,h,8); ctx.fill();
ctx.strokeStyle=C.ink; ctx.lineWidth=4; rrPath(x,y,w,h,8); ctx.stroke();
return { x, y, w, h };
}
function drawStageCard(){
let a=1;
if(state==='intro') a=Math.min(1,introT*3);
else { if(serveT>1.4) return; a=serveT>0.9 ? 1-(serveT-0.9)/0.5 : 1; }
const L=LEVELS[level];
text('STAGE '+(level+1), W/2, 250, 38, { ls:8, alpha:a });
ctx.save(); ctx.globalAlpha=a;
ctx.strokeStyle=C.accent; ctx.lineWidth=3;
ctx.beginPath(); ctx.moveTo(W/2-140,272); ctx.lineTo(W/2+140,272); ctx.stroke();
ctx.restore();
text(L.name, W/2, 296, 16, { color:C.accent, ls:6, alpha:a });
}
function drawClearCard(){
ctx.fillStyle='rgba(244,237,222,0.35)'; ctx.fillRect(F.x,F.y,F.w,H-F.y);
text('STAGE CLEAR', W/2, 300, 32, { ls:8 });
text('+500 BONUS', W/2, 330, 15, { color:C.accent, ls:4 });
if(clearT>0.8 && Math.sin(tNow*5)>-0.2)
text('SPACE / CLICK — NEXT STAGE', W/2, 380, 12, { alpha:0.6, ls:3 });
}
function drawEndCard(){
ctx.fillStyle='rgba(244,237,222,0.8)'; ctx.fillRect(F.x,F.y,F.w,H-F.y);
const p=panel(480,230);
const won = state==='win';
text(won?'ALL CLEAR':'GAME OVER', W/2, p.y+70, 34, { ls:6 });
ctx.strokeStyle=C.accent; ctx.lineWidth=3;
ctx.beginPath(); ctx.moveTo(p.x+70,p.y+92); ctx.lineTo(p.x+p.w-70,p.y+92); ctx.stroke();
text('SCORE '+String(score).padStart(6,'0'), W/2, p.y+128, 16, { ls:3 });
text('BEST '+String(hi).padStart(6,'0'), W/2, p.y+156, 12, { ls:3, alpha:0.55 });
if(Math.sin(tNow*5)>-0.2)
text('SPACE / CLICK — '+(won?'TITLE':'ONE MORE RUN'), W/2, p.y+196, 12, { color:C.accent, ls:3 });
}
function drawPauseCard(){
ctx.fillStyle='rgba(244,237,222,0.6)'; ctx.fillRect(F.x,F.y,F.w,H-F.y);
const p=panel(380,140);
text('PAUSED', W/2, p.y+62, 26, { ls:8 });
text('P / ESC — RESUME', W/2, p.y+100, 12, { alpha:0.6, ls:3 });
}
function drawTitle(){
for(const c of titleCells) if(!c.broken) drawMiniBrick(c);
if(state!=='menu') return;
text('A RISO-PRINT BREAKOUT', W/2, 104, 11, { ls:5, alpha:0.55 });
text('SIX STAGES · FOUR POWER-UPS · COMBO UP TO ×5', W/2, 330, 11, { ls:3, alpha:0.6, color:C.accent });
ctx.globalAlpha = 0.35+0.65*Math.abs(Math.sin(tNow*2.6));
text('CLICK OR PRESS SPACE', W/2, 408, 18, { ls:5 });
ctx.globalAlpha = 1;
text('MOVE — MOUSE OR ARROW KEYS · LAUNCH — SPACE OR CLICK', W/2, 448, 10, { ls:2, alpha:0.5 });
text('P — PAUSE · M — SOUND', W/2, 470, 10, { ls:2, alpha:0.5 });
}
function render(){
ctx.fillStyle=C.paper; ctx.fillRect(0,0,W,H);
const sx=(Math.random()*2-1)*shake, sy=(Math.random()*2-1)*shake;
const rot=(Math.random()*2-1)*shake*0.0015;
ctx.save();
ctx.translate(W/2,H/2); ctx.rotate(rot); ctx.translate(-W/2+sx,-H/2+sy);
drawBG();
if(state==='menu'||state==='titleBreak') drawTitle();
for(const b of bricks) if(b.alive) drawBrick(b);
drawPows();
drawParts();
if(state!=='menu' && state!=='titleBreak'){ drawPaddle(); drawBalls(); }
drawFloats();
drawHUD();
if(state==='intro'||state==='serve') drawStageCard();
if(state==='clear') drawClearCard();
if(state==='over'||state==='win') drawEndCard();
if(state==='pause') drawPauseCard();
ctx.restore();
ctx.fillStyle=grain; ctx.fillRect(0,0,W,H);
if(flash>0){ ctx.fillStyle=`rgba(230,75,53,${flash*0.28})`; ctx.fillRect(0,0,W,H); }
cv.style.cursor = state==='play' ? 'none' : 'pointer';
}
/* ============================== loop ============================== */
let last=performance.now();
function frame(t){
requestAnimationFrame(frame);
let dt=Math.min((t-last)/1000, 1/30); last=t;
if(hitstop>0){ hitstop-=dt; render(); return; } // freeze-frame, shake keeps jittering
if(state!=='pause') update(dt);
render();
}
buildTitle();
requestAnimationFrame(frame);
</script>
</body>
</html>

