Files
breakout/test/pu-test.js
T
michael 212b5d81a9 Eigener Chip-Tune-Soundtrack im Commander-Keen-Stil, prozedural über WebAudio
- audioBus() mit getrennten Busen: sfxGain für Effekt-Töne, musicGain für Musik
- Level-Theme 148 BPM (D-Moll, Puls-Lead, 16tel-Bass-Arpeggio, Noise-Hi-Hat),
  ruhiges Theme 96 BPM für Ready/Pause/Continue/Levelübergang,
  Game-Over-Kadenz über eigenen Gain-Knoten
- Scheduler mit 16tel-Raster und Vorlaufplanung im Animationsloop, Fadings beim
  Trackwechsel, Audio-Entsperrung beim ersten Klick/Tastendruck
- Option "Musik (Chip-Tune)" und Taste M, Persistenz in breakout.options
- Headless-Regressionstest ins Repo aufgenommen: test/pu-test.js (68 Checks)
- README um Musik, Continue/Checkpoint, Level-Varianten, Debug und Test ergänzt
2026-10-14 15:58:59 +00:00

529 lines
28 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Headless-Regressionstest für breakout/index.html (Node, DOM-/Audio-Stubs)
Aufruf: node test/pu-test.js */
const fs = require('fs');
const path = require('path');
function mkEl(extra) {
const el = {
innerHTML: '', style: { setProperty() {}, getPropertyValue: () => '1' },
classList: { toggle() {}, contains() { return false; }, add() {}, remove() {} },
querySelector: () => mkEl(),
offsetHeight: 40, offsetWidth: 720, clientWidth: 720, clientHeight: 500,
open: false, textContent: '', value: '1',
getBoundingClientRect: () => ({ left: 0, top: 0, width: 720, height: 497 }),
addEventListener() {}, removeEventListener() {}, appendChild() {}, removeChild() {},
setPointerCapture() {}, focus() {}, blur() {}, click() {}
};
return Object.assign(el, extra);
}
function ctxStub() {
const noop = () => {};
const base = {
canvas: null, globalAlpha: 1, shadowBlur: 0, shadowColor: '', fillStyle: '', strokeStyle: '', lineWidth: 1,
save: noop, restore: noop, translate: noop, rotate: noop, scale: noop, setTransform: noop,
beginPath: noop, closePath: noop, moveTo: noop, lineTo: noop, arc: noop, rect: noop, roundRect: noop,
fill: noop, stroke: noop, fillRect: noop, strokeRect: noop, fillText: noop, strokeText: noop, clearRect: noop,
measureText: () => ({ width: 10 }),
createLinearGradient: () => ({ addColorStop() {} }),
createRadialGradient: () => ({ addColorStop() {} }),
createPattern: () => null, drawImage: noop, setLineDash: noop
};
return new Proxy(base, {
get(t2, p) { return p in t2 ? t2[p] : noop; },
set(t2, p, v) { t2[p] = v; return true; }
});
}
const canvasEl = mkEl({ width: 720, height: 497, getContext: () => ctxStub(), requestPointerLock: undefined });
const els = {};
global.document = {
getElementById: (id) => (els[id] = els[id] || (id === 'cv' || id === 'canvas' ? canvasEl : mkEl())),
querySelector: () => mkEl(),
createElement: () => mkEl(),
body: mkEl(), documentElement: mkEl({ clientHeight: 800 }),
activeElement: null,
addEventListener() {}, removeEventListener() {},
fonts: { ready: Promise.resolve() },
hidden: false, pointerLockElement: null, exitPointerLock() {}
};
global.window = {
addEventListener() {}, removeEventListener() {},
innerWidth: 1280, innerHeight: 800, devicePixelRatio: 1,
visualViewport: null
};
global.getComputedStyle = () => ({ paddingTop: '0px', paddingBottom: '0px', paddingLeft: '0px', paddingRight: '0px' });
global.localStorage = {
_s: { 'breakout.scores': JSON.stringify([5000, 4000, 3000, 2000, 1000]), 'breakout.best': '9999' },
getItem(k) { return this._s[k] !== undefined ? this._s[k] : null; },
setItem(k, v) { this._s[k] = v; }
};
let t = 0;
global.performance = { now: () => t };
const audioRec = { oscs: 0, gains: 0, filters: 0, sources: 0, buffers: 0, notes: [] };
function fakeAudio() {
const gv = () => ({ value: 1, setValueAtTime() {}, linearRampToValueAtTime() {}, exponentialRampToValueAtTime() {}, cancelScheduledValues() {} });
const node = () => ({ connect() {}, disconnect() {} });
return {
state: 'running', sampleRate: 44100, destination: node(),
get currentTime() { return t / 1000; },
resume() {},
createGain() { audioRec.gains++; const n = node(); n.gain = gv(); return n; },
createOscillator() {
audioRec.oscs++; const n = node();
n.type = ''; n.frequency = { value: 0 }; n.detune = { value: 0 };
n.start = (tt) => { audioRec.notes.push({ t: tt, f: n.frequency.value, type: n.type }); };
n.stop = () => {};
return n;
},
createBiquadFilter() { audioRec.filters++; const n = node(); n.type = ''; n.frequency = { value: 0 }; return n; },
createBufferSource() { audioRec.sources++; const n = node(); n.buffer = null; n.start = () => {}; n.stop = () => {}; return n; },
createBuffer(ch, len) { audioRec.buffers++; return { getChannelData: () => new Float32Array(len) }; }
};
}
global.window.AudioContext = fakeAudio;
global.window.webkitAudioContext = undefined;
let rafCb = null;
global.requestAnimationFrame = (cb) => { rafCb = cb; };
/* Spiel-Code extrahieren + Test-Hook anhängen */
const html = fs.readFileSync(path.join(__dirname, '..', 'index.html'), 'utf8');
let src = html.split('<script>')[1].split('</script>')[0];
src = src.replace(/\}\)\(\);\s*$/, `
window.__test = {
PU: PU, fx: fx, paddle: paddle, keys: keys, opts: opts,
grab: grab, makeBall: makeBall, buildLevel: buildLevel, resetBall: resetBall, launchAll: launchAll,
hitBrick: hitBrick, collideBricks: collideBricks, collidePaddle: collidePaddle, moveBall: moveBall,
update: update, tickEffects: tickEffects, speedFactor: speedFactor, applyPaddle: applyPaddle,
fireVolley: fireVolley, dropPowerup: dropPowerup, setupPads: setupPads,
doContinue: doContinue, gameOver: gameOver, loseLife: loseLife, newGame: newGame,
resetStats: resetStats, statsHtml: statsHtml, attachPos: attachPos,
variantOf: variantOf, setLevel: setLevel, debugStep: debugStep, movePaddleTo: movePaddleTo,
paddleLive: paddleLive, nudgePaddle: nudgePaddle, movePadsTo: movePadsTo,
audioBus: audioBus, musicTick: musicTick, trackForState: trackForState, setTrack: setTrack,
playCadence: playCadence, midiHz: midiHz, beep: beep,
get musTrack() { return musTrack; }, get musStep() { return musStep; },
get sound() { return sound; }, set sound(v) { sound = v; },
patterns: { ARP_L: ARP_L, BASS_L: BASS_L, MEL_A: MEL_A, MEL_B: MEL_B, ARP_C: ARP_C, BASS_C: BASS_C, MEL_CALM: MEL_CALM },
bpm: { level: BPM_LEVEL, calm: BPM_CALM, steps: MUS_STEPS },
get level() { return level; }, set level(v) { level = v; },
get continues() { return continues; }, set continues(v) { continues = v; },
get checkpoint() { return checkpoint; }, set checkpoint(v) { checkpoint = v; },
get ccUsed() { return ccUsed; }, set ccUsed(v) { ccUsed = v; }, get scoreCC() { return scoreCC; },
get stats() { return stats; }, set stats(v) { stats = v; },
get state() { return state; }, set state(v) { state = v; },
get balls() { return balls; }, set balls(v) { balls = v; },
get bricks() { return bricks; }, set bricks(v) { bricks = v; },
get powerups() { return powerups; }, set powerups(v) { powerups = v; },
get bullets() { return bullets; }, get lives() { return lives; }, set lives(v) { lives = v; },
get score() { return score; }, set score(v) { score = v; },
get variant() { return variant; }, get flip() { return flip; }, get pads() { return pads; },
get scores() { return scores; },
dims: { W: W, H: H, PY: PY, PW: PW, PH: PH, PAD: PAD, TOP: TOP, BR: BR, BH: BH, GAP: GAP, SIDE: SIDE, COLS: COLS, PY_TOP: PY_TOP },
bounds: { SPLIT_TOP: SPLIT_TOP, SPLIT_BOT: SPLIT_BOT, PAD_TOP: PAD_TOP, PAD_BOT: PAD_BOT },
cfg: { CHECKPOINT_EVERY: CHECKPOINT_EVERY, MAX_CONTINUES: MAX_CONTINUES, CONTINUE_TIME: CONTINUE_TIME, START_LIVES: START_LIVES }
};
})();`);
eval(src);
const T = global.window.__test;
function frames(n) { for (let i = 0; i < n; i++) { rafCb(t); t += 1000 / 60; } }
let fails = 0;
function check(name, cond, info) {
console.log((cond ? 'PASS' : 'FAIL') + ' ' + name + (info ? ' [' + info + ']' : ''));
if (!cond) fails++;
}
function id(idn) { return T.PU.find(p => p.id === idn); }
function clearFx() { for (const k in T.fx) T.fx[k] = 0; }
function resetGame() {
T.state = 'playing';
T.level = 1; T.continues = T.cfg.MAX_CONTINUES; T.checkpoint = 1; T.ccUsed = 0;
T.buildLevel(); T.resetBall(); T.launchAll();
clearFx();
T.paddle.w = T.dims.PW;
T.resetStats();
}
function parkBall() { T.balls = [T.makeBall(60, 400, -1, 0)]; }
function padsAt(y) { for (const p of T.pads) p.y = y - p.w / 2; }
/* 0) Pickup: fallendes Power-up wird eingesammelt */
resetGame();
T.powerups = [{ x: T.paddle.x + T.paddle.w / 2, y: T.dims.PY - 60, vy: 130, vx: 0, t: 0, p: id('expand') }];
frames(30);
check('Pickup: fallendes Power-up wird eingesammelt', T.fx.expand > 0, 'expand=' + T.fx.expand.toFixed(1) + 's');
/* 1) expand / shrink */
resetGame(); parkBall(); T.grab(id('expand'), 340, 200);
check('expand: Paddle +60 %', Math.abs(T.paddle.w - T.dims.PW * 1.6) < 0.01, 'w=' + T.paddle.w.toFixed(1));
frames(Math.ceil(12.2 * 60));
check('expand: läuft nach 12 s ab', T.fx.expand === 0 && Math.abs(T.paddle.w - T.dims.PW) < 0.01, 'w=' + T.paddle.w.toFixed(1));
resetGame(); parkBall(); T.grab(id('shrink'), 340, 200);
check('shrink: Paddle -38 %', Math.abs(T.paddle.w - T.dims.PW * 0.62) < 0.01, 'w=' + T.paddle.w.toFixed(1));
/* 2) multi / life */
resetGame(); T.grab(id('multi'), 340, 200);
check('multi: 3 Bälle', T.balls.length === 3, 'balls=' + T.balls.length);
resetGame(); const l0 = T.lives; T.grab(id('life'), 340, 200);
check('life: +1 Leben', T.lives === l0 + 1, 'lives=' + T.lives);
/* 3) laser: Salve trifft Steine */
resetGame(); parkBall(); T.grab(id('laser'), 340, 200);
const s3 = T.score;
frames(120);
check('laser: Kugeln zerstören Steine und bringen Punkte', T.score > s3 || T.stats.down > 0, 'score+' + (T.score - s3) + ' down=' + T.stats.down);
/* 4) slow / fast */
resetGame(); parkBall();
const f0 = T.speedFactor(); T.grab(id('slow'), 340, 200);
const fSlow = T.speedFactor(); T.grab(id('fast'), 340, 200);
check('slow/fast: Speed-Faktor 0.72 / 1.3',
f0 === 1 && Math.abs(fSlow - 0.72) < 0.001 && Math.abs(T.speedFactor() - 0.72 * 1.3) < 0.001,
'f=' + f0 + '/' + fSlow.toFixed(2) + '/' + T.speedFactor().toFixed(2));
/* 5) sticky: Ball haftet und wird neu geschossen */
resetGame(); T.grab(id('sticky'), 340, 200);
T.balls = [T.makeBall(T.paddle.x + T.paddle.w / 2, T.dims.PY - 40, 0, 300)];
frames(10);
const stuck = T.balls[0] && T.balls[0].attached;
frames(90);
check('sticky: Ball wird gefangen und neu geschossen', stuck && T.balls.length === 1 && !T.balls[0].attached,
'gefangen=' + stuck + ' attached=' + (T.balls[0] && T.balls[0].attached));
/* 6) drill: durchboert Steine ohne Abprall */
resetGame(); parkBall(); T.grab(id('drill'), 340, 200);
const br0 = T.bricks.filter(b => b.hp > 0)[0];
const db = T.makeBall(br0.x + br0.w / 2, br0.y - 2, 0, 200);
const vyBefore = db.vy;
T.bricks = [br0]; T.balls = [db];
T.collideBricks(db);
check('drill: Stein wird getroffen, Richtung bleibt', br0.hp < br0.max && db.vy === vyBefore, 'hp=' + br0.hp + '/' + br0.max + ' vy=' + db.vy);
/* 7) Paddle: Tasten und freie Fahrt */
resetGame(); parkBall();
const x0 = T.paddle.x; T.keys.right = true; frames(15); T.keys.right = false;
check('Paddle: Taste rechts bewegt', T.paddle.x > x0 + 10, 'x=' + T.paddle.x.toFixed(1));
resetGame(); parkBall(); T.grab(id('free'), 340, 200);
check('free: Power-up aktiv', T.fx.free > 0, 'free=' + T.fx.free.toFixed(1) + 's');
T.keys.up = true; frames(60); T.keys.up = false;
const upY = T.paddle.y;
check('free: Paddle fährt mit hoch nach oben', upY <= T.dims.PY_TOP + 1, 'y=' + upY.toFixed(1));
T.keys.down = true; frames(30); T.keys.down = false;
check('free: Paddle fährt mit runter wieder nach unten', T.paddle.y > upY + 20, 'y=' + T.paddle.y.toFixed(1));
const bDown = T.makeBall(340, T.paddle.y + T.dims.PH + 12, 0, -300);
T.balls = [bDown]; T.paddle.x = 340 - T.paddle.w / 2; frames(10);
check('free: Abprall an der Unterseite kehrt vy um', T.balls[0].vy > 0, 'vy=' + T.balls[0].vy.toFixed(1));
clearFx(); frames(Math.ceil(1.2 * 60));
check('free: nach Ablauf zurück zur Grundlinie', Math.abs(T.paddle.y - T.dims.PY) < 0.01, 'y=' + T.paddle.y.toFixed(1));
/* 8) free + sticky: gehaltener Ball klebt an der Paddlehöhe */
resetGame(); T.grab(id('free'), 340, 200); T.grab(id('sticky'), 340, 200);
T.keys.up = true; frames(60); T.keys.down = true; frames(30); T.keys.down = false;
const sb = T.balls[0];
check('free+sticky: Ball wird gefangen', sb.attached === true, 'attached=' + sb.attached);
check('free+sticky: gehaltener Ball sitzt an der Paddlehöhe',
sb.attached && Math.abs(sb.y - (T.paddle.y - sb.r - 2)) < 0.01 && sb.y < T.dims.PY - 100,
'ball y=' + sb.y.toFixed(1) + ' paddle y=' + T.paddle.y.toFixed(1));
T.keys.up = true; frames(30); T.keys.up = false;
check('free+sticky: gehaltener Ball folgt dem Paddle',
T.balls[0].attached && Math.abs(T.balls[0].y - (T.paddle.y - T.balls[0].r - 2)) < 0.01 && T.paddle.y < 150,
'ball y=' + T.balls[0].y.toFixed(1) + ' paddle y=' + T.paddle.y.toFixed(1));
clearFx();
/* 9) attachPos nutzt die aktuelle Paddlehöhe */
check('attachPos folgt dem Paddle (kein festes PY)', (function () {
const b = T.makeBall(0, 0, 0, 0); b.attached = true; b.off = 0;
T.paddle.axis = 'h'; T.paddle.y = 200;
const q = T.attachPos(b);
return Math.abs(q.y - (200 - b.r - 2)) < 0.01 && Math.abs(q.x - (T.paddle.x + T.paddle.w / 2)) < 0.01;
})(), 'attachPos hängt an paddle.y');
/* 10) Ready: gehaltener Startball folgt dem Paddle */
resetGame(); T.grab(id('free'), 340, 200);
T.resetBall();
T.paddle.y = 300; T.paddle.x = 200; frames(2);
check('Ready: Startball klebt am Paddle (folgt der Bewegung)',
T.state === 'ready' && T.balls[0].attached && Math.abs(T.balls[0].y - (T.paddle.y - T.balls[0].r - 2)) < 0.01 && T.balls[0].y < T.dims.PY - 50,
'state=' + T.state + ' ball y=' + T.balls[0].y.toFixed(1) + ' paddle y=' + T.paddle.y.toFixed(1));
clearFx(); T.paddle.y = T.dims.PY;
/* 11) Paddle-Eingabe nur in Playing/Ready */
resetGame(); T.state = 'playing';
T.movePaddleTo(123, undefined);
check('Playing: movePaddleTo bewegt das Paddle', Math.abs(T.paddle.x - 123) < 0.01, 'x=' + T.paddle.x.toFixed(1));
T.state = 'paused';
T.movePaddleTo(600, undefined);
check('Pause: movePaddleTo bewegt das Paddle nicht', !T.paddleLive() && Math.abs(T.paddle.x - 123) < 0.01, 'x=' + T.paddle.x.toFixed(1));
T.keys.left = true; frames(3); T.keys.left = false;
check('Pause: Paddle steht still (Tasten)', Math.abs(T.paddle.x - 123) < 0.01, 'x=' + T.paddle.x.toFixed(1));
T.state = 'ready';
check('Ready: Zielen bleibt möglich', T.movePaddleTo(300, undefined) && Math.abs(T.paddle.x - 300) < 0.01, 'x=' + T.paddle.x.toFixed(1));
/* 12) kein Tunneln bei schnellem Paddle (Maus-Sprung) */
resetGame(); T.grab(id('free'), 340, 200);
const jb = T.makeBall(340, 300, 0, 300); T.balls = [jb];
T.paddle.y = 340; T.paddle.prevY = 340;
frames(1);
T.paddle.y = 240;
const livesBefore12 = T.lives;
frames(1);
check('free+Mausjump: Ball prallt ab statt durchs Paddle zu fliegen',
jb.vy < 0 && T.lives === livesBefore12 && T.state === 'playing', 'vy=' + jb.vy.toFixed(1) + ' lives=' + T.lives);
check('free+Mausjump: kein Wahnsinnsspeed durch Paddle-Ruck', Math.hypot(jb.vx, jb.vy) < 700,
'speed=' + Math.hypot(jb.vx, jb.vy).toFixed(1));
/* 13) schnelle Gegenfahrt fängt schnellen Ball */
resetGame(); T.grab(id('free'), 340, 200);
T.paddle.y = 420; T.paddle.prevY = 420;
const fb = T.makeBall(340, 300, 0, 1); fb.speed = 900; fb.vy = 900; T.balls = [fb];
const livesBefore13 = T.lives;
T.keys.up = true;
let bounced13 = false;
for (let i = 0; i < 90 && !bounced13; i++) { frames(1); if (fb.vy < 0) bounced13 = true; }
T.keys.up = false;
check('free+Gegenfahrt: schneller fallender Ball wird gefangen', bounced13 && T.lives === livesBefore13,
'bounced=' + bounced13 + ' lives=' + T.lives);
/* 14) ohne free: normales Ballverhalten */
resetGame(); parkBall(); frames(60);
check('ohne free: Ballverhalten unverändert', T.balls.length === 1 && T.balls[0].speed > 0 && T.state === 'playing',
'balls=' + T.balls.length + ' state=' + T.state);
/* 15) Checkpoint alle 5 Level */
check('Checkpoint-Intervall: CHECKPOINT_EVERY = 5', T.cfg.CHECKPOINT_EVERY === 5, 'every=' + T.cfg.CHECKPOINT_EVERY);
/* 16) Tod auf Level 7 -> Continue-Abfrage */
resetGame(); T.checkpoint = 5; T.level = 7; T.lives = 1; T.score = 12345; T.state = 'playing'; T.balls = [];
frames(2);
check('Tod auf Level 7: Continue-Abfrage statt Game Over', T.state === 'continue' && T.continues === T.cfg.MAX_CONTINUES,
'state=' + T.state + ' continues=' + T.continues);
T.doContinue();
check('Continue: Checkpoint-Level, volle Leben, Punkte bleiben',
T.level === 5 && T.lives === T.cfg.START_LIVES && T.continues === T.cfg.MAX_CONTINUES - 1 && T.score === 12345 && T.ccUsed === 1,
'level=' + T.level + ' lives=' + T.lives + ' continues=' + T.continues);
check('Continue: Power-up-Effekte zurückgesetzt', Object.keys(T.fx).every(k => T.fx[k] === 0) && Math.abs(T.paddle.w - T.dims.PW) < 0.01,
'w=' + T.paddle.w.toFixed(1));
/* 17) Countdown abgelaufen -> echtes Game Over */
resetGame(); T.checkpoint = 5; T.level = 7; T.lives = 1; T.score = 7777; T.state = 'playing'; T.balls = [];
frames(2);
frames(Math.ceil((T.cfg.CONTINUE_TIME + 0.3) * 60));
check('Countdown abgelaufen: Game Over, Continues unverändert', T.state === 'over' && T.continues === T.cfg.MAX_CONTINUES,
'state=' + T.state + ' continues=' + T.continues);
/* 18) Game Over nach Continue -> CC-Markierung im Highscore */
resetGame(); T.checkpoint = 5; T.level = 7; T.lives = 1; T.score = 6666; T.continues = 1; T.state = 'playing'; T.balls = [];
frames(2);
T.doContinue();
T.level = 9; T.lives = 1; T.state = 'playing'; T.balls = [];
frames(2);
const saved18 = JSON.parse(global.localStorage._s['breakout.scores'] || '[]');
const meta18 = JSON.parse(global.localStorage._s['breakout.scoreCC'] || '{}');
check('Game Over nach Continue: Score gespeichert und mit 1 CC markiert',
T.state === 'over' && saved18.indexOf(6666) >= 0 && meta18['6666'] === 1,
'saved=' + saved18.join(',') + ' meta=' + JSON.stringify(meta18));
/* 19) Statistik: zerstörte Blöcke pro Klasse + Treffer */
resetGame(); T.score = 0;
const bb1 = T.bricks.filter(b => b.max === 1)[0], bb2 = T.bricks.filter(b => b.max === 2)[0], bb3 = T.bricks.filter(b => b.max === 3)[0];
T.hitBrick(bb1); T.hitBrick(bb2); T.hitBrick(bb2); T.hitBrick(bb3);
check('Statistik: zerstörte Blöcke pro Klasse, Treffer separat',
T.stats.blk[1] === 1 && T.stats.blk[2] === 1 && T.stats.blk[3] === undefined && T.stats.down === 2 && T.stats.hits === 4,
'blk=' + JSON.stringify(T.stats.blk) + ' down=' + T.stats.down + ' hits=' + T.stats.hits);
/* 20) Statistik: Power-ups pro Typ */
T.grab(id('expand'), 340, 200); T.grab(id('expand'), 340, 220); T.grab(id('laser'), 340, 200); T.grab(id('free'), 340, 200);
check('Statistik: Power-ups pro Typ gezählt',
T.stats.pu.expand === 2 && T.stats.pu.laser === 1 && T.stats.pu.free === 1, 'pu=' + JSON.stringify(T.stats.pu));
/* 21) Game-Over-Screen zeigt Statistik */
T.lives = 0; T.continues = 0; T.state = 'playing'; T.balls = [];
frames(2);
const overHtml = els.msg.innerHTML || '';
check('Game Over: Block- und Power-up-Statistik im Screen',
T.state === 'over' && overHtml.indexOf('Blöcke') >= 0 && overHtml.indexOf('1×-Block') >= 0 &&
overHtml.indexOf('Treffer') >= 0 && overHtml.indexOf('Breites Paddle') >= 0,
overHtml.replace(/\s+/g, ' ').slice(0, 110));
/* 22) Neues Spiel setzt Statistik zurück */
T.newGame();
check('Neues Spiel: Statistik leer',
Object.keys(T.stats.blk).length === 0 && T.stats.down === 0 && T.stats.hits === 0 && Object.keys(T.stats.pu).length === 0,
JSON.stringify(T.stats));
/* 23) Spezial-Level-Zyklus jedes 4. Level */
const vsched = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16].map(l => T.variantOf(l));
check('Spezial-Level jedes 4. Level (Pyramide, Überkopf, Festung, Zwei Paddel)',
vsched[0] === 'normal' && vsched[1] === 'normal' && vsched[2] === 'normal' &&
vsched[3] === 'pyramid' && vsched[7] === 'upside' && vsched[11] === 'fort' && vsched[15] === 'split',
vsched.join(','));
/* 24) Überkopf */
T.level = 8; T.buildLevel();
check('Level 8 = Überkopf: Flip aktiv, Physik intern unverändert',
T.variant === 'upside' && T.flip === true && Math.abs(T.paddle.y - T.dims.PY) < 0.01 && T.pads.length === 1 && T.bricks.length > 0,
'variant=' + T.variant + ' flip=' + T.flip + ' bricks=' + T.bricks.length);
/* 25) Pyramide und Festung */
T.level = 4; T.buildLevel();
const pyTop = T.bricks.filter(b => Math.abs(b.y - T.dims.TOP) < 1).length;
const pyBot = T.bricks.filter(b => Math.abs(b.y - (T.dims.TOP + 7 * (T.dims.BH + T.dims.GAP))) < 1).length;
check('Level 4 = Pyramide: schmale Spitze, breite Basis', T.variant === 'pyramid' && pyTop >= 2 && pyTop < pyBot,
'top=' + pyTop + ' bottom=' + pyBot);
T.level = 12; T.buildLevel();
check('Level 12 = Festung: harter Rahmen, weicher Kern',
T.variant === 'fort' && T.bricks.some(b => b.max >= 3) && T.bricks.some(b => b.max === 1),
'maxHp=' + Math.max.apply(null, T.bricks.map(b => b.max)));
/* 26) Zwei Paddel: Geometrie und Cluster */
T.level = 16; T.buildLevel();
const midY = (T.bounds.SPLIT_TOP + T.bounds.SPLIT_BOT) / 2;
check('Level 16 = Zwei Paddel: vertikale Paddel links und rechts',
T.variant === 'split' && T.pads.length === 2 && T.pads[0].axis === 'v' && T.pads[1].axis === 'v' &&
Math.abs(T.pads[0].x - T.dims.PAD) < 0.01 && Math.abs(T.pads[1].x - (T.dims.W - T.dims.PAD - T.dims.PH)) < 0.01,
'pads=' + T.pads.map(p => p.axis + '@' + p.x.toFixed(0)).join(' '));
check('Split: Steine nur in der Mitte, Bahnen oben/unten frei',
T.bricks.length > 0 && T.bricks.every(b => b.y > midY - 120 && b.y + b.h < midY + 120) &&
T.bricks.every(b => b.x > 100 && b.x + b.w < T.dims.W - 100), 'bricks=' + T.bricks.length);
/* 27) Seitpaddle fängt den Ball */
T.lives = 3; T.resetBall(); T.state = 'playing'; padsAt(midY);
const sp1 = T.makeBall(90, midY, -420, 0); T.balls = [sp1];
const lv27 = T.lives;
let flips27 = 0, prevVx27 = sp1.vx;
for (let i = 0; i < 30; i++) { frames(1); if (prevVx27 < 0 && sp1.vx > 0) flips27++; prevVx27 = sp1.vx; }
check('Split: linkes Paddle fängt nach links fliegenden Ball ab',
flips27 >= 1 && T.lives === lv27 && T.state === 'playing', 'Reflektionen=' + flips27 + ' lives=' + T.lives);
/* 28) am Seitpaddle vorbei kostet ein Leben */
T.level = 16; T.buildLevel(); T.lives = 3; T.resetBall(); T.state = 'playing'; padsAt(midY);
T.balls = [T.makeBall(90, T.bounds.SPLIT_BOT - 16, -420, 0)];
frames(25);
check('Split: Ball am Paddle vorbei -> ein Leben weg', T.lives === 2, 'lives=' + T.lives + ' state=' + T.state);
/* 29) Fangball am Seitpaddle */
T.level = 16; T.buildLevel(); T.lives = 3; T.resetBall(); T.state = 'playing'; clearFx(); T.fx.sticky = 8; padsAt(midY);
T.balls = [T.makeBall(90, midY, -420, 0)];
frames(10);
const caught29 = T.balls[0].attached && T.balls[0].pad && T.balls[0].pad.axis === 'v';
let vx29 = 0;
for (let i = 0; i < 120 && !vx29; i++) { frames(1); if (!T.balls[0].attached) vx29 = T.balls[0].vx; }
check('Split: Fangball haftet am Seitpaddle und fliegt zurück ins Feld',
caught29 && vx29 > 0 && T.lives === 3, 'caught=' + caught29 + ' vx=' + vx29.toFixed(1));
/* 30) Split: Laser und Freies Paddle fallen nicht */
T.level = 16; T.buildLevel(); T.powerups = [];
for (let i = 0; i < 300; i++) T.dropPowerup(340, 240);
check('Split: Laser und Freies Paddle nicht im Drop-Pool',
T.powerups.length > 5 && T.powerups.every(pu => pu.p.id !== 'laser' && pu.p.id !== 'free'), 'drops=' + T.powerups.length);
/* 31) Continue landet im Checkpoint-Speziallevel */
T.level = 11; T.checkpoint = 12; T.continues = 2; T.lives = 1; T.state = 'playing'; T.balls = [];
frames(2);
T.doContinue();
check('Continue: Speziallevel am Checkpoint wird aufgebaut', T.level === 12 && T.variant === 'fort',
'level=' + T.level + ' variant=' + T.variant);
/* 32) Debug: Level direkt anwählen */
T.opts.debug = false;
T.debugStep(1);
check('Debug aus: debugStep ändert nichts', T.level === 12, 'level=' + T.level);
T.opts.debug = true;
T.setLevel(16);
check('Debug an: setLevel springt direkt ins Split-Level',
T.level === 16 && T.variant === 'split' && T.pads.length === 2 && T.state === 'ready',
'level=' + T.level + ' variant=' + T.variant + ' state=' + T.state);
T.debugStep(4);
check('Debug: +4 springt auf das nächste Spezial-Level (20 = Pyramide)',
T.level === 20 && T.variant === 'pyramid', 'level=' + T.level + ' variant=' + T.variant);
T.setLevel(999);
check('Debug: Level wird auf 1..99 geklemmt', T.level === 99 && T.bricks.length > 0, 'level=' + T.level);
T.setLevel(1);
check('Debug: zurück auf Level 1 (normal)', T.level === 1 && T.variant === 'normal', 'variant=' + T.variant);
T.setLevel(5);
check('Debug: Sprung auf Checkpoint-Level setzt Checkpoint', T.checkpoint === 5, 'checkpoint=' + T.checkpoint);
/* 33) Split-Steuerung: Mauspunkt und Nudge */
T.opts.debug = true; T.setLevel(16);
T.movePaddleTo(0, 200);
check('Split: Mauspunkt zentriert beide Seitenpaddel',
Math.abs(T.pads[0].y - (200 - T.pads[0].w / 2)) < 0.01 && Math.abs(T.pads[1].y - T.pads[0].y) < 0.01,
'y=' + T.pads.map(p => p.y.toFixed(1)).join('/'));
T.movePaddleTo(0, T.dims.H);
check('Split: Paddel bleibt in den Feldgrenzen',
T.pads[0].y >= T.bounds.PAD_TOP - 0.01 && T.pads[0].y <= T.bounds.PAD_BOT - T.pads[0].w + 0.01,
'y=' + T.pads[0].y.toFixed(1));
T.movePadsTo(200);
const y33 = T.pads[0].y;
for (let i = 0; i < 5; i++) T.nudgePaddle(0, 10);
check('Split: fünf Mausbewegungen à 10 px verschieben 50 px',
Math.abs(T.pads[0].y - (y33 + 50)) < 0.01 && Math.abs(T.pads[1].y - T.pads[0].y) < 0.01,
'y=' + y33.toFixed(1) + ' -> ' + T.pads[0].y.toFixed(1));
T.state = 'playing';
const y33b = T.pads[0].y;
T.keys.up = true; frames(15); T.keys.up = false;
check('Split: Tasten hoch/runter bewegen beide Seitenpaddel',
T.pads[0].y < y33b - 50 && Math.abs(T.pads[1].y - T.pads[0].y) < 0.01, 'y=' + y33b.toFixed(1) + ' -> ' + T.pads[0].y.toFixed(1));
T.setLevel(1); T.opts.debug = false;
/* 34) Musik: Tracks je Spielzustand */
T.audioBus();
T.state = 'playing';
check('Musik: Level-Track beim Spielen, ruhiger Track in Ready/Pause/Continue',
T.trackForState() === 'level' &&
(T.state = 'ready', T.trackForState() === 'calm') &&
(T.state = 'paused', T.trackForState() === 'calm') &&
(T.state = 'continue', T.trackForState() === 'calm') &&
(T.state = 'levelclear', T.trackForState() === 'calm') &&
(T.state = 'over', T.trackForState() === 'none'),
'playing/ready/paused/continue/levelclear/over geprüft');
T.state = 'playing';
/* 35) Musik: Tempo und Muster */
check('Musik: konstante Tempi 148 / 96 BPM, 128 Steps Loop',
T.bpm.level === 148 && T.bpm.calm === 96 && T.bpm.steps === 128, JSON.stringify(T.bpm));
check('Musik: Lead-Muster sind Notentripel im spielbaren MIDI-Bereich',
[T.patterns.MEL_A, T.patterns.MEL_B, T.patterns.MEL_CALM].every(m =>
Array.isArray(m) && m.length >= 8 && m.every(n => n.length === 3 && n[1] >= 24 && n[1] <= 100 && n[2] > 0)) &&
T.patterns.ARP_L.join(',') === '0,7,12,7' && T.patterns.BASS_L.length === 4 && T.patterns.BASS_C.length === 4,
'MEL_A=' + T.patterns.MEL_A.length + ' MEL_B=' + T.patterns.MEL_B.length);
check('Musik: Tonhöhen-Umrechnung MIDI 69 = 440 Hz', Math.abs(T.midiHz(69) - 440) < 0.001 && Math.abs(T.midiHz(81) - 880) < 0.001,
'A4=' + T.midiHz(69).toFixed(1) + ' Hz, A5=' + T.midiHz(81).toFixed(1) + ' Hz');
/* 36) Musik: Scheduler erzeugt Stimmen im Level-Track */
const osc36 = audioRec.oscs;
T.setTrack('none'); T.setTrack('level');
frames(60);
const made36 = audioRec.oscs - osc36;
check('Musik: 1 s Level-Track erzeugt Bass, Lead und Hi-Hat',
made36 > 20 && T.musTrack === 'level' && audioRec.sources > 0 && audioRec.filters > 0,
'Oszillatoren+' + made36 + ' Noise-Quellen=' + audioRec.sources);
/* 37) Musik: Game-Over-Kadenz und Stummschaltung */
const osc37 = audioRec.oscs;
T.gameOver();
frames(2);
check('Musik: Game Over spielt die Kadenz und stoppt die Loops', audioRec.oscs - osc37 >= 6 && T.musTrack === 'none',
'Oszillatoren+' + (audioRec.oscs - osc37) + ' track=' + T.musTrack);
const osc38 = audioRec.oscs;
T.opts.music = false;
T.state = 'playing'; frames(30);
check('Musik aus: es werden keine Musikstimmen mehr geplant', audioRec.oscs - osc38 < 4 && T.musTrack === 'none',
'Oszillatoren+' + (audioRec.oscs - osc38) + ' track=' + T.musTrack);
T.opts.music = true;
/* 39) Musik: die geplanten Töne sind hörbar und verschieden */
audioRec.notes.length = 0;
T.state = 'playing'; T.setTrack('none'); T.setTrack('level');
frames(45);
const ns39 = audioRec.notes;
const uniq39 = new Set(ns39.map(n => Math.round(n.f)));
check('Musik: geplante Töne im hörbaren Bereich, mehrere Tonhöhen',
ns39.length > 15 && ns39.every(n => n.f >= 40 && n.f <= 2500) && uniq39.size >= 8,
'Noten=' + ns39.length + ' Tonhöhen=' + uniq39.size + ' z.B. ' + ns39.slice(0, 6).map(n => n.f.toFixed(0)).join('/'));
console.log(fails === 0 ? '\nALLE TESTS OK' : '\n' + fails + ' FEHLER');
process.exit(fails ? 1 : 0);