Cleanup, improve aiming code

This commit is contained in:
2025-05-31 15:28:30 +01:00
parent 3553ee5bbf
commit 8b07fffa7c
6 changed files with 107 additions and 93 deletions
-2
View File
@@ -33,14 +33,12 @@ useItemLoc ::
useItemLoc cr loc pt w
| HeldPlatformSF <- sf
, fromMaybe False $ loc ^? locLDT . ldtValue . _1 . itLocation . ilIsRoot
-- , cr ^. crStance . posture == Aiming =
, Aiming {} <- cr ^. crStance . posture =
return $ heldEffect pt (bimap _iatType (^. _1) ldt) cr w
| GadgetPlatformSF <- sf =
return $ gadgetEffect pt loc cr w
| UnderBarrelPlatformSF <- sf
, fromMaybe False $ loc ^? locLDT . ldtValue . _1 . itLocation . ilIsAttached
-- , cr ^. crStance . posture == Aiming =
, Aiming {} <- cr ^. crStance . posture =
return $ heldEffect pt (bimap _iatType (^. _1) ldt) cr w
| RemoteDetonatorSF <- sf
+4 -4
View File
@@ -119,11 +119,11 @@ wasdWithAiming w cr = wasdAim inp cam $ wasdMovement inp cam speed cr
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
| Just 0 <- inp ^? mouseButtons . ix SDL.ButtonRight
, Nothing <- inp ^? mouseButtons . ix SDL.ButtonLeft
= setAimPosture cr
| SDL.ButtonRight `M.member` _mouseButtons inp = aimTurn mouseDir cr
| Aiming <- cr ^. crStance . posture = removeAimPosture cr
| otherwise = creatureTurnTowardDir (_crMvAim cr) 0.2 cr
where
mouseDir = argV $ mouseWorldPos inp cam - (cr ^. crPos)
+1
View File
@@ -38,6 +38,7 @@ data MouseContext
| OverCombEscape
| OverTerminalReturn {_mcoTermID :: Int}
| OverTerminalEscape
| MouseGameRotate
deriving (Show)
data Input = Input
+10
View File
@@ -111,6 +111,7 @@ mouseCursorType u = case u ^. uvWorld . input . mouseContext of
OverCombEscape -> rotate (pi / 4) $ drawPlus 5
OverTerminalReturn{} -> drawReturn 5
OverTerminalEscape -> rotate (pi / 4) $ drawPlus 5
MouseGameRotate -> rotate a (drawVerticalDoubleArrow 5)
where
w = u ^. uvWorld
selsec = u ^? uvWorld . hud . hudElement . diSelection . _Just . _1
@@ -191,6 +192,15 @@ drawDrag x =
y = 0.5 * x
w = 0.3 * x
drawVerticalDoubleArrow :: Float -> Picture
drawVerticalDoubleArrow x =
line [V2 0 z, V2 0 (- z)]
<> line [V2 (- w) (z - w), V2 0 z, V2 w (z - w)]
<> line [V2 (- w) (w - z), V2 0 (- z), V2 w (w - z)]
where
z = 1.5 * x
w = 0.6 * x
drawDragDrop :: Float -> Picture
drawDragDrop x =
line (fmap (+ V2 z (- x)) [V2 (- x) x, V2 0 x, V2 0 (- x)])
+3
View File
@@ -327,6 +327,9 @@ updateMouseContextGame cfig u = case u ^. uvWorld . input . mouseContext of
where
w = u ^. uvWorld
aimcontext
| Just t1 <- w ^. input . mouseButtons . at ButtonLeft
, Just t2 <- w ^. input . mouseButtons . at ButtonRight
, t1 > t2 = MouseGameRotate
| ButtonRight `M.member` (w ^. input . mouseButtons) = MouseAiming
| otherwise = MouseInGame
mpos = w ^. input . mousePos