First implementation of creatures detecting sounds

This commit is contained in:
2021-09-08 21:56:58 +01:00
parent c3d567353c
commit a2288110ae
8 changed files with 22 additions and 20 deletions
+2 -1
View File
@@ -26,7 +26,7 @@ import Control.Lens
--import Foreign (Word32) --import Foreign (Word32)
import Control.Monad import Control.Monad
--import System.Random --import System.Random
import qualified Data.Map as M --import qualified Data.Map as M
import qualified Data.IntMap as IM import qualified Data.IntMap as IM
import Graphics.Rendering.OpenGL hiding (color, rotate, scale, translate) import Graphics.Rendering.OpenGL hiding (color, rotate, scale, translate)
import qualified SDL import qualified SDL
@@ -75,6 +75,7 @@ doSideEffects w = do
) )
newpdata <- foldr (=<<) (return (preData & frameTimer .~ endTicks)) (_doneSideEffects w) newpdata <- foldr (=<<) (return (preData & frameTimer .~ endTicks)) (_doneSideEffects w)
return $ w & preloadData .~ newpdata return $ w & preloadData .~ newpdata
& playingSounds .~ newPlayingSounds
doPreload :: IO PreloadData doPreload :: IO PreloadData
doPreload = do doPreload = do
+1 -1
View File
@@ -3,7 +3,7 @@ IO actions that apply config side effects and save configuration settings to dis
-} -}
module Dodge.Config.Update module Dodge.Config.Update
where where
import Dodge.Data.SoundOrigin --import Dodge.Data.SoundOrigin
import Dodge.Config.Data import Dodge.Config.Data
import Sound import Sound
import Data.Preload import Data.Preload
+6 -7
View File
@@ -10,7 +10,7 @@ import Dodge.Creature.Memory.Data
import Dodge.Base.Collide import Dodge.Base.Collide
import Geometry.Vector import Geometry.Vector
--import Geometry.Data --import Geometry.Data
--import Sound.Data import Sound.Data
--import StrictHelp --import StrictHelp
import Data.Maybe import Data.Maybe
@@ -88,12 +88,11 @@ awakeLevelPerception cr = case _crAwakeLevel $ _crPerception cr of
Overstrung -> 10000 Overstrung -> 10000
newSounds :: World -> [(Point2,Float)] newSounds :: World -> [(Point2,Float)]
newSounds = mapMaybe f . M.elems . _sounds newSounds = mapMaybe f . M.elems . _playingSounds
where where
f s = Just (_soundPos s, _soundVolume s) f s | _soundStatus s == JustStartedPlaying
-- f s | _soundStatus s == JustStartedPlaying = Just (_soundPos s, _soundVolume s)
-- = Just (_soundPos s, _soundVolume s) | otherwise = Nothing
-- | otherwise = Nothing
rememberSounds :: Creature -> Reader World Creature rememberSounds :: Creature -> Reader World Creature
rememberSounds cr = do rememberSounds cr = do
@@ -102,4 +101,4 @@ rememberSounds cr = do
-- return $ cr & crMemory . soundsToInvestigate .~ [V2 0 0] -- return $ cr & crMemory . soundsToInvestigate .~ [V2 0 0]
soundIsClose :: Creature -> (Point2,Float) -> Bool soundIsClose :: Creature -> (Point2,Float) -> Bool
soundIsClose cr (pos,vol) = True -- vol > (_auDist . _crAudition $ _crPerception cr) (dist pos (_crPos cr)) soundIsClose cr (pos,vol) = vol > (_auDist . _crAudition $ _crPerception cr) (dist pos (_crPos cr))
+1 -1
View File
@@ -66,7 +66,7 @@ creatureDisplayText w cr
(V2 x y) = campos +.+ v +.+ _crRad cr *.* normalizeV v (V2 x y) = campos +.+ v +.+ _crRad cr *.* normalizeV v
creatureDisplayString :: Creature -> String creatureDisplayString :: Creature -> String
creatureDisplayString cr = show . _soundsToInvestigate $ _crMemory cr creatureDisplayString cr = show . take 1 . _soundsToInvestigate $ _crMemory cr
-- | isAsleep = "Z" -- | isAsleep = "Z"
-- | isSuspicious = "?" -- | isSuspicious = "?"
-- | otherwise = "" -- | otherwise = ""
+3 -1
View File
@@ -47,7 +47,9 @@ tryMeleeAttack cr tcr
setMvPos :: Creature -> Reader World Creature setMvPos :: Creature -> Reader World Creature
setMvPos cr = pure $ cr & crMvTarget .~ mpos setMvPos cr = pure $ cr & crMvTarget .~ mpos
where where
mpos = (_crPos <$> _crTarget cr) <|> listToMaybe (_soundsToInvestigate $ _crMemory cr) mpos = (_crPos <$> _crTarget cr)
<|> _crMvTarget cr
<|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
setTargetMv setTargetMv
:: (Creature -> Reader World (Maybe Creature)) -- ^ Function for determining target :: (Creature -> Reader World (Maybe Creature)) -- ^ Function for determining target
+1 -1
View File
@@ -84,7 +84,7 @@ defaultVision = Eyes
| otherwise = 1 | otherwise = 1
defaultAudition :: Audition defaultAudition :: Audition
defaultAudition = Ears defaultAudition = Ears
{ _auDist = \x -> 1 / (x * x) { _auDist = \x -> x * x
} }
defaultChaseMvType :: CrMvType defaultChaseMvType :: CrMvType
defaultChaseMvType = ChaseMvType defaultChaseMvType = ChaseMvType
+1 -1
View File
@@ -54,7 +54,7 @@ initialWorld = defaultWorld
} }
testStringInit :: World -> [String] testStringInit :: World -> [String]
--testStringInit _ = [] --testStringInit _ = []
testStringInit w = [show $ newSounds w] testStringInit w = [show . length $ newSounds w]
--testStringInit w = (show . _crPos $ _creatures w IM.! 0) --testStringInit w = (show . _crPos $ _creatures w IM.! 0)
-- : (map show . _grBound . last $ sortOn _grName grs) -- : (map show . _grBound . last $ sortOn _grName grs)
-- ++ closeRooms -- ++ closeRooms
+7 -7
View File
@@ -13,11 +13,11 @@ loadSounds = do
putdownSound' <- Mix.load "./data/sound/whiteNoiseFadeOut.wav" putdownSound' <- Mix.load "./data/sound/whiteNoiseFadeOut.wav"
fireSound' <- Mix.load "./data/sound/fire1.wav" fireSound' <- Mix.load "./data/sound/fire1.wav"
grenadeBang' <- Mix.load "./data/sound/grenade.wav" grenadeBang' <- Mix.load "./data/sound/grenade.wav"
tapQuiet' <- Mix.load "./data/sound/tapQuiet.wav" tapQuiet' <- Mix.load "./data/sound/tapQuiet.wav"
twoStep' <- Mix.load "./data/sound/twoStep.wav" twoStep' <- Mix.load "./data/sound/twoStep.wav"
healSound' <- Mix.load "./data/sound/heal.wav" healSound' <- Mix.load "./data/sound/heal.wav"
doorSound' <- Mix.load "./data/sound/slideDoor.wav" doorSound' <- Mix.load "./data/sound/slideDoor.wav"
twoStepSlow' <- Mix.load "./data/sound/twoStepSlow.wav" twoStepSlow' <- Mix.load "./data/sound/twoStepSlow.wav"
knifeSound' <- Mix.load "./data/sound/knife.wav" knifeSound' <- Mix.load "./data/sound/knife.wav"
buzzSound' <- Mix.load "./data/sound/buzz.wav" buzzSound' <- Mix.load "./data/sound/buzz.wav"
hitSound' <- Mix.load "./data/sound/hit1.wav" hitSound' <- Mix.load "./data/sound/hit1.wav"
@@ -46,7 +46,7 @@ loadSounds = do
glass2' <- Mix.load "./data/sound/Small-Piece-Of-Glass-Shattering-A2.wav" glass2' <- Mix.load "./data/sound/Small-Piece-Of-Glass-Shattering-A2.wav"
glass3' <- Mix.load "./data/sound/Small-Piece-Of-Glass-Shattering-A3.wav" glass3' <- Mix.load "./data/sound/Small-Piece-Of-Glass-Shattering-A3.wav"
glass4' <- Mix.load "./data/sound/Small-Piece-Of-Glass-Shattering-A4.wav" glass4' <- Mix.load "./data/sound/Small-Piece-Of-Glass-Shattering-A4.wav"
foamSpray' <- Mix.load "./data/sound/foamSprayLoop.wav" foamSpray <- Mix.load "./data/sound/foamSprayLoop.wav"
foamSprayFadeOut <- Mix.load "./data/sound/foamSprayFadeOut.wav" foamSprayFadeOut <- Mix.load "./data/sound/foamSprayFadeOut.wav"
sineRaisePitchOneSec <- Mix.load "./data/sound/sineRaisePitchOneSec.wav" sineRaisePitchOneSec <- Mix.load "./data/sound/sineRaisePitchOneSec.wav"
sineRaisePitchTwoSec <- Mix.load "./data/sound/sineRaisePitchTwoSec.wav" sineRaisePitchTwoSec <- Mix.load "./data/sound/sineRaisePitchTwoSec.wav"
@@ -93,7 +93,7 @@ loadSounds = do
, glass2' , glass2'
, glass3' , glass3'
, glass4' --40 , glass4' --40
, foamSpray' , foamSpray
, foamSprayFadeOut , foamSprayFadeOut
, sineRaisePitchOneSec , sineRaisePitchOneSec
, sineRaisePitchTwoSec , sineRaisePitchTwoSec