Remove _crTwist

This commit is contained in:
2025-05-30 10:23:37 +01:00
parent 3efa01bf09
commit 0bcf263db7
14 changed files with 304 additions and 259 deletions
+51 -19
View File
@@ -28,7 +28,8 @@ yourControl _ w
, f x =
w
& cWorld . lWorld . creatures . ix 0
%~ (wasdWithAiming w . setCrPosture pkeys)
-- %~ (wasdWithAiming w . setCrPosture pkeys)
%~ wasdWithAiming w
& tryClickUse pkeys
& handleHotkeys
| otherwise =
@@ -115,7 +116,8 @@ wasdWithAiming ::
World ->
Creature ->
Creature
wasdWithAiming w cr = wasdAim inp cam . wasdTwist $ wasdMovement inp cam speed cr
--wasdWithAiming w cr = wasdAim inp cam . wasdTwist $ wasdMovement inp cam speed cr
wasdWithAiming w cr = wasdAim inp cam $ wasdMovement inp cam speed cr
where
speed = _mvSpeed $ _crMvType cr
inp = w ^. input
@@ -123,29 +125,59 @@ wasdWithAiming w cr = wasdAim inp cam . wasdTwist $ wasdMovement inp cam speed c
wasdAim :: Input -> Camera -> Creature -> Creature
wasdAim inp cam cr
| Just 0 <- inp ^? mouseButtons . ix SDL.ButtonRight
= setAimPosture cr
| Just 0 <- inp ^? mouseButtonsReleased . ix SDL.ButtonRight
= removeAimPosture cr
| SDL.ButtonRight `M.member` _mouseButtons inp = aimTurn mouseDir cr
| otherwise = creatureTurnTowardDir (_crMvAim cr) 0.2 cr
where
mouseDir = argV $ mouseWorldPos inp cam - (cr ^. crPos)
-- aim with the root item
wasdTwist :: Creature -> Creature
wasdTwist cr
| _posture (_crStance cr) == Aiming = fromMaybe cr $ do
itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
case (astance, cr ^. crTwist) of
(TwoHandUnder, 0) ->
return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
(TwoHandOver, 0) ->
return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
_ -> Nothing
| otherwise =
cr
& crDir +~ _crTwist cr
& crTwist .~ 0 --remove twistk
---- aim with the root item
---- when initiating aim with a two handed weapon, change the creature direction
---- to be closer to where the two handed weapon was pointing
--wasdTwist :: Creature -> Creature
--wasdTwist cr
---- | _posture (_crStance cr) == Aiming
-- | Aiming {} <- cr ^. crStance . posture = fromMaybe cr $ do
-- itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
-- astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
-- case (astance, cr ^. crTwist) of
-- (TwoHandUnder, 0) ->
-- return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
-- (TwoHandOver, 0) ->
-- return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
-- _ -> Nothing
-- | otherwise =
-- cr
-- & crDir +~ _crTwist cr
-- & crTwist .~ 0 --remove twistk
-- where
-- twistamount = 1.6
setAimPosture :: Creature -> Creature
setAimPosture cr = fromMaybe cr $ do
itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
case astance of
TwoHandUnder ->
return $ cr & crStance . posture .~ Aiming (twistamount * pi)
& crDir -~ (twistamount * pi)
TwoHandOver ->
return $ cr & crStance . posture .~ Aiming (twistamount * pi)
& crDir -~ (twistamount * pi)
_ -> return $ cr & crStance . posture .~ Aiming 0
where
twistamount :: Float
twistamount = 1.6
removeAimPosture :: Creature -> Creature
removeAimPosture cr = fromMaybe cr $ do
x <- cr ^? crStance . posture . aimTwist
return $ cr
& crDir +~ x
& crStance . posture .~ AtEase
wasdMovement :: Input -> Camera -> Float -> Creature -> Creature
wasdMovement inp cam speed = theMovement . setMvAim
@@ -171,7 +203,7 @@ aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr
-}
setCrPosture :: M.Map SDL.MouseButton Int -> Creature -> Creature
setCrPosture pkeys
| SDL.ButtonRight `M.member` pkeys = crStance . posture .~ Aiming
| SDL.ButtonRight `M.member` pkeys = crStance . posture .~ Aiming 0
| otherwise = crStance . posture .~ AtEase
tryClickUse :: M.Map SDL.MouseButton Int -> World -> World