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