From e6bb6fb1f37e706d2e7fceb80d7f2dad86d3d9fb Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 19 Jun 2025 12:46:54 +0100 Subject: [PATCH] Simplify walk cycle --- src/Dodge/Creature/State.hs | 2 +- src/Dodge/Creature/State/WalkCycle.hs | 40 +++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 8ec59ae31..fec8dc843 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -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 diff --git a/src/Dodge/Creature/State/WalkCycle.hs b/src/Dodge/Creature/State/WalkCycle.hs index b94d4cc16..09674316d 100644 --- a/src/Dodge/Creature/State/WalkCycle.hs +++ b/src/Dodge/Creature/State/WalkCycle.hs @@ -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