From 212b5d81a982e1f13784ff2bcf13c0a7a87dd2b9 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 14 Oct 2026 15:58:59 +0000 Subject: [PATCH] =?UTF-8?q?Eigener=20Chip-Tune-Soundtrack=20im=20Commander?= =?UTF-8?q?-Keen-Stil,=20prozedural=20=C3=BCber=20WebAudio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- README.md | 59 +++++- index.html | 139 ++++++++++++- test/pu-test.js | 528 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 719 insertions(+), 7 deletions(-) create mode 100644 test/pu-test.js diff --git a/README.md b/README.md index 3e74b02..61d6e05 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,19 @@ Komplettes Breakout in einer einzigen HTML-Datei — ohne Build, ohne Abhängigk | Eingabe | Wirkung | |---|---| | Klick ins Spielfeld | Maus fangen (Pointer-Lock) und Ball abschießen | -| `ESC` | Maus freigeben | +| `ESC` | Maus freigeben (einmaliges Klick in Pause ignoriert das Spielfeld) | | Maus / Touch | Paddle folgt | -| Leertaste | Ball abschießen | +| Leertaste | Ball abschießen, Laser-Salve (bei Auto-Feuer aus) | | ← → | Paddle per Tastatur | +| ↑ ↓ | freies Paddle hoch/runter, Seitenpaddel in Zwei-Paddel-Leveln | | `P` | Pause | | `R` | Neustart | +| `M` | Musik an/aus | +| `[` `]` | Debug-Modus: ein Level zurück/vor | | `Optionen`-Button | Optionsmenü öffnen (pausiert das Spiel) | +In Pause, Continue-Abfrage und Game Over steht das Paddle still; Klicks in der Zeit werden nicht verschluckt, sondern lösen erst die Abfrage bzw. das neue Spiel aus. + ## Optionen Umschaltbar, Persistenz via `localStorage` (`breakout.options`): @@ -26,20 +31,68 @@ Umschaltbar, Persistenz via `localStorage` (`breakout.options`): - **Rundes Paddle** — an: Abprall an der Bogen-Normalen; aus: klassischer fester Positionswinkel - **Auto-Feuer (Laser)** — an: Laser feuert alle 0,34 s automatisch; aus: eine Salve pro Klick/Leertaste - **Power-ups** — aus: keine Drops mehr, aktive Effekte werden beendet +- **Musik (Chip-Tune)** — an: eigene Musik im Spiel, aus: nur Effekt-Töne +- **Debug: Level-Wahl** — an: Level direkt anwählen (siehe *Debug*) + +## Musik + +Eigene Komposition im Chip-Tune-Stil (Commander-Keen-artig), komplett prozedural über WebAudio — keine Audiodateien, keine Samples: + +- **Level-Theme:** 148 BPM, D-Moll, Lead (Puls), 16tel-Bass-Arpeggio, Noise-Hi-Hat, 8-Takte-Loop +- **Ruhiges Theme:** 96 BPM, Am–F–C–G, Dreiklang-Arpeggios in Ready, Pause, Continue und Levelübergang +- **Game Over:** kurze Kadenz (absteigende Line + Bass-Schlag), danach Stille +- Sounds laufen über einen eigenen Bus, damit die Musik die Effekt-Töne nicht zudeckt; `M` oder die Option schaltet die Musik stumm +- Der Browser startet Audio erst nach der ersten Eingabe (Autoplay-Regel): der erste Klick/Tastendruck entsperrt den Klang + +## Continue und Checkpoint + +- Checkpoint alle 5 Level (`CHECKPOINT_EVERY`), 3 Continues pro Spiel +- Nach dem letzten Leben: 10-Sekunden-Abfrage (Klick oder Leertaste = Continue); Punkte bleiben, Power-ups und Ball werden zurückgesetzt +- Mit Continue erreichte Punktzahlen bekommen im Highscore den Vermerk `(n CC)` + +## Level-Varianten + +Jedes 4. Level bringt ein Spezial-Level, Zyklus Pyramide → Überkopf → Festung → Zwei Paddel (`variantOf`), danach wieder normale Level. Das HUD zeigt das Kürzel (PYR/ÜBER/FEST/2P) und jedes Level wird kurz angesagt. + +- **Pyramide** — Spitze oben, breite Basis +- **Überkopf** — Steine unten, nur spiegelverkehrt gezeichnet (Physik unverändert) +- **Festung** — harter Rahmen, weicher Kern +- **Zwei Paddel** — Steine in der Mitte, vertikale Paddel links und rechts, freie Bahnen oben und unten; Ball darf oben/unten hinüber. Laser und freies Paddle fallen hier nicht + +## Debug: Level-Wahl + +Im Optionsmenü einschalten; dann erscheint unter dem Spielfeld `- [Level] +` (und `[` `]` auf der Tastatur). Ein Sprung auf ein Checkpoint-Level (5, 10, …) setzt auch den Checkpoint. Beim Neustart (`R`) beginnt wieder Level 1. + +Ohne Menü auch per URL: `?level=16`, `?variant=split|upside|fort|pyramid`, `?debug=1`. ## Power-ups -**Gut:** `E` breites Paddle · `M` Dreifach-Ball · `L` Laser · `≈` Zeitlupe · `C` Fangball · `◆` Durchschlag · `+` extra Leben +**Gut:** `E` breites Paddle · `M` Dreifach-Ball · `L` Laser · `≈` Zeitlupe · `C` Fangball · `◆` Durchschlag · `+` extra Leben · `✛` freies Paddle (in der Höhe frei beweglich) **Malus:** `i` schmales Paddle · `»` Turbo +## Statistik + +Der Game-Over-Screen zeigt die Session: zerstörte Blöcke nach Art (1×/2×/3×/Armour/Laser), Treffer gesamt und jede Power-up-Art mit Anzahl. + +## Test + +``` +node test/pu-test.js +``` + +Headless-Regressionstest (Node, DOM- und Audio-Stubs) über Power-ups, Checkpoint/Continue, Session-Statistik, Level-Varianten, Split-Physik und Musik. Erwartete Ausgabe: `ALLE TESTS OK`. + ## Technik - Canvas mit Neon-Gradienten, Glow, Ball-Trail, Partikeln, Screenshake - Substep-Kollision (kein Tunneling durch Steine) - Gebogenes Paddle: Abprall an der Normalen des Paddel-Bogens (Winkel aus Anflug + Position, kein fester Positionswinkel) +- Swept-Paddle-Kollision: Paddle-Wege zwischen zwei Abfragen werden überstrichen, damit schnelle Paddle-Sprünge den Ball nicht durchlassen +- Kollision je Paddle-Achse (horizontal/vertikal) mit eigener Auslenkung und Todesachse - Combo-Sound: Tonhöhe steigt mit jedem Stein in der Combo-Kette - Combo-Multiplikator, Leben, Level, Steine mit Hitpoints +- Musik-Scheduler: 16tel-Raster mit Vorlaufplanung im Animationsloop, Fadings über Gain-Bus - Power-up-HUD mit Countdown-Balken, Highscore-Top-5 via `localStorage` (Beim Game Over einsortiert) - Breites Fenster (ab 940 px): Statuswerte (Punkte/Bestwert/Level/Combo/Leben) als Liste links, aktive Power-ups + Legende immer offen rechts; schmale/niedrige Fenster stapeln alles unter das Spielfeld - Automatische Skalung: Spielfeld löst Fensterbreite und -höhe gemeinsam auf, UI skaliert proportional, HiDPI-scharf, Kompakt-Modus bei niedrigen Fenstern diff --git a/index.html b/index.html index 7c44836..90c8b74 100644 --- a/index.html +++ b/index.html @@ -222,6 +222,7 @@ + @@ -279,6 +280,7 @@ var optRound = document.getElementById('optRound'); var optAuto = document.getElementById('optAuto'); var optPU = document.getElementById('optPU'); + var optMusic = document.getElementById('optMusic'); var optDebug = document.getElementById('optDebug'); var optClose = document.getElementById('optClose'); var dbgBox = document.getElementById('dbg'); @@ -388,7 +390,7 @@ '
Power-ups' + pc.join('') + '
'; } - var opts = { round: true, autoFire: true, pu: true, debug: false }; + var opts = { round: true, autoFire: true, pu: true, debug: false, music: true }; try { var ov = JSON.parse(localStorage.getItem('breakout.options') || 'null'); if (ov && typeof ov === 'object') { @@ -396,6 +398,7 @@ opts.autoFire = ov.autoFire !== false; opts.pu = ov.pu !== false; opts.debug = ov.debug === true; + opts.music = ov.music !== false; } } catch (e) {} function saveOpts() { try { localStorage.setItem('breakout.options', JSON.stringify(opts)); } catch (e) {} } @@ -412,14 +415,27 @@ } /* ---------------- sound ---------------- */ + function audioBus() { + if (!ac) ac = new (window.AudioContext || window.webkitAudioContext)(); + if (!sfxGain) { sfxGain = ac.createGain(); sfxGain.gain.value = 0.9; sfxGain.connect(ac.destination); } + if (!musGain) { musGain = ac.createGain(); musGain.gain.value = 0; musGain.connect(ac.destination); } + if (!noiseBuf) { + noiseBuf = ac.createBuffer(1, Math.max(1, Math.floor(ac.sampleRate * 0.4)), ac.sampleRate); + var d = noiseBuf.getChannelData(0); + for (var i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1; + } + if (ac.state === 'suspended') ac.resume(); + return ac; + } + function beep(freq, dur, type, gain) { if (!sound) return; try { - if (!ac) ac = new (window.AudioContext || window.webkitAudioContext)(); + audioBus(); if (ac.state === 'suspended') ac.resume(); var o = ac.createOscillator(), g = ac.createGain(); o.type = type || 'square'; o.frequency.value = freq; - o.connect(g); g.connect(ac.destination); + o.connect(g); g.connect(sfxGain || ac.destination); var t = ac.currentTime, v = gain || 0.05, d = dur || 0.07; g.gain.setValueAtTime(v, t); g.gain.exponentialRampToValueAtTime(0.0001, t + d); @@ -427,6 +443,107 @@ } catch (e) {} } + /* ---------------- musik: eigene Komposition im Chip-Tune-Stil ---------------- */ + var BPM_LEVEL = 148, BPM_CALM = 96, MUS_STEPS = 128; + var ARP_L = [0, 7, 12, 7], BASS_L = [38, 41, 36, 38]; /* Dm - F - C - Dm */ + var MEL_A = [[0,62,2],[2,65,2],[4,69,2],[6,74,2],[8,69,4],[12,67,4], + [16,65,2],[18,69,2],[20,72,2],[22,69,2],[24,65,8], + [32,60,2],[34,67,2],[36,72,2],[38,67,2],[40,60,4],[44,62,4], + [48,62,2],[50,65,2],[52,69,2],[54,74,2],[56,77,4],[60,74,4]]; + var MEL_B = [[0,74,2],[2,72,2],[4,69,2],[6,65,2],[8,62,8], + [16,57,2],[18,65,2],[20,69,2],[22,74,2],[24,72,8], + [32,65,4],[36,69,4],[40,74,8], + [48,62,2],[50,69,2],[52,74,2],[54,69,2],[56,62,8]]; + var ARP_C = [0, 7, 12], BASS_C = [45, 41, 36, 43]; /* Am - F - C - G */ + var MEL_CALM = [[0,69,8],[8,72,8],[16,76,8],[24,72,8],[32,65,8],[40,60,8],[48,67,8],[56,69,8]]; + var musTrack = 'none', musStep = 0, musAt = 0; + var sfxGain = null, musGain = null, noiseBuf = null; + + function midiHz(m) { return 440 * Math.pow(2, (m - 69) / 12); } + function tone(t, midi, type, dur, gain, detune, bus) { + var out = bus || musGain; + var o = ac.createOscillator(), g = ac.createGain(); + o.type = type; o.frequency.value = midiHz(midi); + g.gain.setValueAtTime(0.0001, t); + g.gain.linearRampToValueAtTime(gain, t + 0.008); + g.gain.exponentialRampToValueAtTime(0.0001, t + dur); + o.connect(g); g.connect(out); + o.start(t); o.stop(t + dur + 0.02); + if (detune) { /* zweite Stimme für Druck */ + var o2 = ac.createOscillator(), g2 = ac.createGain(); + o2.type = type; o2.frequency.value = midiHz(midi); o2.detune.value = -detune; + g2.gain.setValueAtTime(0.0001, t); + g2.gain.linearRampToValueAtTime(gain * 0.65, t + 0.012); + g2.gain.exponentialRampToValueAtTime(0.0001, t + dur); + o2.connect(g2); g2.connect(out); o2.start(t); o2.stop(t + dur + 0.02); + } + } + function hat(t, gain) { + var s = ac.createBufferSource(); s.buffer = noiseBuf; + var f = ac.createBiquadFilter(); f.type = 'highpass'; f.frequency.value = 7000; + var g = ac.createGain(); + g.gain.setValueAtTime(gain, t); g.gain.exponentialRampToValueAtTime(0.0001, t + 0.05); + s.connect(f); f.connect(g); g.connect(musGain); + s.start(t); s.stop(t + 0.06); + } + function playStep(tr, s, t, sd) { + var bar = Math.floor(s / 16) % 4; + if (tr === 'level') { + tone(t, BASS_L[bar] + ARP_L[s % 4], 'square', sd * 0.9, 0.10); + if (s % 2 === 0) hat(t, s % 8 === 0 ? 0.09 : 0.045); + var mel = s < 64 ? MEL_A : MEL_B, off = s % 64; + for (var i = 0; i < mel.length; i++) if (mel[i][0] === off) tone(t, mel[i][1], 'square', mel[i][2] * sd * 0.85, 0.062, 8); + } else { + if (s % 2 === 0) tone(t, BASS_C[bar] + ARP_C[(s / 2) % 3], 'triangle', sd * 1.7, 0.085); + var mc = MEL_CALM, ofc = s % 64; + for (var j = 0; j < mc.length; j++) if (mc[j][0] === ofc) tone(t, mc[j][1], 'triangle', mc[j][2] * sd * 1.5, 0.05, 6); + if (s % 8 === 0) hat(t, 0.022); + } + } + function trackForState() { + if (!sound || !opts.music) return 'none'; + if (state === 'playing') return 'level'; + if (state === 'over') return 'none'; + return 'calm'; + } + function musGainTo(v, inSec) { + if (!musGain || !ac) return; + var t = ac.currentTime; + musGain.gain.cancelScheduledValues(t); + musGain.gain.setValueAtTime(musGain.gain.value, t); + musGain.gain.linearRampToValueAtTime(v, t + inSec); + } + function setTrack(tr) { + if (tr === musTrack) return; + musTrack = tr; musStep = 0; + musGainTo(tr === 'level' ? 0.16 : (tr === 'calm' ? 0.115 : 0), 0.3); + if (ac) musAt = ac.currentTime + 0.06; + } + function musicTick() { + if (!ac || !musGain) return; + var want = trackForState(); + if (want !== musTrack) setTrack(want); + if (musTrack === 'none') return; + var sd = 60 / (musTrack === 'level' ? BPM_LEVEL : BPM_CALM) / 4; + if (musAt < ac.currentTime) musAt = ac.currentTime + 0.02; + for (var guard = 0; musAt < ac.currentTime + 0.35 && guard < 64; guard++) { + playStep(musTrack, musStep, musAt, sd); + musStep = (musStep + 1) % MUS_STEPS; + musAt += sd; + } + } + function playCadence() { + if (!ac || !sound || !opts.music) return; + var cg = ac.createGain(); cg.gain.value = 0.15; cg.connect(ac.destination); + var t = ac.currentTime + 0.06, sd = 0.25; + [74, 72, 69, 65].forEach(function (n, i) { tone(t + i * sd, n, 'square', sd * 1.3, 0.075, 8, cg); }); + tone(t + 4 * sd, 62, 'square', sd * 3, 0.08, 8, cg); + tone(t, 38, 'triangle', sd * 5, 0.12, 0, cg); + tone(t + 4 * sd, 31, 'square', sd * 6, 0.09, 8, cg); + cg.gain.setValueAtTime(0.15, t + 2.2); + cg.gain.linearRampToValueAtTime(0.0001, t + 3.2); + } + /* ---------------- helpers ---------------- */ var rootEl = document.documentElement; var headEl = document.getElementById('head'); @@ -1104,6 +1221,7 @@ showMsg('Game Over', 'Erreicht: ' + score.toLocaleString('de-DE') + ' Punkte' + (ccUsed ? ' · ' + ccUsed + ' Continue genutzt' : '') + '
Top 5: ' + top5Html(), statsHtml() + '
Klick für neues Spiel
'); hudFx(true); + playCadence(); } /* ---------------- draw ---------------- */ @@ -1497,6 +1615,7 @@ } }); wrap.addEventListener('pointerdown', function (e) { + try { audioBus(); } catch (err) {} if (e.pointerType !== 'mouse' && wrap.setPointerCapture) { try { wrap.setPointerCapture(e.pointerId); } catch (err) {} } if (e.pointerType === 'mouse' && !pointerLocked) canvasRequestLock(); if (state === 'continue') { doContinue(); return; } @@ -1506,6 +1625,12 @@ startOrRestart(); }); window.addEventListener('keydown', function (e) { + try { audioBus(); } catch (err) {} + if (e.key === 'm' || e.key === 'M') { + opts.music = !opts.music; saveOpts(); renderOpts(); + if (!opts.music) { musGainTo(0, 0.2); musTrack = 'none'; } + return; + } if (e.key === 'Escape') { if (optionsOpen) closeOptions(); if (state === 'continue') gameOver(); canvasExitLock(); return; } if (optionsOpen) return; if (opts.debug && (e.key === '[' || e.key === ']')) { debugStep(e.key === ']' ? 1 : -1); e.preventDefault(); return; } @@ -1563,7 +1688,8 @@ } function debugStep(d) { if (opts.debug) setLevel(level + d); } function renderOpts() { - paintOpt(optRound, opts.round); paintOpt(optAuto, opts.autoFire); paintOpt(optPU, opts.pu); paintOpt(optDebug, opts.debug); + paintOpt(optRound, opts.round); paintOpt(optAuto, opts.autoFire); paintOpt(optPU, opts.pu); + paintOpt(optDebug, opts.debug); paintOpt(optMusic, opts.music); dbgSync(); if (laserHint) laserHint.textContent = opts.autoFire ? 'Laser feuert automatisch' : 'Laser: Salve per Klick/Leertaste'; } @@ -1587,6 +1713,10 @@ if (!opts.pu) { powerups.length = 0; for (var k in fx) fx[k] = 0; applyPaddle(); hudFx(true); } }); optDebug.addEventListener('click', function () { opts.debug = !opts.debug; saveOpts(); renderOpts(); }); + optMusic.addEventListener('click', function () { + opts.music = !opts.music; saveOpts(); renderOpts(); + if (!opts.music) { musGainTo(0, 0.2); musTrack = 'none'; } + }); dbgUp.addEventListener('click', function () { debugStep(1); if (dbgLvl.blur) dbgLvl.blur(); }); dbgDown.addEventListener('click', function () { debugStep(-1); if (dbgLvl.blur) dbgLvl.blur(); }); dbgLvl.addEventListener('change', function () { setLevel(dbgLvl.value); }); @@ -1656,6 +1786,7 @@ } else { shake = 0; shakeX = 0; shakeY = 0; } hudFx(false); + musicTick(); draw(); /* Paddle-Endposition dieses Frames merken: fürs Abfrage-Scanning des nächsten Frames */ for (var pj = 0; pj < pads.length; pj++) { pads[pj].prevX = pads[pj].x; pads[pj].prevY = pads[pj].y; } diff --git a/test/pu-test.js b/test/pu-test.js new file mode 100644 index 0000000..fba1c62 --- /dev/null +++ b/test/pu-test.js @@ -0,0 +1,528 @@ +/* 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('')[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);