Highscore-Top-5 (localStorage), gebogenes Paddle mit Winkel-Physik, Combo-Sound mit steigender Tonhöhe

This commit is contained in:
michael committed 2026-10-13 12:18:55 +00:00
1 parent e6566c0b86
commit c4e637369a
2 files changed
+51 -18

No files matched your search

+3 -1
View File
@@ -28,6 +28,8 @@ Komplettes Breakout in einer einzigen HTML-Datei — ohne Build, ohne Abhängigk
- 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)
- Combo-Sound: Tonhöhe steigt mit jedem Stein in der Combo-Kette
- Combo-Multiplikator, Leben, Level, Steine mit Hitpoints
- Power-up-HUD mit Countdown-Balken, Bestwert via `localStorage`
- Power-up-HUD mit Countdown-Balken, Highscore-Top-5 via `localStorage` (Beim Game Over einsortiert)
- Automatische Skalung: Spielfeld löst Fensterbreite und -höhe gemeinsam auf, UI skaliert proportional, HiDPI-scharf, Kompakt-Modus bei niedrigen Fenstern
+48 -17
View File
@@ -182,6 +182,8 @@
var W = 680, H = 470;
var SIDE = 24, TOP = 58, GAP = 6, COLS = 12, BH = 22;
var PW = 112, PH = 14, PY = H - 34, PAD = 18, BR = 7;
var ARC = 0.45; /* max. Neigung (rad) der Paddle-Bogenfläche */
var ARC_V = 4; /* sichtbare Wölbung des Paddles in px */
var wrap = document.getElementById('wrap');
var canvas = document.getElementById('cv');
@@ -225,7 +227,17 @@
var combo = 0, comboT = 0, shake = 0, shakeX = 0, shakeY = 0, levelTimer = 0;
var sound = true, ac = null, fxSig = '';
try { best = Number(localStorage.getItem('breakout.best')) || 0; } catch (e) { best = 0; }
var scores = [];
try { scores = JSON.parse(localStorage.getItem('breakout.scores') || '[]'); } catch (e) { scores = []; }
try { var oldBest = Number(localStorage.getItem('breakout.best')) || 0; if (oldBest > 0) scores.push(oldBest); } catch (e) {}
scores = scores.filter(function (v) { return typeof v === 'number' && isFinite(v) && v > 0; });
scores.sort(function (a, b) { return b - a; });
scores = scores.slice(0, 5);
best = scores[0] || 0;
function top5Html() {
if (!scores.length) return 'Noch keine Ergebnisse';
return scores.map(function (v, i) { return (i + 1) + '. ' + v.toLocaleString('de-DE'); }).join(' · ');
}
function legend() {
var html = '';
@@ -518,7 +530,7 @@
b.hp--; b.flash = 1;
if (b.hp <= 0) {
burst(b, b.c2); shake = Math.min(9, shake + 4);
beep(180 + b.max * 130, 0.09, 'square', 0.05);
beep(210 + Math.min(combo, 12) * 42 + b.max * 18, 0.09, 'square', 0.05);
dropPowerup(b.x + b.w / 2, b.y + b.h / 2);
} else beep(240, 0.04, 'sine', 0.04);
var mult = 1 + Math.min(combo, 8) * 0.5;
@@ -566,10 +578,17 @@
beep(200, 0.05, 'sine', 0.05);
return true;
}
var ang = off * 1.02;
/* Gebogenes Paddle: Reflexion an der Normalen des Paddel-Bogens */
var tilt = off * ARC;
var nx = Math.sin(tilt), ny = -Math.cos(tilt);
var dot = b.vx * nx + b.vy * ny;
b.speed = Math.max(baseSpeed(), Math.min(b.speed + 6, baseSpeed() + 190));
b.vx = Math.sin(ang) * b.speed + paddle.vx * 0.22;
b.vy = -Math.cos(ang) * b.speed;
if (dot < 0) { b.vx -= 2 * dot * nx; b.vy -= 2 * dot * ny; }
if (b.vy > 0) b.vy = -b.vy;
if (Math.abs(b.vy) < b.speed * 0.26) b.vy = -b.speed * 0.26;
var m = Math.sqrt(b.vx * b.vx + b.vy * b.vy) || 1;
b.vx *= b.speed / m; b.vy *= b.speed / m;
b.vx += paddle.vx * 0.22;
b.y = PY - b.r - 0.6;
combo = 0; comboT = 0; hud();
beep(140, 0.05, 'sine', 0.05);
@@ -664,8 +683,15 @@
fx.shrink = 0; fx.fast = 0; applyPaddle();
if (lives <= 0) {
state = 'over';
try { localStorage.setItem('breakout.best', String(best)); } catch (e) {}
showMsg('Game Over', 'Erreicht: ' + score.toLocaleString('de-DE') + ' Punkte · Klick für neues Spiel');
if (score > 0) {
scores.push(score);
scores.sort(function (a, b) { return b - a; });
scores = scores.slice(0, 5);
best = scores[0];
}
try { localStorage.setItem('breakout.scores', JSON.stringify(scores)); } catch (e) {}
hud();
showMsg('Game Over', 'Erreicht: ' + score.toLocaleString('de-DE') + ' Punkte<br>Top 5: ' + top5Html() + '<br>Klick für neues Spiel');
hudFx(true);
} else resetBall();
}
@@ -801,11 +827,20 @@
if (fx.shrink > 0) { g.addColorStop(0, '#A32D2D'); g.addColorStop(1, '#F09595'); }
else if (fx.expand > 0) { g.addColorStop(0, '#1D9E75'); g.addColorStop(0.5, '#5DCAA5'); g.addColorStop(1, '#97C459'); }
else { g.addColorStop(0, '#378ADD'); g.addColorStop(0.5, '#AFA9EC'); g.addColorStop(1, '#1D9E75'); }
rr(paddle.x, PY, paddle.w, PH, 7); ctx.fillStyle = g; ctx.fill();
ctx.beginPath();
ctx.moveTo(paddle.x, PY + PH);
ctx.lineTo(paddle.x, PY);
ctx.quadraticCurveTo(paddle.x + paddle.w / 2, PY - 2 * ARC_V, paddle.x + paddle.w, PY);
ctx.lineTo(paddle.x + paddle.w, PY + PH);
ctx.closePath();
ctx.fillStyle = g; ctx.fill();
ctx.restore();
ctx.fillStyle = 'rgba(255,255,255,0.55)';
rr(paddle.x + 6, PY + 3, paddle.w - 12, 2.5, 1.5); ctx.fill();
ctx.strokeStyle = 'rgba(255,255,255,0.5)'; ctx.lineWidth = 2.5;
ctx.beginPath();
ctx.moveTo(paddle.x + 8, PY + 1);
ctx.quadraticCurveTo(paddle.x + paddle.w / 2, PY - 2 * ARC_V + 5, paddle.x + paddle.w - 8, PY + 1);
ctx.stroke();
if (fx.laser > 0) {
ctx.save(); ctx.shadowColor = '#EF9F27'; ctx.shadowBlur = 12; ctx.fillStyle = '#FAEEDA';
@@ -816,8 +851,9 @@
if (fx.sticky > 0) {
ctx.fillStyle = 'rgba(237,147,177,0.85)';
for (var i = 0; i < 5; i++) {
var t = (10 + i * (paddle.w - 20) / 4 - paddle.x) / paddle.w;
ctx.beginPath();
ctx.arc(paddle.x + 10 + i * (paddle.w - 20) / 4, PY, 2.2, 0, Math.PI * 2);
ctx.arc(paddle.x + 10 + i * (paddle.w - 20) / 4, PY - 4 * ARC_V * t * (1 - t), 2.2, 0, Math.PI * 2);
ctx.fill();
}
}
@@ -850,13 +886,8 @@
}
/* ---------------- HUD ---------------- */
var storeCd = 0;
function hud() {
if (score > best) {
best = score;
storeCd -= 1;
if (storeCd <= 0) { storeCd = 8; try { localStorage.setItem('breakout.best', String(best)); } catch (e) {} }
}
if (score > best) best = score;
elScore.textContent = score.toLocaleString('de-DE');
elBest.textContent = best.toLocaleString('de-DE');
elLevel.textContent = level;