Add support for directional sound

This commit is contained in:
2021-04-06 15:46:49 +02:00
parent ebcac39069
commit 7801920fd2
4 changed files with 32 additions and 3 deletions
+19
View File
@@ -1,6 +1,7 @@
module Dodge.SoundLogic where
import Dodge.Data
import Sound.Preload (SoundStatus (..))
import Geometry.Vector
import Control.Lens
import qualified Data.Map as M
@@ -29,6 +30,24 @@ soundOnceOrigin sType so = over sounds (M.insertWith (flip const) so sound)
, _soundPos = Nothing
}
soundFromPos :: SoundOrigin -> Point2 -> Int -> Int -> Int -> World -> World
soundFromPos so pos sType time fadeTime w = over sounds (M.insertWith f so sound) w
where
sound = Sound
{ _soundChunkID = sType
, _soundTime = Just time
, _soundStatus = ToStart
, _soundFadeTime = fadeTime
, _soundChannel = Nothing
, _soundPos = Just (a,0)
}
f _ s = s {_soundTime = Just time, _soundFadeTime = fadeTime}
a = round
. radToDeg
. normalizeAngle
. (+ pi)
$ argV (vNormal (pos -.- _cameraViewFrom w)) - _cameraRot w
soundFrom :: SoundOrigin -> Int -> Int -> Int -> World -> World
soundFrom so sType time fadeTime w = over sounds (M.insertWith f so sound) w
where