APmanageur Wi-Fi V1.0
This commit is contained in:
1 parent
33cf355785
commit
f78e380236
3 files changed
+159
-19
No files matched your search
+134
-6
@@ -279,6 +279,7 @@
|
||||
<div id="level" class="value">1</div>
|
||||
</div>
|
||||
<button id="pauseBtn" class="btn secondary" onclick="togglePause()">PAUSE (P)</button>
|
||||
<button id="musicBtn" class="btn secondary" onclick="toggleMusic()">🎵 Musique : ON</button>
|
||||
<button class="btn" onclick="startGame()">NOUVEAU</button>
|
||||
|
||||
<div class="controls-help">
|
||||
@@ -309,14 +310,12 @@
|
||||
} else {
|
||||
delete document.documentElement.dataset.macosMode;
|
||||
}
|
||||
draw();
|
||||
drawNext();
|
||||
if (typeof ctx !== 'undefined' && ctx && typeof board !== 'undefined' && board) {
|
||||
draw();
|
||||
drawNext();
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize theme from URL query param
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
setTheme(urlParams.get('theme') || 'dark', urlParams.get('macosMode'));
|
||||
|
||||
window.addEventListener('message', e => {
|
||||
if (e.data && e.data.type === 'themeChange') {
|
||||
setTheme(e.data.theme, e.data.macosMode);
|
||||
@@ -373,6 +372,127 @@
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// Tetris Theme Music (Korobeiniki 8-bit Chiptune)
|
||||
let isMusicEnabled = true;
|
||||
let musicTimeout = null;
|
||||
let musicStep = 0;
|
||||
const T_TEMPO = 146;
|
||||
const T_BEAT = 60 / T_TEMPO; // ~0.41s per quarter note
|
||||
|
||||
const KOROBEINIKI = [
|
||||
// Part A
|
||||
{ f: 659.25, d: 4 }, // E5
|
||||
{ f: 493.88, d: 2 }, // B4
|
||||
{ f: 523.25, d: 2 }, // C5
|
||||
{ f: 587.33, d: 4 }, // D5
|
||||
{ f: 523.25, d: 2 }, // C5
|
||||
{ f: 493.88, d: 2 }, // B4
|
||||
{ f: 440.00, d: 4 }, // A4
|
||||
{ f: 440.00, d: 2 }, // A4
|
||||
{ f: 523.25, d: 2 }, // C5
|
||||
{ f: 659.25, d: 4 }, // E5
|
||||
{ f: 587.33, d: 2 }, // D5
|
||||
{ f: 523.25, d: 2 }, // C5
|
||||
{ f: 493.88, d: 6 }, // B4
|
||||
{ f: 523.25, d: 2 }, // C5
|
||||
{ f: 587.33, d: 4 }, // D5
|
||||
{ f: 659.25, d: 4 }, // E5
|
||||
{ f: 523.25, d: 4 }, // C5
|
||||
{ f: 440.00, d: 4 }, // A4
|
||||
{ f: 440.00, d: 4 }, // A4
|
||||
{ f: 0, d: 4 }, // Pause
|
||||
|
||||
// Part B
|
||||
{ f: 587.33, d: 6 }, // D5
|
||||
{ f: 698.46, d: 2 }, // F5
|
||||
{ f: 880.00, d: 4 }, // A5
|
||||
{ f: 783.99, d: 2 }, // G5
|
||||
{ f: 698.46, d: 2 }, // F5
|
||||
{ f: 659.25, d: 6 }, // E5
|
||||
{ f: 523.25, d: 2 }, // C5
|
||||
{ f: 659.25, d: 4 }, // E5
|
||||
{ f: 587.33, d: 2 }, // D5
|
||||
{ f: 523.25, d: 2 }, // C5
|
||||
{ f: 493.88, d: 4 }, // B4
|
||||
{ f: 493.88, d: 2 }, // B4
|
||||
{ f: 523.25, d: 2 }, // C5
|
||||
{ f: 587.33, d: 4 }, // D5
|
||||
{ f: 659.25, d: 4 }, // E5
|
||||
{ f: 523.25, d: 4 }, // C5
|
||||
{ f: 440.00, d: 4 }, // A4
|
||||
{ f: 440.00, d: 4 }, // A4
|
||||
{ f: 0, d: 4 } // Pause
|
||||
];
|
||||
|
||||
function playMusicNote(freq, durSec) {
|
||||
if (!isMusicEnabled || isPaused || isGameOver || freq <= 0) return;
|
||||
try {
|
||||
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
if (audioCtx.state === 'suspended') audioCtx.resume();
|
||||
const osc = audioCtx.createOscillator();
|
||||
const gain = audioCtx.createGain();
|
||||
osc.type = 'square';
|
||||
osc.frequency.setValueAtTime(freq, audioCtx.currentTime);
|
||||
const vol = 0.035;
|
||||
gain.gain.setValueAtTime(vol, audioCtx.currentTime);
|
||||
gain.gain.setValueAtTime(vol * 0.85, audioCtx.currentTime + durSec * 0.7);
|
||||
gain.gain.linearRampToValueAtTime(0.0001, audioCtx.currentTime + durSec * 0.95);
|
||||
osc.connect(gain);
|
||||
gain.connect(audioCtx.destination);
|
||||
osc.start();
|
||||
osc.stop(audioCtx.currentTime + durSec * 0.95);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function scheduleMusic() {
|
||||
if (musicTimeout) clearTimeout(musicTimeout);
|
||||
if (!isMusicEnabled || isPaused || isGameOver) return;
|
||||
const item = KOROBEINIKI[musicStep];
|
||||
const durSec = item.d * (T_BEAT / 4);
|
||||
if (item.f > 0) {
|
||||
playMusicNote(item.f, durSec);
|
||||
}
|
||||
musicStep = (musicStep + 1) % KOROBEINIKI.length;
|
||||
musicTimeout = setTimeout(scheduleMusic, durSec * 1000);
|
||||
}
|
||||
|
||||
function startMusic() {
|
||||
if (musicTimeout) clearTimeout(musicTimeout);
|
||||
musicStep = 0;
|
||||
if (isMusicEnabled && !isPaused && !isGameOver) {
|
||||
scheduleMusic();
|
||||
}
|
||||
}
|
||||
|
||||
function stopMusic() {
|
||||
if (musicTimeout) {
|
||||
clearTimeout(musicTimeout);
|
||||
musicTimeout = null;
|
||||
}
|
||||
}
|
||||
|
||||
function toggleMusic() {
|
||||
isMusicEnabled = !isMusicEnabled;
|
||||
const btn = document.getElementById('musicBtn');
|
||||
if (btn) btn.textContent = isMusicEnabled ? '🎵 Musique : ON' : '🔇 Musique : OFF';
|
||||
if (isMusicEnabled) {
|
||||
if (!isPaused && !isGameOver) scheduleMusic();
|
||||
} else {
|
||||
stopMusic();
|
||||
}
|
||||
}
|
||||
|
||||
function resumeAudioOnGesture() {
|
||||
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
if (audioCtx.state === 'suspended') audioCtx.resume();
|
||||
if (isMusicEnabled && !musicTimeout && !isPaused && !isGameOver) {
|
||||
scheduleMusic();
|
||||
}
|
||||
}
|
||||
window.addEventListener('keydown', resumeAudioOnGesture);
|
||||
window.addEventListener('pointerdown', resumeAudioOnGesture);
|
||||
|
||||
|
||||
const canvas = document.getElementById('tetris');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const nextCanvas = document.getElementById('next');
|
||||
@@ -519,6 +639,7 @@
|
||||
|
||||
if (collide(board, player)) {
|
||||
isGameOver = true;
|
||||
stopMusic();
|
||||
playSound('gameover');
|
||||
document.getElementById('gameOverlay').style.display = 'flex';
|
||||
document.getElementById('overlayTitle').textContent = 'GAME OVER';
|
||||
@@ -609,12 +730,14 @@
|
||||
document.getElementById('pauseBtn').textContent = isPaused ? 'REPRENDRE' : 'PAUSE (P)';
|
||||
const ov = document.getElementById('gameOverlay');
|
||||
if (isPaused) {
|
||||
stopMusic();
|
||||
ov.style.display = 'flex';
|
||||
document.getElementById('overlayTitle').textContent = 'PAUSE';
|
||||
document.getElementById('overlayScore').textContent = 'Score: ' + player.score;
|
||||
} else {
|
||||
ov.style.display = 'none';
|
||||
lastTime = performance.now();
|
||||
if (isMusicEnabled) scheduleMusic();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -752,6 +875,7 @@
|
||||
nextPiece = null;
|
||||
playerReset();
|
||||
lastTime = performance.now();
|
||||
startMusic();
|
||||
}
|
||||
|
||||
window.addEventListener('keydown', e => {
|
||||
@@ -771,6 +895,10 @@
|
||||
else if (e.key === ' ') hardDrop();
|
||||
});
|
||||
|
||||
// Initialize theme from URL query param safely after all variables exist
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
setTheme(urlParams.get('theme') || 'dark', urlParams.get('macosMode'));
|
||||
|
||||
startGame();
|
||||
update();
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user