44 lines
1.3 KiB
Haskell
44 lines
1.3 KiB
Haskell
module Dodge.Creature.State.WalkCycle
|
|
( updateWalkCycle
|
|
, footstepSideEffect
|
|
)
|
|
where
|
|
import Dodge.Data
|
|
import Dodge.SoundLogic
|
|
import Geometry.Data
|
|
import Sound.Data
|
|
|
|
import Control.Lens
|
|
|
|
updateWalkCycle :: Creature -> Creature
|
|
updateWalkCycle cr = case cr ^? crStance . carriage of
|
|
Just (Walking x ff) | x > maxStride -> cr & crStance . carriage .~ Walking 0 (normalGait ff)
|
|
_ -> cr
|
|
where
|
|
maxStride = _strideLength $ _crStance cr
|
|
|
|
normalGait :: FootForward -> FootForward
|
|
normalGait LeftForward = RightForward
|
|
normalGait WasLeftForward = RightForward
|
|
normalGait RightForward = LeftForward
|
|
normalGait WasRightForward = LeftForward
|
|
|
|
footstepSideEffect :: Creature -> World -> World
|
|
footstepSideEffect cr w = case cr ^? crStance . carriage of
|
|
Just (Walking x ff) -> makeFootstepSound x maxStride ff (_crPos cr) w
|
|
_ -> w
|
|
where
|
|
maxStride = _strideLength (_crStance cr)
|
|
|
|
|
|
makeFootstepSound :: Int -> Int -> FootForward -> Point2 -> World -> World
|
|
makeFootstepSound currentStride maxStride ff p
|
|
| currentStride > maxStride = soundMultiFrom footor p (chooseFootSound ff) Nothing
|
|
| otherwise = id
|
|
where
|
|
footor = [FootstepSound 0,FootstepSound 1]
|
|
|
|
chooseFootSound :: FootForward -> SoundID
|
|
chooseFootSound LeftForward = foot1S
|
|
chooseFootSound _ = foot2S
|