Modularise and improve step cycle
This commit is contained in:
+26
-5
@@ -12,6 +12,7 @@ module Dodge.SoundLogic (
|
||||
, soundFromPos
|
||||
, soundFrom
|
||||
, soundMultiFrom
|
||||
, soundMultiFromPos
|
||||
, stopSoundFrom
|
||||
|
||||
-- * Manipulation of all sounds
|
||||
@@ -129,8 +130,7 @@ soundFrom so sType time fadeTime = sounds %~ M.insertWith f so sound
|
||||
, _soundChannel = Nothing
|
||||
, _soundPos = Nothing
|
||||
}
|
||||
f _ s = s {_soundTime = Just time, _soundFadeTime = fadeTime}
|
||||
|
||||
f _ s = s {_soundTime = Just time, _soundFadeTime = fadeTime}
|
||||
{-| Uses the first free origin from a list.
|
||||
Does nothing if all origins are already creating sounds.
|
||||
TODO: add positional information.
|
||||
@@ -154,9 +154,30 @@ soundMultiFrom (so:sos) sType time fadeTime w
|
||||
, _soundChannel = Nothing
|
||||
, _soundPos = Nothing
|
||||
}
|
||||
|
||||
{- | Sets '_soundTime' to 0.
|
||||
-}
|
||||
{-| Uses the first free origin from a list.
|
||||
Does nothing if all origins are already creating sounds. -}
|
||||
soundMultiFromPos
|
||||
:: [SoundOrigin]
|
||||
-> Int -- ^ Sound ID
|
||||
-> Int -- ^ Frames to play for
|
||||
-> Int -- ^ Fade out time (ms)
|
||||
-> Point2 -- ^ Position
|
||||
-> World -> World
|
||||
soundMultiFromPos [] _ _ _ _ w = w
|
||||
soundMultiFromPos (so:sos) sType time fadeTime pos w
|
||||
| so `M.member` _sounds w = soundMultiFromPos sos sType time fadeTime pos w
|
||||
| otherwise = over sounds (M.insert so sound) w
|
||||
where
|
||||
sound = Sound
|
||||
{ _soundChunkID = sType
|
||||
, _soundTime = Nothing
|
||||
, _soundStatus = ToStart
|
||||
, _soundFadeTime = fadeTime
|
||||
, _soundChannel = Nothing
|
||||
, _soundPos = Just (a,0)
|
||||
}
|
||||
a = soundAngle pos w
|
||||
{- | Sets '_soundTime' to 0. -}
|
||||
stopSoundFrom :: SoundOrigin -> World -> World
|
||||
stopSoundFrom so = over (sounds . ix so . soundTime) (fmap $ min 0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user