Slow your turn when moving and not aiming
This commit is contained in:
@@ -8,12 +8,11 @@ import Geometry
|
|||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import qualified Data.IntMap.Strict as IM
|
import qualified Data.IntMap.Strict as IM
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
|
|
||||||
{- | Creature attempts to moves under its own steam.
|
{- | Creature attempts to moves under its own steam.
|
||||||
The idea is that this may or may not work, depending on the status of the creature.
|
The idea is that this may or may not work, depending on the status of the creature.
|
||||||
For now, though, this cannot fail. -}
|
For now, though, this cannot fail. -}
|
||||||
crMvBy
|
crMvBy
|
||||||
:: Point2 -- ^ Movement translation vector
|
:: Point2 -- ^ Movement translation vector, will be made relative to creature direction
|
||||||
-> Creature
|
-> Creature
|
||||||
-> Creature
|
-> Creature
|
||||||
crMvBy p' cr = advanceStepCounter (magV p) $ over crPos (+.+ p) cr
|
crMvBy p' cr = advanceStepCounter (magV p) $ over crPos (+.+ p) cr
|
||||||
@@ -28,6 +27,22 @@ crMvBy p' cr = advanceStepCounter (magV p) $ over crPos (+.+ p) cr
|
|||||||
| otherwise = 1
|
| otherwise = 1
|
||||||
it = _crInv cr IM.! _crInvSel cr
|
it = _crInv cr IM.! _crInvSel cr
|
||||||
|
|
||||||
|
crMvAbsolute
|
||||||
|
:: Point2 -- ^ Movement translation vector
|
||||||
|
-> Creature
|
||||||
|
-> Creature
|
||||||
|
crMvAbsolute p' cr = advanceStepCounter (magV p) $ over crPos (+.+ p) cr
|
||||||
|
where
|
||||||
|
p = (*.*) (equipFactor * aimingFactor) p'
|
||||||
|
equipFactor
|
||||||
|
| _posture (_crStance cr) == Aiming
|
||||||
|
= product $ map equipAimSpeed $ IM.elems $ _crInv cr
|
||||||
|
| otherwise = product $ map equipSpeed $ IM.elems $ _crInv cr
|
||||||
|
aimingFactor
|
||||||
|
| _posture (_crStance cr) == Aiming = fromMaybe 1 $ it ^? itAimingSpeed
|
||||||
|
| otherwise = 1
|
||||||
|
it = _crInv cr IM.! _crInvSel cr
|
||||||
|
|
||||||
crMvForward
|
crMvForward
|
||||||
:: Float -- ^ Speed
|
:: Float -- ^ Speed
|
||||||
-> Creature
|
-> Creature
|
||||||
@@ -46,6 +61,7 @@ advanceStepCounter speed = crStance . carriage %~ f
|
|||||||
creatureTurn :: Float -> Creature -> Creature
|
creatureTurn :: Float -> Creature -> Creature
|
||||||
creatureTurn a = crDir +~ a
|
creatureTurn a = crDir +~ a
|
||||||
|
|
||||||
|
|
||||||
creatureTurnTo :: Point2 -> Creature -> Creature
|
creatureTurnTo :: Point2 -> Creature -> Creature
|
||||||
creatureTurnTo p cr
|
creatureTurnTo p cr
|
||||||
| vToTarg == (0,0) = cr -- this should deal with the angleVV error
|
| vToTarg == (0,0) = cr -- this should deal with the angleVV error
|
||||||
@@ -54,6 +70,21 @@ creatureTurnTo p cr
|
|||||||
vToTarg = p -.- _crPos cr
|
vToTarg = p -.- _crPos cr
|
||||||
dirToTarget = argV vToTarg
|
dirToTarget = argV vToTarg
|
||||||
|
|
||||||
|
creatureTurnTowardDir
|
||||||
|
:: Float -- ^ Angle
|
||||||
|
-> Float -- ^ Turn speed
|
||||||
|
-> Creature
|
||||||
|
-> Creature
|
||||||
|
creatureTurnTowardDir a turnSpeed cr
|
||||||
|
| vToTarg == (0,0) = cr -- this should deal with the angleVV error
|
||||||
|
| errorAngleVV 3 vToTarg (unitVectorAtAngle (_crDir cr)) <= turnSpeed
|
||||||
|
= cr & crDir .~ dirToTarget
|
||||||
|
| isLeftOfA (normalizeAngle dirToTarget) (normalizeAngle $ _crDir cr) = cr & crDir +~ turnSpeed
|
||||||
|
| otherwise = cr & crDir -~ turnSpeed
|
||||||
|
where
|
||||||
|
vToTarg = rotateV a (1,0)
|
||||||
|
dirToTarget = argV vToTarg
|
||||||
|
|
||||||
creatureTurnToward :: Point2 -> Float -> Creature -> Creature
|
creatureTurnToward :: Point2 -> Float -> Creature -> Creature
|
||||||
creatureTurnToward p turnSpeed cr
|
creatureTurnToward p turnSpeed cr
|
||||||
| vToTarg == (0,0) = cr -- this should deal with the angleVV error
|
| vToTarg == (0,0) = cr -- this should deal with the angleVV error
|
||||||
|
|||||||
@@ -34,11 +34,14 @@ wasdWithAiming
|
|||||||
-> Creature
|
-> Creature
|
||||||
wasdWithAiming w speed i cr
|
wasdWithAiming w speed i cr
|
||||||
| isAiming = set crDir mouseDir $ crMvBy (speed *.* mov) cr
|
| isAiming = set crDir mouseDir $ crMvBy (speed *.* mov) cr
|
||||||
| isMoving = crMvForward speed $ over crDir (`fromMaybe` dir) cr
|
| isMoving = crMvAbsolute (speed *.* movAbs) $ turnAction cr
|
||||||
|
-- | isMoving = crMvForward speed $ over crDir (`fromMaybe` dir) cr
|
||||||
| otherwise = cr
|
| otherwise = cr
|
||||||
where
|
where
|
||||||
(mov',dir') = wasdComp (view keys w) w
|
(mov',dir') = wasdComp (view keys w) w
|
||||||
dir = fmap (_cameraRot w +) dir'
|
dir = fmap (_cameraRot w +) dir'
|
||||||
|
turnAction cr' = maybe cr (\d -> creatureTurnTowardDir d 0.2 cr') dir
|
||||||
|
movAbs = rotateV (_cameraRot w) mov'
|
||||||
mov = rotateV (negate $ _crDir cr - _cameraRot w) mov'
|
mov = rotateV (negate $ _crDir cr - _cameraRot w) mov'
|
||||||
isAiming = _posture (_crStance cr) == Aiming
|
isAiming = _posture (_crStance cr) == Aiming
|
||||||
isMoving = mov' /= (0,0)
|
isMoving = mov' /= (0,0)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import Control.Monad.State
|
|||||||
import Data.List
|
import Data.List
|
||||||
--import Data.Maybe
|
--import Data.Maybe
|
||||||
import System.Random
|
import System.Random
|
||||||
import qualified Data.IntMap.Strict as IM
|
--import qualified Data.IntMap.Strict as IM
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
|
|
||||||
makePoisonExplosionAt
|
makePoisonExplosionAt
|
||||||
@@ -36,7 +36,7 @@ makeTeslaExplosionAt
|
|||||||
:: Point2 -- ^ Position
|
:: Point2 -- ^ Position
|
||||||
-> World
|
-> World
|
||||||
-> World
|
-> World
|
||||||
makeTeslaExplosionAt pos w = undefined
|
makeTeslaExplosionAt pos w = undefined pos w
|
||||||
-- soundOncePos grenadeBang pos $ foldr ($) w listOfFunctions -- a bit shorter
|
-- soundOncePos grenadeBang pos $ foldr ($) w listOfFunctions -- a bit shorter
|
||||||
-- where
|
-- where
|
||||||
-- xs = randomRs (0, 2*pi) $ _randGen w
|
-- xs = randomRs (0, 2*pi) $ _randGen w
|
||||||
|
|||||||
Reference in New Issue
Block a user