Tweak creature update

This commit is contained in:
2025-08-06 13:10:37 +01:00
parent af5bdf59b9
commit 9fb7440776
11 changed files with 196 additions and 191 deletions
+17 -19
View File
@@ -1,37 +1,35 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Creature.State.WalkCycle (
updateWalkCycle,
) where
module Dodge.Creature.State.WalkCycle (updateWalkCycle) where
import Control.Lens
import Dodge.Data.World
import Dodge.SoundLogic
import Sound.Data
updateWalkCycle :: Creature -> World -> World
updateWalkCycle cr =
case cr ^. crStance . carriage of
Walking x ff
| x > cr ^. crStance . strideLength ->
soundMultiFrom
[FootstepSound i | i <- [0 .. 10]]
(cr ^. crPos)
(chooseFootSound ff)
Nothing
. over (cWorld . lWorld . creatures . ix (cr ^. crID) . crStance . carriage) resetStride
_ -> id
updateWalkCycle :: Int -> World -> World
updateWalkCycle cid w
| Just cr <- w ^? cWorld . lWorld . creatures . ix 0
, Walking x ff <- cr ^. crStance . carriage
, x > cr ^. crStance . strideLength =
w
& soundMultiFrom
[FootstepSound i | i <- [0 .. 10]]
(cr ^. crPos)
(chooseFootSound ff)
Nothing
& over (cWorld . lWorld . creatures . ix cid . crStance . carriage) resetStride
| otherwise = w
resetStride :: Carriage -> Carriage
resetStride (Walking _ ff) = Walking 0 (normalGait ff)
resetStride x = x
resetStride = \case
Walking _ ff -> Walking 0 (normalGait ff)
x -> x
normalGait :: FootForward -> FootForward
normalGait = \case
LeftForward -> RightForward
WasLeftForward -> RightForward
RightForward -> LeftForward
WasRightForward -> LeftForward
chooseFootSound :: FootForward -> SoundID
chooseFootSound LeftForward = foot1S