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
+1
View File
@@ -57,6 +57,7 @@ data ItemUse
data AimParams = AimParams
{ _aimWeight :: Int
, _aimTurnSpeed :: Float
, _aimRange :: Float
, _aimZoom :: ItZoom
, _aimStance :: AimStance
+11
View File
@@ -42,7 +42,18 @@ applyTerminalCommandArguments command args u = case command of
"ITEM" -> fromMaybe u $ do
(ibt, n) <- parseItem args
return $ u & uvWorld %~ flip (foldr ($)) (replicate n (snd . createPutItem (itemFromBase ibt)))
"DEX" -> fromMaybe u $ do
x <- readMaybe =<< args ^? _head
return $ u & ypoint . crStatistics . dexterity .~ x
"STR" -> fromMaybe u $ do
x <- readMaybe =<< args ^? _head
return $ u & ypoint . crStatistics . strength .~ x
"INT" -> fromMaybe u $ do
x <- readMaybe =<< args ^? _head
return $ u & ypoint . crStatistics . intelligence .~ x
_ -> u
where
ypoint = uvWorld . cWorld . lWorld . creatures . ix 0
parseItem :: [String] -> Maybe (ItemBaseType, Int)
parseItem (x : xs) =
+1 -1
View File
@@ -52,7 +52,7 @@ defaultCreature =
, _crMvType = defaultAimMvType
, _crHammerPosition = HammerUp
, _crName = "DEFAULTCRNAME"
, _crStatistics = CreatureStatistics 10 10 10
, _crStatistics = CreatureStatistics 50 50 50
, _crCamouflage = FullyVisible
, _crTargeting = defaultCreatureTargeting
}
+1
View File
@@ -6,6 +6,7 @@ defaultAimParams :: AimParams
defaultAimParams =
AimParams
{ _aimWeight = 0
, _aimTurnSpeed = 1
, _aimRange = 0
, _aimZoom = ItZoom 20 0.2 1
, _aimStance = OneHand
-3
View File
@@ -250,9 +250,6 @@ setEquipAllocation w = case _rbOptions w of
}
_ -> w
-- where
-- curpos = invSelPos w
setEquipActivation :: World -> World
setEquipActivation w = case w ^? rbOptions . opAllocateEquipment of
Just DoNotMoveEquipment -> w
+1
View File
@@ -131,6 +131,7 @@ miniGunX :: Int -> Item
miniGunX i =
autoRifle
& itUse .~ miniGunUse i
& itUse . heldAim . aimTurnSpeed .~ 0.5
& itParams
.~ BulletShooter
{ _muzVel = 1
+5 -9
View File
@@ -10,15 +10,11 @@ flatShield :: Item
flatShield =
defaultHeldItem
& itEffect . ieInv .~ EffectIfHeld CreateShieldWall RemoveShieldWall
& itUse . heldAim
.~ AimParams
{ _aimWeight = 5
, _aimRange = 0
, _aimZoom = ItZoom 20 0.2 1
, _aimStance = TwoHandFlat
, _aimHandlePos = 0
, _aimMuzPos = 0
}
& itUse . heldAim . aimWeight .~ 5
& itUse . heldAim . aimTurnSpeed .~ 0.5
& itUse . heldAim . aimStance .~ TwoHandFlat
& itUse . heldAim . aimHandlePos .~ 0
& itUse . heldAim . aimMuzPos .~ 0
& itInvSize .~ 3
& itType . iyBase .~ HELD FLATSHIELD
+6 -1
View File
@@ -335,7 +335,12 @@ menuWheelStep i u = fromMaybe u $ do
-- where
-- y = w ^. input . scrollAmount
updateWheelEvents :: World -> World
updateWheelEvents w = updateWheelEvent (w ^. input . scrollAmount) w
updateWheelEvents w
| yi == 0 = w
| otherwise = updateWheelEvent yi w
where
yi = w ^. input . scrollAmount
advanceScrollAmount :: Universe -> Universe
advanceScrollAmount u =
+3 -2
View File
@@ -168,8 +168,9 @@ nRaysRad n x = take n $ iterate (rotateV (2*pi/fromIntegral n)) (V2 x 0)
-- smallest change in rotation between them.
-- This appears to sometimes fail if the angles are not normalized.
isLeftOfA :: Float -> Float -> Bool
isLeftOfA angle1 angle2 = (angle1 - angle2 < pi && angle1 > angle2)
|| (angle2 - angle1 > pi && angle2 > angle1)
--isLeftOfA angle1 angle2 = (angle1 - angle2 < pi && angle1 > angle2)
-- || (angle2 - angle1 > pi && angle2 > angle1)
isLeftOfA angle1 angle2 = normalizeAngle (angle1 - angle2) < pi
-- | Test whether a vector is to the left of another, according to the smallest
-- change of rotation between them.
isLeftOf :: Point2 -> Point2 -> Bool