Tweak movement
This commit is contained in:
@@ -33,19 +33,17 @@ wasdWithAiming
|
||||
-> Creature
|
||||
-> Creature
|
||||
wasdWithAiming w speed i cr
|
||||
| isAiming = set crDir mouseDir $ crMvBy (speed *.* mov) cr
|
||||
| isMoving = crMvAbsolute (speed *.* movAbs) $ turnAction cr
|
||||
-- | isMoving = crMvAbsolute (speed *.* movAbs) cr
|
||||
-- | isMoving = crMvForward speed $ over crDir (`fromMaybe` dir) cr
|
||||
| otherwise = cr
|
||||
| isAiming = set crDir mouseDir $ theMovement cr
|
||||
| otherwise = theTurn $ theMovement cr
|
||||
where
|
||||
(mov',dir') = wasdComp (view keys w) w
|
||||
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'
|
||||
isAiming = _posture (_crStance cr) == Aiming
|
||||
isMoving = mov' /= (0,0)
|
||||
theMovement
|
||||
| movDir == (0,0) = id
|
||||
| otherwise = crMvAbsolute (speed *.* movAbs) . set crMvDir dir
|
||||
theTurn cr' = creatureTurnTowardDir (_crMvDir cr') 0.2 cr'
|
||||
movDir = wasdDir w
|
||||
dir = _cameraRot w + argV movDir
|
||||
movAbs = rotateV (_cameraRot w) $ normalizeV movDir
|
||||
isAiming = _posture (_crStance cr) == Aiming
|
||||
mouseDir = case w ^? creatures . ix i . crInv . ix (_crInvSel (_creatures w IM.! i))
|
||||
. itAttachment of
|
||||
Just (Just ItScope{_scopePos = p}) -> normalizeAngle $ argV
|
||||
@@ -61,6 +59,9 @@ wasdM w scancode
|
||||
| scancode == moveLeftKey (_keyConfig w) = (-1, 0)
|
||||
wasdM _ _ = (0,0)
|
||||
|
||||
wasdDir :: World -> Point2
|
||||
wasdDir w = foldr ((+.+) . wasdM w) (0,0) $ _keys w
|
||||
|
||||
wasdComp :: S.Set SDL.Scancode -> World -> (Point2,Maybe Float)
|
||||
wasdComp ks w = f $ foldr ( (+.+) . wasdM w ) (0,0) ks
|
||||
where
|
||||
|
||||
@@ -22,7 +22,7 @@ pictureWeaponOnAim p cr posInInv
|
||||
| isSelected && _posture (_crStance cr) == Aiming
|
||||
= onLayer PtLayer drawnWep
|
||||
| isSelected && isOneHand
|
||||
= onLayerL [levLayer CrLayer, -3] holsteredOneHandWep
|
||||
= onLayerL [levLayer CrLayer, -5] holsteredOneHandWep
|
||||
| isSelected
|
||||
= onLayerL [levLayer CrLayer, -3] holsteredWep
|
||||
| otherwise = blank
|
||||
|
||||
@@ -9,6 +9,8 @@ import Dodge.Render.MenuScreen
|
||||
import Geometry
|
||||
import Picture
|
||||
|
||||
--import Dodge.Creature.YourControl
|
||||
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
@@ -47,7 +49,7 @@ customMouseCursor w =
|
||||
testPic :: World -> [Picture]
|
||||
testPic w =
|
||||
[ setDepth (-1) . translate 0 0.8
|
||||
. scale 0.001 0.001 . text . show $ _cameraRot w
|
||||
. scale 0.001 0.001 . text . show $ _crMvDir $ you w
|
||||
]
|
||||
|
||||
crDraw :: World -> Creature -> Picture
|
||||
|
||||
@@ -72,11 +72,13 @@ normalizeV p = (1 / magV p) *.* p
|
||||
{- | Angle between two vectors. Always positive. -}
|
||||
angleVV :: Point2 -> Point2 -> Float
|
||||
{-# INLINE angleVV #-}
|
||||
angleVV a b =
|
||||
let ma = magV a
|
||||
mb = magV b
|
||||
d = a `dotV` b
|
||||
in acos $ d / (ma * mb)
|
||||
angleVV a b
|
||||
| a == b = 0
|
||||
| otherwise =
|
||||
let ma = magV a
|
||||
mb = magV b
|
||||
d = a `dotV` b
|
||||
in acos $ d / (ma * mb)
|
||||
{- | Safe version of 'angleVV' that returns 0 if either vector is null. -}
|
||||
safeAngleVV :: Point2 -> Point2 -> Float
|
||||
{-# INLINE safeAngleVV #-}
|
||||
|
||||
Reference in New Issue
Block a user