Make bezierGun set target on right click

This commit is contained in:
2021-05-23 20:32:15 +02:00
parent b337fbdab9
commit 3ae454acf4
7 changed files with 76 additions and 19 deletions
+17 -16
View File
@@ -58,7 +58,6 @@ pistol
,poisonLauncher
,teslaLauncher
,remoteLauncher
,bezierGun
,defaultThrowable
-- ,shatterGun
,longGun,flamer,blinkGun,forceFieldGun :: Item
@@ -319,35 +318,37 @@ teslaLauncher = launcher
, _wpFire = shootWithSound (fromIntegral launcherSound) $ aRocketWithPayload makeTeslaExplosionAt
}
useTargetPos
:: (Point2 -> Int -> World -> World)
-> Int
-> World
-> World
useTargetPos f cid w = case cr ^? crInv . ix (_crInvSel cr) . itAttachment . _Just . itTargetPos of
Nothing -> w
Just p -> f p cid w
where
cr = _creatures w IM.! cid
bezierGun :: Item
bezierGun = defaultAutoGun
{ _itName = "B-GUN"
, _wpFire = hammerCheck $ maybeSetTarget $ \p ->
, _wpFire = useTargetPos $ \p ->
shootWithSound 0
. withMuzFlare
. withRecoil 40
. torqueBefore 0.05 -- I believe that this doesn't affect
$ shootBezier p -- <- the start point
$ shootBezier p -- <- the start point
, _itAttachment = Nothing
, _itScrollUp = removeItAttachment 0
, _itScrollDown = removeItAttachment 0
, _itHammer = HammerUp
, _itEffect = bezierRecock
, _itEffect = bezierTargetEffect
, _itZoom = defaultItZoom
, _itAimingRange = 0
}
maybeSetTarget :: (Point2 -> Int -> World -> World) -> Int -> World -> World
maybeSetTarget f cid w = case join $ w ^? creatures . ix cid . crInv . ix itRef . itAttachment of
Just (ItTargetPos targetp)
-> f targetp cid w
_ -> w & creatures . ix cid . crInv . ix itRef . itAttachment ?~ ItTargetPos mp
where
mp = mouseWorldPos w
cr = _creatures w IM.! cid
itRef = _crInvSel cr
shootBezier :: Point2 -> Int -> World -> World
shootBezier targetp cid w = over particles (theBullet :) w
shootBezier targetp cid w = w & particles %~ (theBullet :)
where
theBullet = aCurveBulAt
(Just cid)
@@ -365,7 +366,7 @@ shootBezier targetp cid w = over particles (theBullet :) w
a <- randInCirc 10
b <- randInCirc 20
return (a,b)
removeItAttachment :: Int -> Int -> World -> World
removeItAttachment i _ w = w & creatures . ix i . crInv . ix itRef . itAttachment .~ Nothing
where