Optionsmenü: rundes Paddle, Auto-Feuer und Power-ups umschaltbar (Persistenz via localStorage)
This commit is contained in:
1 parent
c4e637369a
commit
d88f5b54f1
2 files changed
+138
-37
No files matched your search
@@ -17,6 +17,15 @@ Komplettes Breakout in einer einzigen HTML-Datei — ohne Build, ohne Abhängigk
|
||||
| ← → | Paddle per Tastatur |
|
||||
| `P` | Pause |
|
||||
| `R` | Neustart |
|
||||
| `Optionen`-Button | Optionsmenü öffnen (pausiert das Spiel) |
|
||||
|
||||
## Optionen
|
||||
|
||||
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
|
||||
|
||||
## Power-ups
|
||||
|
||||
|
||||
+129
-37
@@ -97,6 +97,18 @@
|
||||
background: rgba(7,11,22,.62); pointer-events: none; transition: opacity .25s ease;
|
||||
}
|
||||
#msg.hidden { opacity: 0; }
|
||||
#opts {
|
||||
position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column;
|
||||
align-items: center; justify-content: center; gap: 8px; cursor: default;
|
||||
background: rgba(7,11,22,.9);
|
||||
}
|
||||
#opts.hidden { display: none; }
|
||||
#opts .ttl { font-size: calc(20px * var(--s)); font-weight: 500; color: #fff; margin-bottom: 4px; }
|
||||
#opts button.opt {
|
||||
width: min(340px, 84%); display: flex; justify-content: space-between; align-items: center;
|
||||
}
|
||||
#opts button.opt b { color: var(--green); }
|
||||
#opts button.opt.off b { color: var(--muted); }
|
||||
#msg .big { font-size: calc(27px * var(--s)); font-weight: 500; color: #fff; letter-spacing: .02em; }
|
||||
#msg .small { font-size: calc(12px * var(--s)); color: #a9b6cf; max-width: 72%; line-height: 1.5; }
|
||||
#msg .accent { color: var(--green); }
|
||||
@@ -161,11 +173,19 @@
|
||||
<div class="big">Breakout</div>
|
||||
<div class="small">Klick ins Spielfeld zum Starten. Zerstörte Steine lassen gelegentlich Power-ups fallen — <span class="accent">goldene, grüne und helle einsammeln, rote meiden.</span></div>
|
||||
</div>
|
||||
<div id="opts" class="hidden">
|
||||
<div class="ttl">Optionen</div>
|
||||
<button class="opt" id="optRound"><span>Rundes Paddle</span><b>AN</b></button>
|
||||
<button class="opt" id="optAuto"><span>Auto-Feuer (Laser)</span><b>AN</b></button>
|
||||
<button class="opt" id="optPU"><span>Power-ups</span><b>AN</b></button>
|
||||
<button id="optClose">Schließen</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="foot">
|
||||
<span>← → Pfeiltasten gehen auch · Laser feuert automatisch · <span id="dims"></span></span>
|
||||
<span>← → Pfeiltasten gehen auch · <span id="laserhint">Laser feuert automatisch</span> · <span id="dims"></span></span>
|
||||
<div id="actions">
|
||||
<button id="options">Optionen</button>
|
||||
<button id="sound">Ton an</button>
|
||||
<button id="restart">Neustart</button>
|
||||
</div>
|
||||
@@ -197,6 +217,14 @@
|
||||
var elHearts = document.getElementById('hearts');
|
||||
var btnSound = document.getElementById('sound');
|
||||
var btnRestart = document.getElementById('restart');
|
||||
var btnOptions = document.getElementById('options');
|
||||
var optsPanel = document.getElementById('opts');
|
||||
var optRound = document.getElementById('optRound');
|
||||
var optAuto = document.getElementById('optAuto');
|
||||
var optPU = document.getElementById('optPU');
|
||||
var optClose = document.getElementById('optClose');
|
||||
var laserHint = document.getElementById('laserhint');
|
||||
var optionsOpen = false;
|
||||
|
||||
var PAL = [
|
||||
['#534AB7', '#AFA9EC'], ['#185FA5', '#85B7EB'], ['#0F6E56', '#5DCAA5'],
|
||||
@@ -239,13 +267,24 @@
|
||||
return scores.map(function (v, i) { return (i + 1) + '. ' + v.toLocaleString('de-DE'); }).join(' · ');
|
||||
}
|
||||
|
||||
var opts = { round: true, autoFire: true, pu: true };
|
||||
try {
|
||||
var ov = JSON.parse(localStorage.getItem('breakout.options') || 'null');
|
||||
if (ov && typeof ov === 'object') {
|
||||
opts.round = ov.round !== false;
|
||||
opts.autoFire = ov.autoFire !== false;
|
||||
opts.pu = ov.pu !== false;
|
||||
}
|
||||
} catch (e) {}
|
||||
function saveOpts() { try { localStorage.setItem('breakout.options', JSON.stringify(opts)); } catch (e) {} }
|
||||
|
||||
function legend() {
|
||||
var html = '';
|
||||
PU.forEach(function (p) {
|
||||
html += '<div class="card' + (p.good ? '' : ' bad') + '">'
|
||||
+ '<div class="glyph" style="background:' + (p.good ? p.c2 : p.c) + '">' + p.icon + '</div>'
|
||||
+ '<div><div class="n">' + p.name + (p.good ? '' : ' · Malus') + '</div>'
|
||||
+ '<div class="d">' + p.desc + '</div></div></div>';
|
||||
+ '<div class="d">' + (p.id === 'laser' && !opts.autoFire ? '8 s, Feuer per Klick/Leertaste' : p.desc) + '</div></div></div>';
|
||||
});
|
||||
document.getElementById('pu-legend').innerHTML = html;
|
||||
}
|
||||
@@ -456,6 +495,7 @@
|
||||
|
||||
/* ---------------- power-up logic ---------------- */
|
||||
function dropPowerup(bx, by) {
|
||||
if (!opts.pu) return;
|
||||
if (Math.random() > 0.24) return;
|
||||
var total = 0; PU.forEach(function (p) { total += p.w; });
|
||||
var roll = Math.random() * total, acc = 0, pick = PU[0];
|
||||
@@ -517,6 +557,14 @@
|
||||
return f;
|
||||
}
|
||||
|
||||
function fireVolley() {
|
||||
if (fx.laser <= 0) return false;
|
||||
bullets.push({ x: paddle.x + 7, y: PY - 2 });
|
||||
bullets.push({ x: paddle.x + paddle.w - 7, y: PY - 2 });
|
||||
beep(1100, 0.05, 'square', 0.035);
|
||||
return true;
|
||||
}
|
||||
|
||||
function burst(b, color) {
|
||||
for (var i = 0; i < 16; i++) {
|
||||
var a = Math.random() * Math.PI * 2, s = 40 + Math.random() * 210;
|
||||
@@ -578,17 +626,24 @@
|
||||
beep(200, 0.05, 'sine', 0.05);
|
||||
return true;
|
||||
}
|
||||
/* 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));
|
||||
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;
|
||||
if (opts.round) {
|
||||
/* 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;
|
||||
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;
|
||||
} else {
|
||||
/* Lineares Paddle: klassischer fester Positionswinkel */
|
||||
var ang = off * 1.02;
|
||||
b.vx = Math.sin(ang) * b.speed + paddle.vx * 0.22;
|
||||
b.vy = -Math.cos(ang) * b.speed;
|
||||
}
|
||||
b.y = PY - b.r - 0.6;
|
||||
combo = 0; comboT = 0; hud();
|
||||
beep(140, 0.05, 'sine', 0.05);
|
||||
@@ -636,14 +691,9 @@
|
||||
}
|
||||
if (balls.length === 0) { loseLife(); return; }
|
||||
|
||||
if (fx.laser > 0) {
|
||||
if (fx.laser > 0 && opts.autoFire) {
|
||||
laserCd -= dt;
|
||||
if (laserCd <= 0) {
|
||||
laserCd = 0.34;
|
||||
bullets.push({ x: paddle.x + 7, y: PY - 2 });
|
||||
bullets.push({ x: paddle.x + paddle.w - 7, y: PY - 2 });
|
||||
beep(1100, 0.05, 'square', 0.035);
|
||||
}
|
||||
if (laserCd <= 0) { laserCd = 0.34; fireVolley(); }
|
||||
}
|
||||
for (var j = bullets.length - 1; j >= 0; j--) {
|
||||
var bu = bullets[j]; bu.y -= 520 * dt;
|
||||
@@ -827,20 +877,28 @@
|
||||
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'); }
|
||||
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();
|
||||
if (opts.round) {
|
||||
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.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();
|
||||
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();
|
||||
} else {
|
||||
rr(paddle.x, PY, paddle.w, PH, 7); 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();
|
||||
}
|
||||
|
||||
if (fx.laser > 0) {
|
||||
ctx.save(); ctx.shadowColor = '#EF9F27'; ctx.shadowBlur = 12; ctx.fillStyle = '#FAEEDA';
|
||||
@@ -852,8 +910,9 @@
|
||||
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;
|
||||
var dy = opts.round ? 4 * ARC_V * t * (1 - t) : 0;
|
||||
ctx.beginPath();
|
||||
ctx.arc(paddle.x + 10 + i * (paddle.w - 20) / 4, PY - 4 * ARC_V * t * (1 - t), 2.2, 0, Math.PI * 2);
|
||||
ctx.arc(paddle.x + 10 + i * (paddle.w - 20) / 4, PY - dy, 2.2, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
@@ -988,19 +1047,20 @@
|
||||
if (e.pointerType !== 'mouse' && wrap.setPointerCapture) { try { wrap.setPointerCapture(e.pointerId); } catch (err) {} }
|
||||
if (e.pointerType === 'mouse' && !pointerLocked) canvasRequestLock();
|
||||
if (state === 'levelclear') return;
|
||||
if (state === 'playing') { launchAttached(); return; }
|
||||
if (state === 'playing') { launchAttached(); fireVolley(); return; }
|
||||
if (state === 'paused') { state = 'playing'; hideMsg(); last = performance.now(); return; }
|
||||
startOrRestart();
|
||||
});
|
||||
window.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape') { canvasExitLock(); return; }
|
||||
if (e.key === 'Escape') { if (optionsOpen) closeOptions(); canvasExitLock(); return; }
|
||||
if (optionsOpen) return;
|
||||
if (e.key === 'ArrowLeft') keys.left = true;
|
||||
if (e.key === 'ArrowRight') keys.right = true;
|
||||
if (e.code === 'Space' || e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
if (state === 'levelclear') return;
|
||||
if (state === 'paused') { state = 'playing'; hideMsg(); last = performance.now(); return; }
|
||||
if (state === 'playing') { launchAttached(); return; }
|
||||
if (state === 'playing') { launchAttached(); fireVolley(); return; }
|
||||
startOrRestart();
|
||||
}
|
||||
if (e.key === 'p' || e.key === 'P') {
|
||||
@@ -1015,6 +1075,38 @@
|
||||
});
|
||||
btnRestart.addEventListener('click', function () { newGame(); });
|
||||
btnSound.addEventListener('click', function () { sound = !sound; btnSound.textContent = sound ? 'Ton an' : 'Ton aus'; });
|
||||
|
||||
function paintOpt(btn, on) {
|
||||
var b = btn.querySelector('b');
|
||||
if (b) b.textContent = on ? 'AN' : 'OFF';
|
||||
btn.classList.toggle('off', !on);
|
||||
}
|
||||
function renderOpts() {
|
||||
paintOpt(optRound, opts.round); paintOpt(optAuto, opts.autoFire); paintOpt(optPU, opts.pu);
|
||||
if (laserHint) laserHint.textContent = opts.autoFire ? 'Laser feuert automatisch' : 'Laser: Salve per Klick/Leertaste';
|
||||
}
|
||||
function openOptions() {
|
||||
optionsOpen = true;
|
||||
canvasExitLock();
|
||||
if (state === 'playing') state = 'paused';
|
||||
hideMsg();
|
||||
optsPanel.classList.remove('hidden');
|
||||
}
|
||||
function closeOptions() {
|
||||
optionsOpen = false;
|
||||
optsPanel.classList.add('hidden');
|
||||
if (state === 'paused') showMsg('Pause', 'Klick oder P zum weiterspielen');
|
||||
else if (state === 'ready' && lives > 0) showMsg('Level ' + level, 'Klicken zum Starten');
|
||||
}
|
||||
optRound.addEventListener('click', function () { opts.round = !opts.round; saveOpts(); renderOpts(); });
|
||||
optAuto.addEventListener('click', function () { opts.autoFire = !opts.autoFire; laserCd = 0; saveOpts(); renderOpts(); legend(); });
|
||||
optPU.addEventListener('click', function () {
|
||||
opts.pu = !opts.pu; saveOpts(); renderOpts();
|
||||
if (!opts.pu) { powerups.length = 0; for (var k in fx) fx[k] = 0; applyPaddle(); hudFx(true); }
|
||||
});
|
||||
optClose.addEventListener('click', closeOptions);
|
||||
btnOptions.addEventListener('click', function () { if (optionsOpen) closeOptions(); else openOptions(); });
|
||||
optsPanel.addEventListener('pointerdown', function (e) { e.stopPropagation(); });
|
||||
window.addEventListener('resize', requestLayout);
|
||||
window.addEventListener('orientationchange', requestLayout);
|
||||
if (window.visualViewport) window.visualViewport.addEventListener('resize', requestLayout);
|
||||
@@ -1060,7 +1152,7 @@
|
||||
requestAnimationFrame(frame);
|
||||
}
|
||||
|
||||
legend(); layout(); buildLevel(); resetBall(); hud(); hudFx(true);
|
||||
legend(); renderOpts(); layout(); buildLevel(); resetBall(); hud(); hudFx(true);
|
||||
/* Layout finalisieren nachdem Fonts/Box-Messung stabil sind */
|
||||
if (document.fonts && document.fonts.ready) document.fonts.ready.then(requestLayout);
|
||||
setTimeout(requestLayout, 80);
|
||||
|
||||
Reference in new issue
Block a user