Simplify walk cycle
This commit is contained in:
@@ -423,7 +423,7 @@ setRBCreatureTargeting cr w ituse
|
||||
updateMovement :: Creature -> Creature
|
||||
updateMovement cr
|
||||
| isFrictionless cr = over crPos (+.+ momentum) cr
|
||||
| otherwise = updateWalkCycle cr
|
||||
| otherwise = cr & crStance %~ updateWalkCycle
|
||||
where
|
||||
momentum' = 0.98 *.* (_crPos cr -.- _crOldPos cr)
|
||||
momentum
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
module Dodge.Creature.State.WalkCycle (
|
||||
updateWalkCycle,
|
||||
footstepSideEffect,
|
||||
@@ -6,36 +7,35 @@ module Dodge.Creature.State.WalkCycle (
|
||||
import Control.Lens
|
||||
import Dodge.Data.World
|
||||
import Dodge.SoundLogic
|
||||
import Geometry.Data
|
||||
import Sound.Data
|
||||
|
||||
updateWalkCycle :: Creature -> Creature
|
||||
updateWalkCycle cr = case cr ^? crStance . carriage of
|
||||
Just (Walking x ff) | x > maxStride -> cr & crStance . carriage .~ Walking 0 (normalGait ff)
|
||||
_ -> cr
|
||||
updateWalkCycle :: Stance -> Stance
|
||||
updateWalkCycle s = case s ^. carriage of
|
||||
Walking x ff | x > maxStride -> s & carriage .~ Walking 0 (normalGait ff)
|
||||
_ -> s
|
||||
where
|
||||
maxStride = _strideLength $ _crStance cr
|
||||
maxStride = s ^. strideLength
|
||||
|
||||
normalGait :: FootForward -> FootForward
|
||||
normalGait LeftForward = RightForward
|
||||
normalGait WasLeftForward = RightForward
|
||||
normalGait RightForward = LeftForward
|
||||
normalGait WasRightForward = LeftForward
|
||||
normalGait = \case
|
||||
LeftForward -> RightForward
|
||||
WasLeftForward -> RightForward
|
||||
RightForward -> LeftForward
|
||||
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
|
||||
footstepSideEffect cr = case cr ^. crStance . carriage of
|
||||
Walking x ff
|
||||
| x > maxStride ->
|
||||
soundMultiFrom
|
||||
[FootstepSound i | i <- [0 .. 10]]
|
||||
(cr ^. crPos)
|
||||
(chooseFootSound ff)
|
||||
Nothing
|
||||
_ -> id
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user