Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50d9fe349e | ||
|
|
7f3db5c538 | ||
|
|
cffb5868b6 | ||
|
|
f70679bd9d | ||
|
|
77fe6dd74c | ||
|
|
d972122e27 | ||
|
|
5f5507b538 | ||
|
|
8c965dcfd9 | ||
|
|
1e43dc4dce | ||
|
|
0adbdfc106 |
@@ -189,24 +189,27 @@ const SFX = (() => {
|
|||||||
|
|
||||||
function getCtx() {
|
function getCtx() {
|
||||||
if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();
|
if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
if (ctx.state === 'suspended') ctx.resume();
|
if (ctx.state === 'suspended') ctx.resume().catch(() => {});
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
function unlock() {
|
document.addEventListener('touchstart', () => {
|
||||||
if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();
|
if (!ctx) {
|
||||||
if (ctx.state === 'suspended') ctx.resume().then(() => {});
|
ctx = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
|
} else if (ctx.state === 'suspended') {
|
||||||
|
ctx.resume().catch(() => {});
|
||||||
}
|
}
|
||||||
document.addEventListener('touchstart', unlock, { once: true, passive: true });
|
}, { passive: true });
|
||||||
document.addEventListener('pointerdown', unlock, { once: true, passive: true });
|
|
||||||
document.addEventListener('visibilitychange', () => {
|
document.addEventListener('visibilitychange', () => {
|
||||||
if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') {
|
if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') {
|
||||||
ctx.resume();
|
ctx.resume().catch(() => {});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function tone(freq, type, vol, attack, sustain, release, when) {
|
function tone(freq, type, vol, attack, sustain, release, when) {
|
||||||
const c = getCtx();
|
const c = getCtx();
|
||||||
|
if (c.state !== 'running') return;
|
||||||
const t = when ?? c.currentTime;
|
const t = when ?? c.currentTime;
|
||||||
const osc = c.createOscillator();
|
const osc = c.createOscillator();
|
||||||
const gain = c.createGain();
|
const gain = c.createGain();
|
||||||
@@ -224,11 +227,9 @@ const SFX = (() => {
|
|||||||
|
|
||||||
function seq(notes, type='square', vol=0.18) {
|
function seq(notes, type='square', vol=0.18) {
|
||||||
const c = getCtx();
|
const c = getCtx();
|
||||||
|
if (c.state !== 'running') return;
|
||||||
let t = c.currentTime + 0.02;
|
let t = c.currentTime + 0.02;
|
||||||
notes.forEach(n => {
|
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; });
|
||||||
if (n.f) tone(n.f, type, vol, 0.01, n.d * 0.6, n.d * 0.4, t);
|
|
||||||
t += n.d;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -237,7 +238,7 @@ const SFX = (() => {
|
|||||||
step() { tone(180, 'square', 0.04, 0.005, 0.02, 0.03); },
|
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); },
|
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); },
|
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); },
|
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); },
|
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); },
|
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() {
|
showTitle() {
|
||||||
this.show('title');
|
this.show('title');
|
||||||
SFX.boot();
|
|
||||||
this._showController(true);
|
this._showController(true);
|
||||||
const go = () => {
|
const go = () => {
|
||||||
document.getElementById('screen-title').removeEventListener('click', go);
|
document.getElementById('screen-title').removeEventListener('click', go);
|
||||||
Music.unblock();
|
Music.play();
|
||||||
|
SFX.boot();
|
||||||
this.showContinueOrName();
|
this.showContinueOrName();
|
||||||
};
|
};
|
||||||
document.getElementById('screen-title').addEventListener('click', go);
|
document.getElementById('screen-title').addEventListener('click', go);
|
||||||
|
|||||||
Reference in new issue
Block a user