Work on Falling carriage state
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
module Dodge.Creature.State.WalkCycle (updateCarriage) where
|
||||
|
||||
import Data.Maybe
|
||||
import Dodge.Creature.HandPos
|
||||
import Linear
|
||||
import Control.Lens
|
||||
@@ -10,31 +11,36 @@ import Dodge.SoundLogic
|
||||
import Sound.Data
|
||||
|
||||
updateCarriage :: Int -> World -> World
|
||||
updateCarriage cid w
|
||||
| Just cr <- w ^? cWorld . lWorld . creatures . ix cid
|
||||
, Walking x ff <- cr ^. crStance . carriage
|
||||
, x >= strideLength cr =
|
||||
w
|
||||
updateCarriage cid w = fromMaybe w $ do
|
||||
cr <- w ^? cWorld . lWorld . creatures . ix cid
|
||||
return $ updateCarriage' cid cr w (cr ^. crStance . carriage)
|
||||
|
||||
updateCarriage' :: Int -> Creature -> World -> Carriage -> World
|
||||
updateCarriage' cid cr w = \case
|
||||
Walking x ff | x >= strideLength cr -> w
|
||||
& soundMultiFrom
|
||||
[FootstepSound i | i <- [0 .. 10]]
|
||||
(cr ^. crPos . _xy)
|
||||
(chooseFootSound ff)
|
||||
Nothing
|
||||
& over (cWorld . lWorld . creatures . ix cid . crStance . carriage) resetStride
|
||||
| Just cr <- w ^? cWorld . lWorld . creatures . ix cid
|
||||
, z <- cr ^. crPos . _z
|
||||
, Flying dz x oop <- cr ^. crStance . carriage =
|
||||
w & cWorld . lWorld . creatures . ix cid . crPos . _xy +~ x *^ f (cr ^. crOldPos . _xy - oop)
|
||||
Walking {} -> w
|
||||
Floating -> w
|
||||
Flying {_zSpeed = dz, _flyInertia = x} ->
|
||||
w & cWorld . lWorld . creatures . ix cid . crPos . _xy +~ x *^ f (cr ^. crOldPos . _xy - oop ^. _xy)
|
||||
& cWorld . lWorld . creatures . ix cid . crPos . _z +~ dz
|
||||
& cWorld . lWorld . creatures . ix cid . crStance . carriage . zSpeed
|
||||
%~ if z < 17 then min 0.05 . (+0.001) else max (-0.05) . (subtract 0.001)
|
||||
| otherwise = w
|
||||
%~ if cr ^. crPos . _z < 17 then min 0.05 . (+0.001) else max (-0.05) . subtract 0.001
|
||||
Boosting {} -> w
|
||||
Falling _ _ -> w & cWorld . lWorld . creatures . ix cid . crPos +~
|
||||
0.99 *^ (cr ^. crOldPos - oop & _z -~ 0.5)
|
||||
OnGround {} -> w
|
||||
where
|
||||
-- limits max speed gained through inertia
|
||||
-- f = id
|
||||
oop = cr ^. crOldOldPos
|
||||
f v | norm v > 10 = 10 *^ signorm v
|
||||
| otherwise = v
|
||||
|
||||
|
||||
resetStride :: Carriage -> Carriage
|
||||
resetStride = \case
|
||||
Walking _ ff -> Walking 0 (normalGait ff)
|
||||
|
||||
Reference in New Issue
Block a user