Cleanup launchers

This commit is contained in:
2022-03-02 08:36:16 +00:00
parent b3ba0697b4
commit be1fda266a
7 changed files with 44 additions and 60 deletions
+3
View File
@@ -100,6 +100,9 @@ allWalls = IM.unions . concatMap IM.elems . IM.elems . _znObjects . _wallsZone
creatureNearPoint :: Point2 -> World -> Maybe Creature
creatureNearPoint p = L.fold (L.minimumOn (dist p . _crPos)) . creaturesNearPoint p
creatureNearPointI :: Int -> Point2 -> World -> Maybe Creature
creatureNearPointI n p = L.fold (L.minimumOn (dist p . _crPos)) . creaturesNearPointI n p
creaturesNearPoint :: Point2 -> World -> IM.IntMap Creature
creaturesNearPoint p w = IM.unions
[f b $ f a $ _znObjects $ _creaturesZone w | a<-[x-1,x,x+1] , b<-[y-1,y,y+1]]
+1 -1
View File
@@ -42,7 +42,7 @@ followImpulse cr w imp = case imp of
TurnToward p a -> crup $ creatureTurnToward p a cr
TurnTo p -> crup $ creatureTurnTo p cr
ChangePosture post -> crup $ cr & crStance . posture .~ post
UseItem -> (tryUseItem cr, cr)
UseItem -> (useItem cr, cr)
SwitchToItem i -> crup $ cr & crInvSel .~ i
Melee cid' -> (hitCr cid'
, crMvBy (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20)
+3 -3
View File
@@ -1,5 +1,5 @@
module Dodge.Creature.Impulse.UseItem
( tryUseItem
( useItem
, useLeftItem
) where
import Dodge.Data
@@ -9,8 +9,8 @@ import qualified Data.IntMap.Strict as IM
import Control.Lens
import Data.Maybe
tryUseItem :: Creature -> World -> World
tryUseItem cr' w = fromMaybe w $ do
useItem :: Creature -> World -> World
useItem cr' w = fromMaybe w $ do
cr <- w ^? creatures . ix (_crID cr')
it <- cr ^? crInv . ix (_crInvSel cr)
return $ itemEffect cr it w
+3 -2
View File
@@ -154,9 +154,10 @@ targetRBPressUpdate _ _ w t
targetRBCreatureUpdate :: Item -> Creature -> World -> Targeting -> Targeting
targetRBCreatureUpdate _ _ w t
| SDL.ButtonRight `S.member` _mouseButtons w = t & updatePos
| SDL.ButtonRight `S.member` _mouseButtons w && isJust (t ^? tgID . _Just)
= t & updatePos
& tgActive .~ True
| otherwise = t & tgID .~ fmap _crID (creatureNearPoint mwp w)
| otherwise = t & tgID .~ fmap _crID (creatureNearPointI 3 mwp w)
& updatePos
& tgActive .~ False
where
+28 -48
View File
@@ -44,12 +44,13 @@ launcher = defaultGun
, _amString = "EXPLOSIVE SHELL"
, _amPjDraw = drawShell
}
, _ammoBaseMax = 30
, _ammoLoaded = 30
, _ammoBaseMax = 1
, _ammoLoaded = 1
, _reloadTime = 80
}
, _itUse = ruseRate 20 aRocketWithItemParams upHammer
[ ammoCheckI
, _itUse = ruseRate 20 fireLauncher upHammer
[ hammerCheckI
, ammoCheckI
, useTimeCheck
, withSoundStart tap4S
, useAmmoAmount 1
@@ -154,19 +155,18 @@ doThrust pj w = w
(sparkD,_) = randomR (-0.2,0.2) $ _randGen w
r1 = randInCirc 10 & evalState $ _randGen w
aRocketWithItemParams :: Item -> Creature -> World -> World
aRocketWithItemParams it cr w = over props addShell w
fireLauncher :: Item -> Creature -> World -> World
fireLauncher it cr w = addShell w
where
i = IM.newKey $ _props w
params = _itParams it
spindrag = _shellSpinDrag params
spinamount = _shellSpinAmount params
thrustdelay = _shellThrustDelay params
addShell = makeShell i it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
. pjThrust thrustdelay pj
. reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj
. decTimMvVel pj
. moveShell pj
addShell = makeShell it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
. pjThrust thrustdelay pj
. reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj
. decTimMvVel pj
. moveShell pj
moveShell :: Prop -- ^ Projectile id
-> World
@@ -181,13 +181,12 @@ moveShell pj w
where
time = _pjTimer pj
doExplode = w
& projectileExplosion oldPos
& _pjPayload pj oldPos
& stopSoundFrom (ShellSound i)
& props %~ IM.delete i
i = _pjID pj
oldPos = _pjPos pj
vel = _pjVel pj
projectileExplosion = _pjPayload pj
newPos = oldPos +.+ vel
reduceSpinBy :: Float -> Prop -> World -> World
@@ -257,35 +256,16 @@ trySpinByCID cid i pj w = w & props . ix pjid . pjSpin .~ newSpin
trackingLauncher :: Item
trackingLauncher = launcher
{ _itName = "ROCKO-TRACK"
, _itType = TRACKINGLAUNCHER
, _itUse = ruseRate 10 fireTrackingLauncher upHammer
[ ammoCheckI
, hammerCheckI
, useTimeCheck
, withSoundStart tap4S
, useAmmoAmount 1
]
& useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0.5
& useAim . aimStance .~ TwoHandTwist
}
& itName .~ "ROCKO-TRACK"
& itType .~ TRACKINGLAUNCHER
& itUse . rUse .~ fireTrackingLauncher
remoteLauncher :: Item
remoteLauncher = launcher
{ _itName = "ROCKO-REMOTE"
, _itType = REMOTELAUNCHER
, _itUse = ruseRate 10 fireRemoteLauncher upHammer
[ ammoCheckI
, hammerCheckI
, useTimeCheck
, withSoundStart tap4S
, useAmmoAmount 1
]
& useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0.5
& useAim . aimStance .~ TwoHandTwist
, _itScope = RemoteScope (V2 0 0) 1 True
}
& itName .~ "ROCKO-REMOTE"
& itType .~ REMOTELAUNCHER
& itUse . rUse .~ fireRemoteLauncher
& itScope .~ RemoteScope (V2 0 0) 1 True
& itConsumption . aoType . amPjDraw .~ drawRemoteShell
-- TODO consider allowing tweaking rocket speed
@@ -294,11 +274,11 @@ fireRemoteLauncher it cr w = setLocation
$ set (creatures . ix cid . crInv . ix j . itUse . rUse)
(\_ _ -> explodeRemoteRocket itid i)
$ set (creatures . ix cid . crInv . ix j . itName) "REMOTEROCKET"
$ over props addRemRocket w
$ addRemRocket w
where
i = IM.newKey $ _props w
cid = _crID cr
addRemRocket = makeShell i it cr $ \pj ->
addRemRocket = makeShell it cr $ \pj ->
decTimMvVel pj . setRemoteScope itid pj . moveRemoteShell cid itid pj
j = _crInvSel cr
newitid = IM.newKey $ _itemPositions w
@@ -368,11 +348,10 @@ explodeRemoteRocket itid pjid w
fireTrackingLauncher :: Item -> Creature -> World -> World
fireTrackingLauncher it cr w = setLocation
$ over props addTrackRocket w
$ addTrackRocket w
where
i = IM.newKey $ _props w
cid = _crID cr
addTrackRocket = makeShell i it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
addTrackRocket = makeShell it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
. pjThrust thrustdelay pj
. reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj
. decTimMvVel pj
@@ -392,8 +371,8 @@ fireTrackingLauncher it cr w = setLocation
spindrag = _shellSpinDrag params
params = _itParams it
makeShell :: Int -> Item -> Creature -> (Prop -> World -> World) -> IM.IntMap Prop -> IM.IntMap Prop
makeShell i it cr theupdate = IM.insert i Shell
makeShell :: Item -> Creature -> (Prop -> World -> World) -> World -> World
makeShell it cr theupdate w = w & props %~ IM.insert i Shell
{ _pjPos = pos
, _pjZ = 20
, _pjStartPos = pos
@@ -408,6 +387,7 @@ makeShell i it cr theupdate = IM.insert i Shell
, _pjTimer = 50
}
where
i = IM.newKey $ _props w
dir = _crDir cr
pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0)
am = _itConsumption it
+5 -5
View File
@@ -1,4 +1,8 @@
module Dodge.Reloading where
module Dodge.Reloading
( stepReloading
, startReloadingWeapon
, crStopReloading
) where
import Dodge.Data
import Dodge.Base
--import qualified Data.IntMap.Strict as IM
@@ -6,7 +10,6 @@ import Dodge.Base
--import Data.Maybe
import Control.Lens
startReloadingWeapon :: Creature -> World -> Maybe World
startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr))
icTryStartReloading
@@ -23,9 +26,6 @@ icTryStartReloading it
crStopReloading :: Creature -> Creature
crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . reloadState .~ Nothing'
crUpCrUp :: (Creature -> Creature) -> Creature -> World -> World
crUpCrUp f cr = creatures . ix (_crID cr) %~ f
stepReloading :: Creature -> Creature
stepReloading cr = case cr ^? crInv . ix isel . itConsumption . reloadState . _Just' of
Just 0 -> cr & crInv . ix isel %~ doload
+1 -1
View File
@@ -18,7 +18,7 @@ updateUsingInput w = if _carteDisplay w
updatePressedButtons :: S.Set MouseButton -> World -> World
updatePressedButtons pkeys w
| lbPressed && rbPressed && inTopInv = tryUseItem (you w) w
| lbPressed && rbPressed && inTopInv = useItem (you w) w
| lbPressed &&
(inTopInv || _timeFlow w == RewindingLastFrame)
= useLeftItem (_yourID w) w