added sound

This commit is contained in:
2025-08-26 11:24:42 +01:00
parent 2db634aee7
commit 2b0bb76d0c

View File

@@ -55,6 +55,23 @@
function sleep(ms){ return new Promise(r => setTimeout(r, ms)); }
function bodyGlitch(){ document.body.classList.add('glitch'); setTimeout(()=> document.body.classList.remove('glitch'), 180); }
// --- Typing click sound (minimal) ---
const AudioCtx = window.AudioContext || window.webkitAudioContext;
let ctx = null;
function ensureAudio(){ if (!ctx) ctx = new AudioCtx(); if (ctx.state === 'suspended') ctx.resume(); }
function typeClick(){
if (!ctx) return; // only after first click enables audio
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.type = 'square';
osc.frequency.value = 800 + Math.random()*200;
gain.gain.setValueAtTime(0.05, ctx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.0001, ctx.currentTime + 0.04);
osc.connect(gain).connect(ctx.destination);
osc.start();
osc.stop(ctx.currentTime + 0.05);
}
const bootLines = [
'Phoenix BIOS v4.0 Release 6.0',
'Copyright (C) 1985-2025 Phoenix Technologies Ltd.',
@@ -93,6 +110,7 @@
for (let i=0; i<line.length; i++){
if (aborted) return;
screen.append(document.createTextNode(line[i]));
typeClick();
screen.scrollTop = screen.scrollHeight;
await sleep(speed>1 ? 3 : 12 + Math.random()*30);
}
@@ -100,7 +118,8 @@
if (line.startsWith('[WARN]')) bodyGlitch();
}
document.addEventListener('click', () => { speed = 3; });
// Click once to enable audio & optionally speed up
document.addEventListener('click', () => { ensureAudio(); speed = 3; }, { once: false });
(async function run(){
await sleep(200);
@@ -112,11 +131,12 @@
}
await sleep(300);
const final = 'Incoming message... Andy is a cock.';
const final = 'Incoming message... Andy is a cock!';
const span = document.createElement('span');
screen.append(span);
for (let i=0; i<final.length; i++){
span.textContent += final[i];
typeClick();
screen.scrollTop = screen.scrollHeight;
await sleep(110 / speed);
}