Modularise and improve step cycle

This commit is contained in:
2021-06-06 18:23:52 +02:00
parent eb7c4a8067
commit edd947a857
7 changed files with 98 additions and 29 deletions
+39
View File
@@ -0,0 +1,39 @@
module Dodge.Creature.State.WalkCycle
where
import Dodge.Data
import Dodge.Creature.Stance.Data
import Dodge.SoundLogic
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 = WasLeftForward
normalGait WasLeftForward = RightForward
normalGait RightForward = WasRightForward
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 = soundMultiFromPos footor (chooseFootSound ff) 3 0 p
| otherwise = id
where
footor = [FootstepSound 0,FootstepSound 1]
chooseFootSound :: FootForward -> Int
chooseFootSound LeftForward = 22
chooseFootSound _ = 23