Modularise and improve step cycle
This commit is contained in:
@@ -53,15 +53,17 @@ advanceStepCounter
|
||||
:: Float -- ^ Speed
|
||||
-> Creature
|
||||
-> Creature
|
||||
advanceStepCounter speed = crStance . carriage %~ f
|
||||
advanceStepCounter speed cr = cr & crStance . carriage %~ f
|
||||
where
|
||||
f w@Walking{} = w{_stepToAdd = ceiling speed}
|
||||
f s = s
|
||||
--stnce = _crStance cr
|
||||
f car = case car of
|
||||
Standing -> f (Walking 0 RightForward)
|
||||
Walking i ff -> Walking (i + ceiling speed) ff
|
||||
_ -> car
|
||||
|
||||
creatureTurn :: Float -> Creature -> Creature
|
||||
creatureTurn a = crDir +~ a
|
||||
|
||||
|
||||
creatureTurnTo :: Point2 -> Creature -> Creature
|
||||
creatureTurnTo p cr
|
||||
| vToTarg == (0,0) = cr -- this should deal with the angleVV error
|
||||
|
||||
@@ -6,19 +6,31 @@ import Geometry.Data
|
||||
|
||||
import Control.Lens
|
||||
data Stance = Stance
|
||||
{_carriage :: Carriage
|
||||
,_posture :: Posture
|
||||
{_carriage :: Carriage
|
||||
,_posture :: Posture
|
||||
,_strideLength :: Int
|
||||
}
|
||||
deriving (Eq,Show)
|
||||
data Carriage
|
||||
= Walking { _stepCycle :: Int, _stepToAdd :: Int }
|
||||
= Walking
|
||||
{ _strideAmount :: Int
|
||||
, _currentFoot :: FootForward
|
||||
}
|
||||
| Standing
|
||||
| Floating
|
||||
| Flying
|
||||
| Boosting Point2
|
||||
deriving (Eq,Show)
|
||||
data FootForward
|
||||
= LeftForward
|
||||
| RightForward
|
||||
| WasLeftForward
|
||||
| WasRightForward
|
||||
deriving
|
||||
(Eq,Ord,Show)
|
||||
data Posture = Aiming | AtEase
|
||||
deriving (Eq,Ord,Show)
|
||||
deriving
|
||||
(Eq,Ord,Show)
|
||||
|
||||
makeLenses ''Stance
|
||||
makeLenses ''Carriage
|
||||
|
||||
@@ -2,6 +2,7 @@ module Dodge.Creature.State where
|
||||
import Dodge.Data
|
||||
import Dodge.Item.Data
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Creature.State.WalkCycle
|
||||
import Dodge.Creature.Stance.Data
|
||||
--import Dodge.Creature.Test
|
||||
import Dodge.Base
|
||||
@@ -98,9 +99,7 @@ movementSideEff cr w
|
||||
$ set randGen g
|
||||
w
|
||||
_ -> w
|
||||
| otherwise = case cr ^? crStance . carriage of
|
||||
Just (Walking x y) -> takeStep x y w
|
||||
_ -> w
|
||||
| otherwise = footstepSideEffect cr w
|
||||
where
|
||||
hasJetPack = any (\it -> it ^? itIdentity == Just JetPack) $ _crInv cr
|
||||
oldPos = _crOldPos cr
|
||||
@@ -111,11 +110,8 @@ movementSideEff cr w
|
||||
(randDir,g) = randomR (-0.5,0.5) $ _randGen w
|
||||
(randAng,_) = randomR (0,2*pi) $ _randGen w
|
||||
|
||||
crHasMoved = dist (_crPos cr) (_crOldPos cr) > 0.5
|
||||
takeStep x y | crHasMoved && x < 20 && x + y >= 20 = soundMultiFrom footor 22 3 0
|
||||
| crHasMoved && x < 80 && x + y >= 80 = soundMultiFrom footor 23 3 0
|
||||
| otherwise = id
|
||||
footor = [FootstepSound 0,FootstepSound 1]
|
||||
--crHasMoved = dist (_crPos cr) (_crOldPos cr) > 0.5
|
||||
|
||||
|
||||
invSideEff :: Creature -> World -> World
|
||||
invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr)
|
||||
@@ -136,12 +132,7 @@ weaponReloadSounds cr w = case _crInv cr IM.!? _crInvSel cr of
|
||||
updateMovement :: StdGen -> Creature -> (Creature, StdGen)
|
||||
updateMovement g cr
|
||||
| isFrictionless cr = (over crPos (+.+ momentum) $ setOldPos cr, g')
|
||||
| otherwise = case cr ^? crStance . carriage of
|
||||
Just (Walking x y)
|
||||
-> (set (crStance . carriage) (Walking ((x+y)`mod`120) 0) $ setOldPos cr
|
||||
, g)
|
||||
_ -> (set (crStance . carriage) (Walking 0 0) $ setOldPos cr
|
||||
, g)
|
||||
| otherwise = (updateWalkCycle $ setOldPos cr, g)
|
||||
where
|
||||
momentum' = 0.98 *.* (_crPos cr -.- _crOldPos cr)
|
||||
momentum'' | magV momentum' > 1 = 1 *.* normalizeV momentum'
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
module Dodge.Creature.State.WalkCycle
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Creature.Stance.Data
|
||||
import Dodge.SoundLogic
|
||||
|
||||
import Control.Lens
|
||||
|
||||
updateWalkCycle :: Creature -> Creature
|
||||
updateWalkCycle cr = case cr ^? crStance . carriage of
|
||||
Just (Walking x ff) | x > maxStride -> cr & crStance . carriage .~ Walking 0 (normalGait ff)
|
||||
_ -> cr
|
||||
where
|
||||
maxStride = _strideLength $ _crStance cr
|
||||
|
||||
normalGait :: FootForward -> FootForward
|
||||
normalGait LeftForward = WasLeftForward
|
||||
normalGait WasLeftForward = RightForward
|
||||
normalGait RightForward = WasRightForward
|
||||
normalGait 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
|
||||
where
|
||||
maxStride = _strideLength (_crStance cr)
|
||||
|
||||
|
||||
makeFootstepSound :: Int -> Int -> FootForward -> Point2 -> World -> World
|
||||
makeFootstepSound currentStride maxStride ff p
|
||||
| currentStride > maxStride = soundMultiFromPos footor (chooseFootSound ff) 3 0 p
|
||||
| otherwise = id
|
||||
where
|
||||
footor = [FootstepSound 0,FootstepSound 1]
|
||||
|
||||
chooseFootSound :: FootForward -> Int
|
||||
chooseFootSound LeftForward = 22
|
||||
chooseFootSound _ = 23
|
||||
@@ -13,7 +13,7 @@ import Geometry
|
||||
|
||||
import Control.Lens
|
||||
import qualified SDL
|
||||
import Data.Maybe
|
||||
--import Data.Maybe
|
||||
import qualified Data.Set as S
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import System.Random
|
||||
|
||||
Reference in New Issue
Block a user