diff --git a/public/fear/snd/knock1.mp3 b/public/fear/snd/knock1.mp3 new file mode 100644 index 0000000..9852dfc Binary files /dev/null and b/public/fear/snd/knock1.mp3 differ diff --git a/public/fear/snd/knock2.mp3 b/public/fear/snd/knock2.mp3 new file mode 100644 index 0000000..ed632d9 Binary files /dev/null and b/public/fear/snd/knock2.mp3 differ diff --git a/src/app/fear/scene-components/hallway.tsx b/src/app/fear/scene-components/hallway.tsx index c386c11..984b72e 100644 --- a/src/app/fear/scene-components/hallway.tsx +++ b/src/app/fear/scene-components/hallway.tsx @@ -1,6 +1,6 @@ import { useEffect, useRef, useState } from "react"; import { FEAR_SETTINGS, fearState } from "../state"; -import { useTexture } from "@react-three/drei"; +import { useTexture, PositionalAudio } from "@react-three/drei"; import * as THREE from "three"; import { useFrame } from "@react-three/fiber"; @@ -10,6 +10,27 @@ interface DoorProps { rotation: [number, number, number]; } function Door({ position, rotation }: DoorProps) { + const [soundUrl, setSoundUrl] = useState(null); + const currentSound = useRef(null); + + useEffect(() => { + const interval = setInterval(() => { + if (Math.random() < 0.02) { + const chosenSound = Math.random() < 0.5 ? "fear/snd/knock1.mp3" : "fear/snd/knock2.mp3"; + + setSoundUrl(chosenSound); + currentSound.current = chosenSound; + } + }, 5000); + + return () => clearInterval(interval); + }, []); + + const handleAudioEnded = () => { + setSoundUrl(null); + currentSound.current = null; + }; + return ( @@ -26,6 +47,16 @@ function Door({ position, rotation }: DoorProps) { + + {soundUrl && ( + + )} ); }