Implement slowed down aim turning
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
module Dodge.Creature.Impulse.Movement where
|
module Dodge.Creature.Impulse.Movement where
|
||||||
|
|
||||||
|
import Dodge.Base
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Dodge.Creature.Statistics
|
import Dodge.Creature.Statistics
|
||||||
import Dodge.Data.World
|
import Dodge.Data.World
|
||||||
@@ -30,9 +31,9 @@ crMvAbsolute p' cr =
|
|||||||
|
|
||||||
strengthFactor :: Int -> Float
|
strengthFactor :: Int -> Float
|
||||||
strengthFactor i
|
strengthFactor i
|
||||||
| i > 9 = 1
|
| i > 50 = 1
|
||||||
| i < 1 = 0
|
| i < 1 = 0
|
||||||
| otherwise = 0.1 * fromIntegral i
|
| otherwise = 0.02 * fromIntegral i
|
||||||
|
|
||||||
crMvForward ::
|
crMvForward ::
|
||||||
-- | Speed
|
-- | Speed
|
||||||
@@ -74,15 +75,14 @@ creatureTurnTowardDir ::
|
|||||||
Creature ->
|
Creature ->
|
||||||
Creature
|
Creature
|
||||||
creatureTurnTowardDir a turnSpeed cr
|
creatureTurnTowardDir a turnSpeed cr
|
||||||
| normalizeAngle (abs (a - cdir)) <= turnSpeed =
|
| abs (normalizeAnglePi (a - cdir)) <= turnSpeed = cr & crDir .~ dirToTarget
|
||||||
cr & crDir .~ dirToTarget
|
| otherwise = cr & crDir %~ addOrSub turnSpeed
|
||||||
| isLeftOfA (normalizeAngle dirToTarget) (normalizeAngle $ _crDir cr) =
|
|
||||||
cr & crDir +~ turnSpeed
|
|
||||||
| otherwise = cr & crDir -~ turnSpeed
|
|
||||||
where
|
where
|
||||||
|
addOrSub | isLeftOfA dirToTarget cdir = (+)
|
||||||
|
| otherwise = subtract
|
||||||
cdir = _crDir cr
|
cdir = _crDir cr
|
||||||
vToTarg = rotateV a (V2 1 0)
|
dirToTarget = argV $ rotateV a (V2 1 0)
|
||||||
dirToTarget = argV vToTarg
|
|
||||||
|
|
||||||
creatureTurnToward :: Point2 -> Float -> Creature -> Creature
|
creatureTurnToward :: Point2 -> Float -> Creature -> Creature
|
||||||
creatureTurnToward p turnSpeed cr
|
creatureTurnToward p turnSpeed cr
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ module Dodge.Creature.YourControl (
|
|||||||
yourControl,
|
yourControl,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Data.Maybe
|
||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
import Dodge.Base.Coordinate
|
import Dodge.Base.Coordinate
|
||||||
@@ -38,7 +39,8 @@ wasdWithAiming ::
|
|||||||
Creature ->
|
Creature ->
|
||||||
Creature
|
Creature
|
||||||
wasdWithAiming w speed cr
|
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) =
|
| crIsReloading cr && SDL.ButtonRight `M.member` _mouseButtons (_input w) =
|
||||||
addAnyTwist $ set crDir (mouseDir + anytwist) $ theMovement cr
|
addAnyTwist $ set crDir (mouseDir + anytwist) $ theMovement cr
|
||||||
| otherwise = theMovement $ theTurn $ removeTwist cr
|
| otherwise = theMovement $ theTurn $ removeTwist cr
|
||||||
@@ -64,6 +66,11 @@ wasdWithAiming w speed cr
|
|||||||
Just _ -> argV $ mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- _crPos cr
|
Just _ -> argV $ mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- _crPos cr
|
||||||
_ -> argV (_mousePos (_input w)) + (w ^. cWorld . camPos . camRot)
|
_ -> 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 :: SDL.Scancode -> Point2
|
||||||
wasdM scancode = case scancode of
|
wasdM scancode = case scancode of
|
||||||
SDL.ScancodeW -> V2 0 1
|
SDL.ScancodeW -> V2 0 1
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ data ItemUse
|
|||||||
|
|
||||||
data AimParams = AimParams
|
data AimParams = AimParams
|
||||||
{ _aimWeight :: Int
|
{ _aimWeight :: Int
|
||||||
|
, _aimTurnSpeed :: Float
|
||||||
, _aimRange :: Float
|
, _aimRange :: Float
|
||||||
, _aimZoom :: ItZoom
|
, _aimZoom :: ItZoom
|
||||||
, _aimStance :: AimStance
|
, _aimStance :: AimStance
|
||||||
|
|||||||
@@ -42,7 +42,18 @@ applyTerminalCommandArguments command args u = case command of
|
|||||||
"ITEM" -> fromMaybe u $ do
|
"ITEM" -> fromMaybe u $ do
|
||||||
(ibt, n) <- parseItem args
|
(ibt, n) <- parseItem args
|
||||||
return $ u & uvWorld %~ flip (foldr ($)) (replicate n (snd . createPutItem (itemFromBase ibt)))
|
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
|
_ -> u
|
||||||
|
where
|
||||||
|
ypoint = uvWorld . cWorld . lWorld . creatures . ix 0
|
||||||
|
|
||||||
parseItem :: [String] -> Maybe (ItemBaseType, Int)
|
parseItem :: [String] -> Maybe (ItemBaseType, Int)
|
||||||
parseItem (x : xs) =
|
parseItem (x : xs) =
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ defaultCreature =
|
|||||||
, _crMvType = defaultAimMvType
|
, _crMvType = defaultAimMvType
|
||||||
, _crHammerPosition = HammerUp
|
, _crHammerPosition = HammerUp
|
||||||
, _crName = "DEFAULTCRNAME"
|
, _crName = "DEFAULTCRNAME"
|
||||||
, _crStatistics = CreatureStatistics 10 10 10
|
, _crStatistics = CreatureStatistics 50 50 50
|
||||||
, _crCamouflage = FullyVisible
|
, _crCamouflage = FullyVisible
|
||||||
, _crTargeting = defaultCreatureTargeting
|
, _crTargeting = defaultCreatureTargeting
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ defaultAimParams :: AimParams
|
|||||||
defaultAimParams =
|
defaultAimParams =
|
||||||
AimParams
|
AimParams
|
||||||
{ _aimWeight = 0
|
{ _aimWeight = 0
|
||||||
|
, _aimTurnSpeed = 1
|
||||||
, _aimRange = 0
|
, _aimRange = 0
|
||||||
, _aimZoom = ItZoom 20 0.2 1
|
, _aimZoom = ItZoom 20 0.2 1
|
||||||
, _aimStance = OneHand
|
, _aimStance = OneHand
|
||||||
|
|||||||
@@ -250,9 +250,6 @@ setEquipAllocation w = case _rbOptions w of
|
|||||||
}
|
}
|
||||||
_ -> w
|
_ -> w
|
||||||
|
|
||||||
-- where
|
|
||||||
-- curpos = invSelPos w
|
|
||||||
|
|
||||||
setEquipActivation :: World -> World
|
setEquipActivation :: World -> World
|
||||||
setEquipActivation w = case w ^? rbOptions . opAllocateEquipment of
|
setEquipActivation w = case w ^? rbOptions . opAllocateEquipment of
|
||||||
Just DoNotMoveEquipment -> w
|
Just DoNotMoveEquipment -> w
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ miniGunX :: Int -> Item
|
|||||||
miniGunX i =
|
miniGunX i =
|
||||||
autoRifle
|
autoRifle
|
||||||
& itUse .~ miniGunUse i
|
& itUse .~ miniGunUse i
|
||||||
|
& itUse . heldAim . aimTurnSpeed .~ 0.5
|
||||||
& itParams
|
& itParams
|
||||||
.~ BulletShooter
|
.~ BulletShooter
|
||||||
{ _muzVel = 1
|
{ _muzVel = 1
|
||||||
|
|||||||
@@ -10,15 +10,11 @@ flatShield :: Item
|
|||||||
flatShield =
|
flatShield =
|
||||||
defaultHeldItem
|
defaultHeldItem
|
||||||
& itEffect . ieInv .~ EffectIfHeld CreateShieldWall RemoveShieldWall
|
& itEffect . ieInv .~ EffectIfHeld CreateShieldWall RemoveShieldWall
|
||||||
& itUse . heldAim
|
& itUse . heldAim . aimWeight .~ 5
|
||||||
.~ AimParams
|
& itUse . heldAim . aimTurnSpeed .~ 0.5
|
||||||
{ _aimWeight = 5
|
& itUse . heldAim . aimStance .~ TwoHandFlat
|
||||||
, _aimRange = 0
|
& itUse . heldAim . aimHandlePos .~ 0
|
||||||
, _aimZoom = ItZoom 20 0.2 1
|
& itUse . heldAim . aimMuzPos .~ 0
|
||||||
, _aimStance = TwoHandFlat
|
|
||||||
, _aimHandlePos = 0
|
|
||||||
, _aimMuzPos = 0
|
|
||||||
}
|
|
||||||
& itInvSize .~ 3
|
& itInvSize .~ 3
|
||||||
& itType . iyBase .~ HELD FLATSHIELD
|
& itType . iyBase .~ HELD FLATSHIELD
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -335,7 +335,12 @@ menuWheelStep i u = fromMaybe u $ do
|
|||||||
-- where
|
-- where
|
||||||
-- y = w ^. input . scrollAmount
|
-- y = w ^. input . scrollAmount
|
||||||
updateWheelEvents :: World -> World
|
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 :: Universe -> Universe
|
||||||
advanceScrollAmount u =
|
advanceScrollAmount u =
|
||||||
|
|||||||
+3
-2
@@ -168,8 +168,9 @@ nRaysRad n x = take n $ iterate (rotateV (2*pi/fromIntegral n)) (V2 x 0)
|
|||||||
-- smallest change in rotation between them.
|
-- smallest change in rotation between them.
|
||||||
-- This appears to sometimes fail if the angles are not normalized.
|
-- This appears to sometimes fail if the angles are not normalized.
|
||||||
isLeftOfA :: Float -> Float -> Bool
|
isLeftOfA :: Float -> Float -> Bool
|
||||||
isLeftOfA angle1 angle2 = (angle1 - angle2 < pi && angle1 > angle2)
|
--isLeftOfA angle1 angle2 = (angle1 - angle2 < pi && angle1 > angle2)
|
||||||
|| (angle2 - angle1 > pi && angle2 > angle1)
|
-- || (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
|
-- | Test whether a vector is to the left of another, according to the smallest
|
||||||
-- change of rotation between them.
|
-- change of rotation between them.
|
||||||
isLeftOf :: Point2 -> Point2 -> Bool
|
isLeftOf :: Point2 -> Point2 -> Bool
|
||||||
|
|||||||
Reference in New Issue
Block a user