Split up your control functions
This commit is contained in:
@@ -10,7 +10,6 @@ import Dodge.Base.Coordinate
|
||||
import Dodge.Base.You
|
||||
import Dodge.Creature.Impulse.Movement
|
||||
import Dodge.Creature.Impulse.UseItem
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Data.World
|
||||
import Dodge.Hotkey
|
||||
import Dodge.InputFocus
|
||||
@@ -95,20 +94,67 @@ tryAssignHotkey w sc = fromMaybe w $ do
|
||||
{- | Turn key presses into creature movement.
|
||||
| note the order of operation, setting the posture first--this prevents the twist fire bug
|
||||
-}
|
||||
--wasdWithAiming ::
|
||||
-- World ->
|
||||
-- -- | Base speed
|
||||
-- Float ->
|
||||
-- Creature ->
|
||||
-- Creature
|
||||
--wasdWithAiming w speed cr
|
||||
-- | isAiming = addAnyTwist $ aimTurn mouseDir $ theMovement $ setMvAim cr
|
||||
-- | crIsReloading cr && SDL.ButtonRight `M.member` _mouseButtons (_input w) =
|
||||
-- aimTurn mouseDir $ removeTwist $ theMovement $ setMvAim cr
|
||||
-- | otherwise = theMovement $ theTurn $ removeTwist $ setMvAim cr
|
||||
-- where
|
||||
-- setMvAim = maybe id (crMvAim .~) dir
|
||||
-- twistamount = 1.6
|
||||
-- removeTwist cr' =
|
||||
-- cr'
|
||||
-- & crDir +~ _crTwist cr'
|
||||
-- & crTwist .~ 0
|
||||
-- addAnyTwist = fromMaybe id $ do
|
||||
-- itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
-- astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
|
||||
-- case (astance, cr ^. crTwist) of
|
||||
-- (TwoHandUnder, 0) ->
|
||||
-- return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
|
||||
-- (TwoHandOver, 0) ->
|
||||
-- return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
|
||||
-- _ -> Nothing
|
||||
-- theMovement
|
||||
-- | movDir == V2 0 0 = id
|
||||
-- | otherwise = crMvAbsolute (speed *.* movAbs)
|
||||
-- theTurn cr' = creatureTurnTowardDir (_crMvAim cr') 0.2 cr'
|
||||
-- movDir = wasdDir (w ^. input)
|
||||
-- dir = fmap ((w ^. wCam . camRot) +) (safeArgV movDir)
|
||||
-- movAbs = rotateV (w ^. wCam . camRot) $ normalizeV movDir
|
||||
-- isAiming = _posture (_crStance cr) == Aiming
|
||||
-- mouseDir = argV $ mouseWorldPos (w ^. input) (w ^. wCam) - (cr ^. crPos)
|
||||
|
||||
wasdWithAiming ::
|
||||
World ->
|
||||
-- | Base speed
|
||||
Float ->
|
||||
Creature ->
|
||||
Creature
|
||||
wasdWithAiming w speed cr
|
||||
| isAiming = addAnyTwist $ aimTurn mouseDir $ theMovement $ setMvAim cr
|
||||
| crIsReloading cr && SDL.ButtonRight `M.member` _mouseButtons (_input w) =
|
||||
aimTurn mouseDir $ removeTwist $ theMovement $ setMvAim cr
|
||||
-- | otherwise = noaimmove $ theTurn $ removeTwist $ setMvAim cr
|
||||
| otherwise = theMovement $ theTurn $ removeTwist $ setMvAim cr
|
||||
wasdWithAiming w speed = wasdAim inp cam . wasdTwist . wasdMovement inp cam speed
|
||||
where
|
||||
inp = w ^. input
|
||||
cam = w ^. wCam
|
||||
|
||||
wasdAim :: Input -> Camera -> Creature -> Creature
|
||||
wasdAim inp cam cr
|
||||
| SDL.ButtonRight `M.member` _mouseButtons inp = aimTurn mouseDir cr
|
||||
| otherwise = theTurn cr
|
||||
where
|
||||
theTurn cr' = creatureTurnTowardDir (_crMvAim cr') 0.2 cr'
|
||||
mouseDir = argV $ mouseWorldPos inp cam - (cr ^. crPos)
|
||||
|
||||
wasdTwist :: Creature -> Creature
|
||||
wasdTwist cr
|
||||
| _posture (_crStance cr) == Aiming = addAnyTwist cr
|
||||
| otherwise = removeTwist cr
|
||||
where
|
||||
setMvAim = maybe id (crMvAim .~) dir
|
||||
twistamount = 1.6
|
||||
removeTwist cr' =
|
||||
cr'
|
||||
@@ -123,18 +169,19 @@ wasdWithAiming w speed cr
|
||||
(TwoHandOver, 0) ->
|
||||
return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
|
||||
_ -> Nothing
|
||||
|
||||
|
||||
wasdMovement :: Input -> Camera -> Float -> Creature -> Creature
|
||||
wasdMovement inp cam speed = theMovement . setMvAim
|
||||
where
|
||||
setMvAim = fromMaybe id $ do
|
||||
dir <- safeArgV movDir
|
||||
return $ crMvAim .~ (cam ^. camRot + dir)
|
||||
movDir = wasdDir inp
|
||||
movAbs = rotateV (cam ^. camRot) $ normalizeV movDir
|
||||
theMovement
|
||||
| movDir == V2 0 0 = id
|
||||
| otherwise = crMvAbsolute (speed *.* movAbs)
|
||||
noaimmove
|
||||
| movDir == V2 0 0 = id
|
||||
| otherwise = crMvForward speed
|
||||
theTurn cr' = creatureTurnTowardDir (_crMvAim cr') 0.2 cr'
|
||||
movDir = wasdDir (w ^. input)
|
||||
dir = fmap ((w ^. wCam . camRot) +) (safeArgV movDir)
|
||||
movAbs = rotateV (w ^. wCam . camRot) $ normalizeV movDir
|
||||
isAiming = _posture (_crStance cr) == Aiming
|
||||
mouseDir = argV $ mouseWorldPos (w ^. input) (w ^. wCam) - (cr ^. crPos)
|
||||
|
||||
aimTurn :: Float -> Creature -> Creature
|
||||
aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr
|
||||
|
||||
Reference in New Issue
Block a user