Refactor, try to limit dependencies
This commit is contained in:
@@ -1,49 +1,53 @@
|
||||
module Dodge.Creature.YourControl
|
||||
( yourControl
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.LightSource
|
||||
module Dodge.Creature.YourControl (
|
||||
yourControl,
|
||||
) where
|
||||
|
||||
import qualified Data.Map.Strict as M
|
||||
import Dodge.Base.Coordinate
|
||||
import Dodge.Creature.Impulse.Movement
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Update.UsingInput
|
||||
import Dodge.Data.World
|
||||
import Dodge.InputFocus
|
||||
import Dodge.LightSource
|
||||
import Dodge.Update.UsingInput
|
||||
import Geometry
|
||||
import LensHelp
|
||||
|
||||
import qualified SDL
|
||||
import qualified Data.Map.Strict as M
|
||||
{- | The AI equivalent for your control. -}
|
||||
|
||||
-- | The AI equivalent for your control.
|
||||
yourControl :: Creature -> World -> World
|
||||
yourControl cr w
|
||||
yourControl cr w
|
||||
| inTermFocus w = dimCreatureLight cr w & updateUsingInput
|
||||
| otherwise = dimCreatureLight cr w
|
||||
& cWorld . creatures . ix (_crID cr) %~
|
||||
(wasdWithAiming w (_mvSpeed $ _crMvType cr) . mouseActionsCr (_mouseButtons w))
|
||||
& updateUsingInput
|
||||
| otherwise =
|
||||
dimCreatureLight cr w
|
||||
& cWorld . creatures . ix (_crID cr)
|
||||
%~ (wasdWithAiming w (_mvSpeed $ _crMvType cr) . mouseActionsCr (_mouseButtons w))
|
||||
& updateUsingInput
|
||||
|
||||
dimCreatureLight :: Creature -> World -> World
|
||||
dimCreatureLight cr = cWorld . tempLightSources .:~ tlsTimeRadColPos 1 300 0.1 (addZ 100 $ _crPos cr)
|
||||
|
||||
-- note the order of operation, setting the posture first--this prevents the twist fire bug
|
||||
|
||||
{- | Turn key presses into creature movement. -}
|
||||
wasdWithAiming
|
||||
:: World
|
||||
-> Float -- ^ Base speed
|
||||
-> Creature
|
||||
-> Creature
|
||||
-- | Turn key presses into creature movement.
|
||||
wasdWithAiming ::
|
||||
World ->
|
||||
-- | Base speed
|
||||
Float ->
|
||||
Creature ->
|
||||
Creature
|
||||
wasdWithAiming w speed cr
|
||||
| isAiming = addAnyTwist $ set crDir mouseDir $ theMovement cr
|
||||
| crIsReloading cr && SDL.ButtonRight `M.member` _mouseButtons w
|
||||
= addAnyTwist $ set crDir (mouseDir + anytwist) $ theMovement cr
|
||||
| isAiming = addAnyTwist $ set crDir mouseDir $ theMovement cr
|
||||
| crIsReloading cr && SDL.ButtonRight `M.member` _mouseButtons w =
|
||||
addAnyTwist $ set crDir (mouseDir + anytwist) $ theMovement cr
|
||||
| otherwise = theMovement $ theTurn $ removeTwist cr
|
||||
where
|
||||
where
|
||||
twistamount = 1.6
|
||||
removeTwist cr' = cr'
|
||||
& crDir +~ _crTwist cr'
|
||||
& crTwist .~ 0
|
||||
anytwist = case cr ^? crInv . ix (crSel cr) . itUse . useAim . aimStance of
|
||||
removeTwist cr' =
|
||||
cr'
|
||||
& crDir +~ _crTwist cr'
|
||||
& crTwist .~ 0
|
||||
anytwist = case cr ^? crInv . ix (crSel cr) . itUse . heldAim . aimStance of
|
||||
Just TwoHandTwist -> twistamount * pi
|
||||
_ -> 0
|
||||
addAnyTwist = crTwist .~ anytwist
|
||||
@@ -53,7 +57,7 @@ wasdWithAiming w speed cr
|
||||
theTurn cr' = creatureTurnTowardDir (_crMvDir cr') 0.2 cr'
|
||||
movDir = wasdDir w
|
||||
dir = _cameraRot (_cWorld w) + argV movDir
|
||||
movAbs = rotateV (_cameraRot (_cWorld w)) $ normalizeV movDir
|
||||
movAbs = rotateV (_cameraRot (_cWorld w)) $ normalizeV movDir
|
||||
isAiming = _posture (_crStance cr) == Aiming
|
||||
mouseDir = case cr ^? crInv . ix (crSel cr) . itScope . scopePos of
|
||||
Just _ -> argV $ mouseWorldPos w -.- _crPos cr
|
||||
@@ -61,20 +65,20 @@ wasdWithAiming w speed cr
|
||||
|
||||
wasdM :: SDL.Scancode -> Point2
|
||||
wasdM scancode = case scancode of
|
||||
SDL.ScancodeW -> V2 0 1
|
||||
SDL.ScancodeS -> V2 0 (-1)
|
||||
SDL.ScancodeD -> V2 1 0
|
||||
SDL.ScancodeA -> V2 (-1) 0
|
||||
_ -> V2 0 0
|
||||
SDL.ScancodeW -> V2 0 1
|
||||
SDL.ScancodeS -> V2 0 (-1)
|
||||
SDL.ScancodeD -> V2 1 0
|
||||
SDL.ScancodeA -> V2 (-1) 0
|
||||
_ -> V2 0 0
|
||||
|
||||
wasdDir :: World -> Point2
|
||||
wasdDir = foldr ((+.+) . wasdM) (V2 0 0) . _keys
|
||||
|
||||
{- | Set posture according to mouse presses. -}
|
||||
-- | Set posture according to mouse presses.
|
||||
mouseActionsCr :: M.Map SDL.MouseButton Bool -> Creature -> Creature
|
||||
mouseActionsCr pkeys cr
|
||||
| rbPressed && cr ^?! crInvSel . iselAction == NoInvSelAction
|
||||
= cr & crStance . posture .~ Aiming
|
||||
| rbPressed && cr ^?! crInvSel . iselAction == NoInvSelAction =
|
||||
cr & crStance . posture .~ Aiming
|
||||
| otherwise = cr & crStance . posture .~ AtEase
|
||||
where
|
||||
where
|
||||
rbPressed = SDL.ButtonRight `M.member` pkeys
|
||||
|
||||
Reference in New Issue
Block a user