mirror of
https://github.com/shadoll/sLogos.git
synced 2026-08-28 11:33:29 +00:00
Add common logic for achievements, global stats, session management, settings, and sound in quizzes
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// quizSound.js
|
||||
// Common sound logic for all quizzes
|
||||
|
||||
export function playCorrectSound(soundEnabled) {
|
||||
if (!soundEnabled) return;
|
||||
try {
|
||||
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||
const oscillator = audioContext.createOscillator();
|
||||
const gainNode = audioContext.createGain();
|
||||
oscillator.connect(gainNode);
|
||||
gainNode.connect(audioContext.destination);
|
||||
oscillator.frequency.setValueAtTime(523.25, audioContext.currentTime);
|
||||
oscillator.frequency.setValueAtTime(659.25, audioContext.currentTime + 0.1);
|
||||
oscillator.frequency.setValueAtTime(783.99, audioContext.currentTime + 0.2);
|
||||
gainNode.gain.setValueAtTime(0.3, audioContext.currentTime);
|
||||
gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 0.4);
|
||||
oscillator.start(audioContext.currentTime);
|
||||
oscillator.stop(audioContext.currentTime + 0.4);
|
||||
} catch (e) {
|
||||
console.log("Audio not supported:", e);
|
||||
}
|
||||
}
|
||||
|
||||
export function playWrongSound(soundEnabled) {
|
||||
if (!soundEnabled) return;
|
||||
try {
|
||||
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||
const oscillator = audioContext.createOscillator();
|
||||
const gainNode = audioContext.createGain();
|
||||
oscillator.connect(gainNode);
|
||||
gainNode.connect(audioContext.destination);
|
||||
oscillator.frequency.setValueAtTime(400, audioContext.currentTime);
|
||||
oscillator.frequency.setValueAtTime(300, audioContext.currentTime + 0.15);
|
||||
gainNode.gain.setValueAtTime(0.3, audioContext.currentTime);
|
||||
gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 0.3);
|
||||
oscillator.start(audioContext.currentTime);
|
||||
oscillator.stop(audioContext.currentTime + 0.3);
|
||||
} catch (e) {
|
||||
console.log("Audio not supported:", e);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user