Tweak sound positions
This commit is contained in:
@@ -879,8 +879,7 @@ tractorBeamAt colID i pos dir = Projectile
|
|||||||
|
|
||||||
aGasCloud :: Int -> World -> World
|
aGasCloud :: Int -> World -> World
|
||||||
aGasCloud cid w
|
aGasCloud cid w
|
||||||
= -- soundFrom Flame fireSound 2 500
|
= insertCloud $ set randGen g $
|
||||||
insertCloud $ set randGen g $
|
|
||||||
w
|
w
|
||||||
where
|
where
|
||||||
(a,g) = randomR (-0.1,0.1) (_randGen w)
|
(a,g) = randomR (-0.1,0.1) (_randGen w)
|
||||||
@@ -896,7 +895,6 @@ aGasCloud cid w
|
|||||||
aFlame :: Float -> Int -> World -> World
|
aFlame :: Float -> Int -> World -> World
|
||||||
aFlame a cid w
|
aFlame a cid w
|
||||||
= shakeCr cid 2
|
= shakeCr cid 2
|
||||||
-- $ soundFrom Flame fireSound 2 500
|
|
||||||
$ insertFlame $ resetAngle $ set randGen g $
|
$ insertFlame $ resetAngle $ set randGen g $
|
||||||
w
|
w
|
||||||
where
|
where
|
||||||
@@ -1381,7 +1379,7 @@ moveRemoteShell time i cid itid dir w
|
|||||||
$ set (projectiles . ix i . pjUpdate)
|
$ set (projectiles . ix i . pjUpdate)
|
||||||
(moveRemoteShell (time-1) i cid itid newdir)
|
(moveRemoteShell (time-1) i cid itid newdir)
|
||||||
$ over (projectiles . ix i . pjVel) (\v -> accel +.+ frict *.* v)
|
$ over (projectiles . ix i . pjVel) (\v -> accel +.+ frict *.* v)
|
||||||
$ soundFrom (ShellSound i) (fromIntegral smokeTrailSound) (1) 250
|
$ soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) (1) 250
|
||||||
$ smokeGen
|
$ smokeGen
|
||||||
$ makeFlameletTimed oldPos
|
$ makeFlameletTimed oldPos
|
||||||
(0.5 *.* rotateV (pi+sparkD) accel) Nothing 3 10
|
(0.5 *.* rotateV (pi+sparkD) accel) Nothing 3 10
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ withWarmUp t f cid w
|
|||||||
| fState == 0 = set (pointerToItem . wpFire) (withWarmUp 100 f)
|
| fState == 0 = set (pointerToItem . wpFire) (withWarmUp 100 f)
|
||||||
$ set (pointerToItem . wpFireState) 2
|
$ set (pointerToItem . wpFireState) 2
|
||||||
w
|
w
|
||||||
| t > 1 = set (pointerToItem . wpFire) (withWarmUp (t-1) f)
|
| t > 2 = set (pointerToItem . wpFire) (withWarmUp (t-1) f)
|
||||||
$ set (pointerToItem . wpFireState) 2
|
$ set (pointerToItem . wpFireState) 2
|
||||||
$ continueSound 26
|
$ soundFrom (CrWeaponSound cid) 26 2 0
|
||||||
w
|
w
|
||||||
| t > 0 = set (pointerToItem . wpFire) (withWarmUp (t-1) f)
|
| t > 0 = set (pointerToItem . wpFire) (withWarmUp (t-1) f)
|
||||||
$ set (pointerToItem . wpFireState) 2
|
$ set (pointerToItem . wpFireState) 2
|
||||||
@@ -54,7 +54,7 @@ withWarmUp t f cid w
|
|||||||
$ over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
|
$ over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
|
||||||
$ set (pointerToItem . wpFireState) 2
|
$ set (pointerToItem . wpFireState) 2
|
||||||
$ f cid
|
$ f cid
|
||||||
$ continueSound 28
|
$ soundFrom (CrWeaponSound cid) 28 2 0
|
||||||
w
|
w
|
||||||
where
|
where
|
||||||
cr = _creatures w IM.! cid
|
cr = _creatures w IM.! cid
|
||||||
@@ -64,12 +64,8 @@ withWarmUp t f cid w
|
|||||||
fState = _wpFireState item
|
fState = _wpFireState item
|
||||||
fRate = _wpFireRate item
|
fRate = _wpFireRate item
|
||||||
reloadCondition = _wpLoadedAmmo item == 0
|
reloadCondition = _wpLoadedAmmo item == 0
|
||||||
continueSound soundID
|
|
||||||
| cid == 0 = soundFrom (CrWeaponSound cid) soundID 1 0
|
|
||||||
| otherwise = soundFromPos (CrWeaponSound cid) (_crPos cr) soundID 1 0
|
|
||||||
|
|
||||||
withSound :: Int -> (Int -> World -> World) -> Int -> World -> World
|
withSound :: Int -> (Int -> World -> World) -> Int -> World -> World
|
||||||
withSound soundid f 0 w = (soundOnce soundid . f 0) w
|
|
||||||
withSound soundid f cid w = (soundOncePos soundid p . f cid) w
|
withSound soundid f cid w = (soundOncePos soundid p . f cid) w
|
||||||
where
|
where
|
||||||
p = _crPos (_creatures w IM.! cid)
|
p = _crPos (_creatures w IM.! cid)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import qualified SDL.Mixer as Mix
|
|||||||
-- }}}
|
-- }}}
|
||||||
loadSounds :: IO (IM.IntMap Mix.Chunk)
|
loadSounds :: IO (IM.IntMap Mix.Chunk)
|
||||||
loadSounds = do
|
loadSounds = do
|
||||||
Mix.openAudio Mix.defaultAudio 256
|
Mix.openAudio Mix.defaultAudio 128
|
||||||
pFireSound <- Mix.load "./data/sound/tap3.wav"
|
pFireSound <- Mix.load "./data/sound/tap3.wav"
|
||||||
click <- Mix.load "./data/sound/click1.wav"
|
click <- Mix.load "./data/sound/click1.wav"
|
||||||
reloadSound' <- Mix.load "./data/sound/reload1.wav"
|
reloadSound' <- Mix.load "./data/sound/reload1.wav"
|
||||||
|
|||||||
+100
-13
@@ -1,33 +1,89 @@
|
|||||||
module Dodge.SoundLogic where
|
{-|
|
||||||
|
Module : Dodge.SoundLogic
|
||||||
|
Description : Messages to "Sound" backend
|
||||||
|
|
||||||
|
This module allows us to talk to the "Sound" module.
|
||||||
|
-}
|
||||||
|
module Dodge.SoundLogic (
|
||||||
|
-- * Manipulation of individual sounds
|
||||||
|
soundOnce
|
||||||
|
, soundOncePos
|
||||||
|
, soundOnceOrigin
|
||||||
|
, soundFromPos
|
||||||
|
, soundFrom
|
||||||
|
, soundMultiFrom
|
||||||
|
, stopSoundFrom
|
||||||
|
|
||||||
|
-- * Manipulation of all sounds
|
||||||
|
, haltSound
|
||||||
|
, resumeSound
|
||||||
|
, pauseSound
|
||||||
|
|
||||||
|
-- * Synonyms for sound identifiers
|
||||||
|
, clickSound
|
||||||
|
, reloadSound
|
||||||
|
, pickUpSound
|
||||||
|
, putDownSound
|
||||||
|
, fireSound
|
||||||
|
, grenadeBang
|
||||||
|
, tapQuiet
|
||||||
|
, twoStepSound
|
||||||
|
, healSound
|
||||||
|
, doorSound
|
||||||
|
, twoStepSlowSound
|
||||||
|
, knifeSound
|
||||||
|
, buzzSound
|
||||||
|
, hitSound
|
||||||
|
, autoGunSound
|
||||||
|
, shotgunSound
|
||||||
|
, teleSound
|
||||||
|
, longGunSound
|
||||||
|
, launcherSound
|
||||||
|
, smokeTrailSound
|
||||||
|
, foot1Sound
|
||||||
|
, foot2Sound
|
||||||
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Sound.Data (SoundStatus (..))
|
import Sound.Data (SoundStatus (..))
|
||||||
import Geometry.Vector
|
import Geometry.Vector
|
||||||
|
import Geometry (dist)
|
||||||
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
import Data.Int (Int16)
|
||||||
|
|
||||||
|
{-| Placeholder...-}
|
||||||
haltSound :: World -> World
|
haltSound :: World -> World
|
||||||
haltSound w = w
|
haltSound w = w
|
||||||
|
|
||||||
|
{-| Placeholder...-}
|
||||||
pauseSound :: World -> World
|
pauseSound :: World -> World
|
||||||
pauseSound w = w
|
pauseSound w = w
|
||||||
|
|
||||||
|
{-| Placeholder...-}
|
||||||
resumeSound :: World -> World
|
resumeSound :: World -> World
|
||||||
resumeSound w = w
|
resumeSound w = w
|
||||||
|
|
||||||
|
{-| Add a sound to the queue for playback.
|
||||||
|
-}
|
||||||
soundOnce :: Int -> World -> World
|
soundOnce :: Int -> World -> World
|
||||||
soundOnce i = over soundQueue ((:) (i,0))
|
soundOnce i = over soundQueue ((:) (i,0))
|
||||||
|
|
||||||
|
{-| Play a sound with a given position in the world.
|
||||||
|
Uses the angle between the given position and '_cameraViewFrom', taking into account '_cameraRot'.
|
||||||
|
-}
|
||||||
soundOncePos :: Int -> Point2 -> World -> World
|
soundOncePos :: Int -> Point2 -> World -> World
|
||||||
soundOncePos i pos w = over soundQueue ((:) (i,a)) w
|
soundOncePos i pos w = over soundQueue ((:) (i,a)) w
|
||||||
where
|
where
|
||||||
a = round
|
a = soundAngle pos w
|
||||||
. radToDeg
|
|
||||||
. normalizeAngle
|
|
||||||
. (+ pi)
|
|
||||||
$ argV (vNormal (pos -.- _cameraViewFrom w)) - _cameraRot w
|
|
||||||
|
|
||||||
soundOnceOrigin :: Int -> SoundOrigin -> World -> World
|
{-| Play a sound once, with a given origin.
|
||||||
|
For each origin only one sound will play at a time.
|
||||||
|
-}
|
||||||
|
soundOnceOrigin
|
||||||
|
:: Int -- ^ ID of the sound to be played
|
||||||
|
-> SoundOrigin -- ^ The \"creator\" of the sound
|
||||||
|
-> World -> World
|
||||||
soundOnceOrigin sType so = over sounds (M.insertWith (flip const) so sound)
|
soundOnceOrigin sType so = over sounds (M.insertWith (flip const) so sound)
|
||||||
where
|
where
|
||||||
sound = Sound
|
sound = Sound
|
||||||
@@ -39,7 +95,13 @@ soundOnceOrigin sType so = over sounds (M.insertWith (flip const) so sound)
|
|||||||
, _soundPos = Nothing
|
, _soundPos = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
soundFromPos :: SoundOrigin -> Point2 -> Int -> Int -> Int -> World -> World
|
soundFromPos
|
||||||
|
:: SoundOrigin -- ^ \"Creator\" of sound
|
||||||
|
-> Point2 -- ^ Position of sound
|
||||||
|
-> Int -- ^ ID of sound to be played
|
||||||
|
-> Int -- ^ Frames to play sound for
|
||||||
|
-> Int -- ^ Time sound fades out after playing for the given number of frames (ms)
|
||||||
|
-> World -> World
|
||||||
soundFromPos so pos sType time fadeTime w = over sounds (M.insertWith f so sound) w
|
soundFromPos so pos sType time fadeTime w = over sounds (M.insertWith f so sound) w
|
||||||
where
|
where
|
||||||
sound = Sound
|
sound = Sound
|
||||||
@@ -51,13 +113,29 @@ soundFromPos so pos sType time fadeTime w = over sounds (M.insertWith f so sound
|
|||||||
, _soundPos = Just (a,0)
|
, _soundPos = Just (a,0)
|
||||||
}
|
}
|
||||||
f _ s = s {_soundTime = Just time, _soundFadeTime = fadeTime}
|
f _ s = s {_soundTime = Just time, _soundFadeTime = fadeTime}
|
||||||
a = round
|
a = soundAngle pos w
|
||||||
|
|
||||||
|
{-| Calculates the angle of a sound with reference to '_cameraViewFrom'.
|
||||||
|
Within 10 units considers the sound to be directly in front.
|
||||||
|
-}
|
||||||
|
soundAngle :: Point2 -> World -> Int16
|
||||||
|
{-# INLINE soundAngle #-}
|
||||||
|
soundAngle p w
|
||||||
|
| dist p earPos < 10 = 0
|
||||||
|
| otherwise = round
|
||||||
. radToDeg
|
. radToDeg
|
||||||
. normalizeAngle
|
. normalizeAngle
|
||||||
. (+ pi)
|
. (+ pi)
|
||||||
$ argV (vNormal (pos -.- _cameraViewFrom w)) - _cameraRot w
|
$ argV (vNormal (p -.- earPos)) - _cameraRot w
|
||||||
|
where
|
||||||
|
earPos = _cameraViewFrom w
|
||||||
|
|
||||||
soundFrom :: SoundOrigin -> Int -> Int -> Int -> World -> World
|
soundFrom
|
||||||
|
:: SoundOrigin
|
||||||
|
-> Int -- ^ Sound ID
|
||||||
|
-> Int -- ^ Frames to play
|
||||||
|
-> Int -- ^ Fade out time (ms)
|
||||||
|
-> World -> World
|
||||||
soundFrom so sType time fadeTime w = over sounds (M.insertWith f so sound) w
|
soundFrom so sType time fadeTime w = over sounds (M.insertWith f so sound) w
|
||||||
where
|
where
|
||||||
sound = Sound
|
sound = Sound
|
||||||
@@ -70,7 +148,15 @@ soundFrom so sType time fadeTime w = over sounds (M.insertWith f so sound) w
|
|||||||
}
|
}
|
||||||
f _ s = s {_soundTime = Just time, _soundFadeTime = fadeTime}
|
f _ s = s {_soundTime = Just time, _soundFadeTime = fadeTime}
|
||||||
|
|
||||||
soundMultiFrom :: [SoundOrigin] -> Int -> Int -> Int -> World -> World
|
{-| Uses the first free origin from a list.
|
||||||
|
Does nothing if all origins are already creating sounds.
|
||||||
|
-}
|
||||||
|
soundMultiFrom
|
||||||
|
:: [SoundOrigin]
|
||||||
|
-> Int -- ^ Sound ID
|
||||||
|
-> Int -- ^ Frames to play for
|
||||||
|
-> Int -- ^ Fade out time (ms)
|
||||||
|
-> World -> World
|
||||||
soundMultiFrom [] _ _ _ w = w
|
soundMultiFrom [] _ _ _ w = w
|
||||||
soundMultiFrom (so:sos) sType time fadeTime w
|
soundMultiFrom (so:sos) sType time fadeTime w
|
||||||
| so `M.member` _sounds w = soundMultiFrom sos sType time fadeTime w
|
| so `M.member` _sounds w = soundMultiFrom sos sType time fadeTime w
|
||||||
@@ -85,7 +171,8 @@ soundMultiFrom (so:sos) sType time fadeTime w
|
|||||||
, _soundPos = Nothing
|
, _soundPos = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{- | Sets '_soundTime' to 0.
|
||||||
|
-}
|
||||||
stopSoundFrom :: SoundOrigin -> World -> World
|
stopSoundFrom :: SoundOrigin -> World -> World
|
||||||
stopSoundFrom so = over (sounds . ix so . soundTime) (fmap $ min 0)
|
stopSoundFrom so = over (sounds . ix so . soundTime) (fmap $ min 0)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user