Add more positional sound

This commit is contained in:
2021-04-06 20:42:53 +02:00
parent be3c3339ec
commit 9a86d03fae
4 changed files with 20 additions and 13 deletions
+5 -2
View File
@@ -35,8 +35,11 @@ updateLamp :: Int -> CRUpdate
updateLamp i = unrandUpdate handleLS internalUpdate updateLamp i = unrandUpdate handleLS internalUpdate
where where
handleLS cr w handleLS cr w
| _crHP cr < 0 = explosionFlashAt (_crPos cr) $ mkSoundBreakGlass w & lightSources %~ IM.delete i | _crHP cr < 0 = explosionFlashAt cPos
| otherwise = w & lightSources . ix i . lsPos .~ _crPos cr $ mkSoundBreakGlass cPos w & lightSources %~ IM.delete i
| otherwise = w & lightSources . ix i . lsPos .~ cPos
where
cPos = _crPos cr
internalUpdate cr internalUpdate cr
| _crHP cr < 0 = Nothing | _crHP cr < 0 = Nothing
| otherwise = Just $ doDamage cr | otherwise = Just $ doDamage cr
+3 -4
View File
@@ -42,11 +42,10 @@ killBlock bl w = f bl .
where where
f bl@(Block {_blDegrades = (x:xs)}) = degradeBlock bl . hitSound bl f bl@(Block {_blDegrades = (x:xs)}) = degradeBlock bl . hitSound bl
f bl = hitSound' bl f bl = hitSound' bl
hitSound bl | _wlIsSeeThrough bl = mkSoundBreakGlass pos = _wlLine bl !! 0
-- hitSound bl | _wlIsSeeThrough bl = soundMultiFrom sos (soundid+8) 25 0 hitSound bl | _wlIsSeeThrough bl = mkSoundBreakGlass pos
| otherwise = soundMultiFrom sos soundid 25 0 | otherwise = soundMultiFrom sos soundid 25 0
hitSound' bl | _wlIsSeeThrough bl = mkSoundSplinterGlass hitSound' bl | _wlIsSeeThrough bl = mkSoundSplinterGlass pos
-- hitSound' bl | _wlIsSeeThrough bl = soundMultiFrom sos (soundid+4) 25 0
| otherwise = soundMultiFrom sos soundid 25 0 | otherwise = soundMultiFrom sos soundid 25 0
sos = [BlockDegradeSound 0,BlockDegradeSound 1] sos = [BlockDegradeSound 0,BlockDegradeSound 1]
(soundid,_) = randomR (29,32) $ _randGen w (soundid,_) = randomR (29,32) $ _randGen w
+7 -3
View File
@@ -65,6 +65,7 @@ resumeSound :: World -> World
resumeSound w = w resumeSound w = w
{-| Add a sound to the queue for playback. {-| Add a sound to the queue for playback.
Consider replacing with 'soundOncePos'.
-} -}
soundOnce :: Int -> World -> World soundOnce :: Int -> World -> World
soundOnce i = over soundQueue ((:) (i,0)) soundOnce i = over soundQueue ((:) (i,0))
@@ -83,17 +84,19 @@ For each origin only one sound will play at a time.
soundOnceOrigin soundOnceOrigin
:: Int -- ^ ID of the sound to be played :: Int -- ^ ID of the sound to be played
-> SoundOrigin -- ^ The \"creator\" of the sound -> SoundOrigin -- ^ The \"creator\" of the sound
-> Point2 -- ^ The position of the sound in the world
-> World -> World -> World -> World
soundOnceOrigin sType so = over sounds (M.insertWith (flip const) so sound) soundOnceOrigin sType so p w = over sounds (M.insertWith (flip const) so theSound) w
where where
sound = Sound theSound = Sound
{ _soundChunkID = sType { _soundChunkID = sType
, _soundTime = Nothing , _soundTime = Nothing
, _soundFadeTime = 0 , _soundFadeTime = 0
, _soundStatus = ToStart , _soundStatus = ToStart
, _soundChannel = Nothing , _soundChannel = Nothing
, _soundPos = Nothing , _soundPos = Just (a,0)
} }
a = soundAngle p w
soundFromPos soundFromPos
:: SoundOrigin -- ^ \"Creator\" of sound :: SoundOrigin -- ^ \"Creator\" of sound
@@ -150,6 +153,7 @@ soundFrom so sType time fadeTime w = over sounds (M.insertWith f so sound) w
{-| Uses the first free origin from a list. {-| Uses the first free origin from a list.
Does nothing if all origins are already creating sounds. Does nothing if all origins are already creating sounds.
TODO: add positional information.
-} -}
soundMultiFrom soundMultiFrom
:: [SoundOrigin] :: [SoundOrigin]
+5 -4
View File
@@ -1,18 +1,19 @@
module Dodge.WorldEvent.Sound module Dodge.WorldEvent.Sound
where where
import Dodge.Data import Dodge.Data
import Geometry.Data (Point2)
import Dodge.SoundLogic import Dodge.SoundLogic
import System.Random import System.Random
import Control.Lens import Control.Lens
mkSoundBreakGlass :: World -> World mkSoundBreakGlass :: Point2 -> World -> World
mkSoundBreakGlass w = soundOnceOrigin soundid (GlassBreakSound 0) $ set randGen g w mkSoundBreakGlass p w = soundOnceOrigin soundid (GlassBreakSound 0) p $ set randGen g w
where where
(soundid,g) = _randGen w & randomR (37,40) (soundid,g) = _randGen w & randomR (37,40)
mkSoundSplinterGlass :: World -> World mkSoundSplinterGlass :: Point2 -> World -> World
mkSoundSplinterGlass w = soundOnceOrigin soundid (GlassBreakSound 1) $ set randGen g w mkSoundSplinterGlass p w = soundOnceOrigin soundid (GlassBreakSound 1) p $ set randGen g w
where where
(soundid,g) = _randGen w & randomR (33,36) (soundid,g) = _randGen w & randomR (33,36)