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 Control.Monad
--import System.Random
import qualified Data.Map as M
--import qualified Data.Map as M
import qualified Data.IntMap as IM
import Graphics.Rendering.OpenGL hiding (color, rotate, scale, translate)
import qualified SDL
@@ -75,6 +75,7 @@ doSideEffects w = do
)
newpdata <- foldr (=<<) (return (preData & frameTimer .~ endTicks)) (_doneSideEffects w)
return $ w & preloadData .~ newpdata
& playingSounds .~ newPlayingSounds
doPreload :: IO PreloadData
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
where
import Dodge.Data.SoundOrigin
--import Dodge.Data.SoundOrigin
import Dodge.Config.Data
import Sound
import Data.Preload
+6 -7
View File
@@ -10,7 +10,7 @@ import Dodge.Creature.Memory.Data
import Dodge.Base.Collide
import Geometry.Vector
--import Geometry.Data
--import Sound.Data
import Sound.Data
--import StrictHelp
import Data.Maybe
@@ -88,12 +88,11 @@ awakeLevelPerception cr = case _crAwakeLevel $ _crPerception cr of
Overstrung -> 10000
newSounds :: World -> [(Point2,Float)]
newSounds = mapMaybe f . M.elems . _sounds
newSounds = mapMaybe f . M.elems . _playingSounds
where
f s = Just (_soundPos s, _soundVolume s)
-- f s | _soundStatus s == JustStartedPlaying
-- = Just (_soundPos s, _soundVolume s)
-- | otherwise = Nothing
f s | _soundStatus s == JustStartedPlaying
= Just (_soundPos s, _soundVolume s)
| otherwise = Nothing
rememberSounds :: Creature -> Reader World Creature
rememberSounds cr = do
@@ -102,4 +101,4 @@ rememberSounds cr = do
-- return $ cr & crMemory . soundsToInvestigate .~ [V2 0 0]
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
creatureDisplayString :: Creature -> String
creatureDisplayString cr = show . _soundsToInvestigate $ _crMemory cr
creatureDisplayString cr = show . take 1 . _soundsToInvestigate $ _crMemory cr
-- | isAsleep = "Z"
-- | isSuspicious = "?"
-- | otherwise = ""
+3 -1
View File
@@ -47,7 +47,9 @@ tryMeleeAttack cr tcr
setMvPos :: Creature -> Reader World Creature
setMvPos cr = pure $ cr & crMvTarget .~ mpos
where
mpos = (_crPos <$> _crTarget cr) <|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
mpos = (_crPos <$> _crTarget cr)
<|> _crMvTarget cr
<|> listToMaybe (_soundsToInvestigate $ _crMemory cr)
setTargetMv
:: (Creature -> Reader World (Maybe Creature)) -- ^ Function for determining target
+1 -1
View File
@@ -84,7 +84,7 @@ defaultVision = Eyes
| otherwise = 1
defaultAudition :: Audition
defaultAudition = Ears
{ _auDist = \x -> 1 / (x * x)
{ _auDist = \x -> x * x
}
defaultChaseMvType :: CrMvType
defaultChaseMvType = ChaseMvType
+1 -1
View File
@@ -54,7 +54,7 @@ initialWorld = defaultWorld
}
testStringInit :: World -> [String]
--testStringInit _ = []
testStringInit w = [show $ newSounds w]
testStringInit w = [show . length $ newSounds w]
--testStringInit w = (show . _crPos $ _creatures w IM.! 0)
-- : (map show . _grBound . last $ sortOn _grName grs)
-- ++ closeRooms
+7 -7
View File
@@ -13,11 +13,11 @@ loadSounds = do
putdownSound' <- Mix.load "./data/sound/whiteNoiseFadeOut.wav"
fireSound' <- Mix.load "./data/sound/fire1.wav"
grenadeBang' <- Mix.load "./data/sound/grenade.wav"
tapQuiet' <- Mix.load "./data/sound/tapQuiet.wav"
twoStep' <- Mix.load "./data/sound/twoStep.wav"
healSound' <- Mix.load "./data/sound/heal.wav"
doorSound' <- Mix.load "./data/sound/slideDoor.wav"
twoStepSlow' <- Mix.load "./data/sound/twoStepSlow.wav"
tapQuiet' <- Mix.load "./data/sound/tapQuiet.wav"
twoStep' <- Mix.load "./data/sound/twoStep.wav"
healSound' <- Mix.load "./data/sound/heal.wav"
doorSound' <- Mix.load "./data/sound/slideDoor.wav"
twoStepSlow' <- Mix.load "./data/sound/twoStepSlow.wav"
knifeSound' <- Mix.load "./data/sound/knife.wav"
buzzSound' <- Mix.load "./data/sound/buzz.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"
glass3' <- Mix.load "./data/sound/Small-Piece-Of-Glass-Shattering-A3.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"
sineRaisePitchOneSec <- Mix.load "./data/sound/sineRaisePitchOneSec.wav"
sineRaisePitchTwoSec <- Mix.load "./data/sound/sineRaisePitchTwoSec.wav"
@@ -93,7 +93,7 @@ loadSounds = do
, glass2'
, glass3'
, glass4' --40
, foamSpray'
, foamSpray
, foamSprayFadeOut
, sineRaisePitchOneSec
, sineRaisePitchTwoSec