From 12c509a8b0481e4ff69c6686f8660629a510ad67 Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 26 Dec 2023 23:08:44 +0000 Subject: [PATCH] Split up your control functions --- src/Dodge/Creature/YourControl.hs | 81 ++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 17 deletions(-) diff --git a/src/Dodge/Creature/YourControl.hs b/src/Dodge/Creature/YourControl.hs index d173373a1..723705ee3 100644 --- a/src/Dodge/Creature/YourControl.hs +++ b/src/Dodge/Creature/YourControl.hs @@ -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