Implement slowed down aim turning

This commit is contained in:
2023-01-08 11:10:42 +00:00
parent 44bb6e7e02
commit 05d081497d
11 changed files with 46 additions and 26 deletions
+9 -9
View File
@@ -1,5 +1,6 @@
module Dodge.Creature.Impulse.Movement where
import Dodge.Base
import Control.Lens
import Dodge.Creature.Statistics
import Dodge.Data.World
@@ -30,9 +31,9 @@ crMvAbsolute p' cr =
strengthFactor :: Int -> Float
strengthFactor i
| i > 9 = 1
| i > 50 = 1
| i < 1 = 0
| otherwise = 0.1 * fromIntegral i
| otherwise = 0.02 * fromIntegral i
crMvForward ::
-- | Speed
@@ -74,15 +75,14 @@ creatureTurnTowardDir ::
Creature ->
Creature
creatureTurnTowardDir a turnSpeed cr
| normalizeAngle (abs (a - cdir)) <= turnSpeed =
cr & crDir .~ dirToTarget
| isLeftOfA (normalizeAngle dirToTarget) (normalizeAngle $ _crDir cr) =
cr & crDir +~ turnSpeed
| otherwise = cr & crDir -~ turnSpeed
| abs (normalizeAnglePi (a - cdir)) <= turnSpeed = cr & crDir .~ dirToTarget
| otherwise = cr & crDir %~ addOrSub turnSpeed
where
addOrSub | isLeftOfA dirToTarget cdir = (+)
| otherwise = subtract
cdir = _crDir cr
vToTarg = rotateV a (V2 1 0)
dirToTarget = argV vToTarg
dirToTarget = argV $ rotateV a (V2 1 0)
creatureTurnToward :: Point2 -> Float -> Creature -> Creature
creatureTurnToward p turnSpeed cr
+8 -1
View File
@@ -2,6 +2,7 @@ module Dodge.Creature.YourControl (
yourControl,
) where
import Data.Maybe
import Data.Foldable
import qualified Data.Map.Strict as M
import Dodge.Base.Coordinate
@@ -38,7 +39,8 @@ wasdWithAiming ::
Creature ->
Creature
wasdWithAiming w speed cr
| isAiming = addAnyTwist $ set crDir mouseDir $ theMovement cr
-- | isAiming = addAnyTwist $ set crDir mouseDir $ theMovement cr
| isAiming = addAnyTwist $ aimTurn mouseDir $ theMovement cr
| crIsReloading cr && SDL.ButtonRight `M.member` _mouseButtons (_input w) =
addAnyTwist $ set crDir (mouseDir + anytwist) $ theMovement cr
| otherwise = theMovement $ theTurn $ removeTwist cr
@@ -64,6 +66,11 @@ wasdWithAiming w speed cr
Just _ -> argV $ mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- _crPos cr
_ -> argV (_mousePos (_input w)) + (w ^. cWorld . camPos . camRot)
aimTurn :: Float -> Creature -> Creature
aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr
where
x = fromMaybe 1 $ cr ^? crInv . ix (crSel cr) . itUse . heldAim . aimTurnSpeed
wasdM :: SDL.Scancode -> Point2
wasdM scancode = case scancode of
SDL.ScancodeW -> V2 0 1