Compare commits
10
Commits
5b18f9bda1
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50d9fe349e | ||
|
|
7f3db5c538 | ||
|
|
cffb5868b6 | ||
|
|
f70679bd9d | ||
|
|
77fe6dd74c | ||
|
|
d972122e27 | ||
|
|
5f5507b538 | ||
|
|
8c965dcfd9 | ||
|
|
1e43dc4dce | ||
|
|
0adbdfc106 |
@@ -189,30 +189,33 @@ const SFX = (() => {
|
||||
|
||||
function getCtx() {
|
||||
if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
if (ctx.state === 'suspended') ctx.resume();
|
||||
if (ctx.state === 'suspended') ctx.resume().catch(() => {});
|
||||
return ctx;
|
||||
}
|
||||
|
||||
function unlock() {
|
||||
if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
if (ctx.state === 'suspended') ctx.resume().then(() => {});
|
||||
}
|
||||
document.addEventListener('touchstart', unlock, { once: true, passive: true });
|
||||
document.addEventListener('pointerdown', unlock, { once: true, passive: true });
|
||||
document.addEventListener('touchstart', () => {
|
||||
if (!ctx) {
|
||||
ctx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
} else if (ctx.state === 'suspended') {
|
||||
ctx.resume().catch(() => {});
|
||||
}
|
||||
}, { passive: true });
|
||||
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') {
|
||||
ctx.resume();
|
||||
ctx.resume().catch(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
function tone(freq, type, vol, attack, sustain, release, when) {
|
||||
const c = getCtx();
|
||||
const t = when ?? c.currentTime;
|
||||
const osc = c.createOscillator();
|
||||
const gain= c.createGain();
|
||||
const c = getCtx();
|
||||
if (c.state !== 'running') return;
|
||||
const t = when ?? c.currentTime;
|
||||
const osc = c.createOscillator();
|
||||
const gain = c.createGain();
|
||||
osc.connect(gain);
|
||||
gain.connect(c.destination);
|
||||
osc.type = type;
|
||||
osc.type = type;
|
||||
osc.frequency.setValueAtTime(freq, t);
|
||||
gain.gain.setValueAtTime(0, t);
|
||||
gain.gain.linearRampToValueAtTime(vol, t + attack);
|
||||
@@ -224,11 +227,9 @@ const SFX = (() => {
|
||||
|
||||
function seq(notes, type='square', vol=0.18) {
|
||||
const c = getCtx();
|
||||
if (c.state !== 'running') return;
|
||||
let t = c.currentTime + 0.02;
|
||||
notes.forEach(n => {
|
||||
if (n.f) tone(n.f, type, vol, 0.01, n.d * 0.6, n.d * 0.4, t);
|
||||
t += n.d;
|
||||
});
|
||||
notes.forEach(n => { if (n.f) tone(n.f, type, vol, 0.01, n.d * 0.6, n.d * 0.4, t); t += n.d; });
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -237,7 +238,7 @@ const SFX = (() => {
|
||||
step() { tone(180, 'square', 0.04, 0.005, 0.02, 0.03); },
|
||||
encounter() { seq([{f:523,d:.1},{f:659,d:.18}], 'square', 0.22); },
|
||||
type() { tone(880 + Math.random()*200, 'square', 0.03, 0.005, 0.01, 0.02); },
|
||||
select() { const c = getCtx(); tone(440, 'square', 0.12, 0.005, 0.03, 0.04, c.currentTime + 0.05); },
|
||||
select() { tone(440, 'square', 0.12, 0.005, 0.03, 0.04); },
|
||||
backspace() { seq([{f:350,d:.05},{f:250,d:.08}], 'triangle', 0.12); },
|
||||
correct() { seq([{f:523,d:.08},{f:659,d:.08},{f:784,d:.08},{f:1047,d:.2}], 'square', 0.18); },
|
||||
streak() { seq([{f:523,d:.06},{f:659,d:.06},{f:784,d:.06},{f:1047,d:.06},{f:1319,d:.2}], 'square', 0.18); },
|
||||
@@ -1150,11 +1151,11 @@ class Game {
|
||||
|
||||
showTitle() {
|
||||
this.show('title');
|
||||
SFX.boot();
|
||||
this._showController(true);
|
||||
const go = () => {
|
||||
document.getElementById('screen-title').removeEventListener('click', go);
|
||||
Music.unblock();
|
||||
Music.play();
|
||||
SFX.boot();
|
||||
this.showContinueOrName();
|
||||
};
|
||||
document.getElementById('screen-title').addEventListener('click', go);
|
||||
|
||||
Reference in new issue
Block a user