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
+17
View File
@@ -8,6 +8,7 @@ import Dodge.Data
import Dodge.Base
import Dodge.Item.Weapon.Decoration
import Dodge.Item.Weapon.UseEffect
import Dodge.Item.Attachment.Data
import Dodge.WorldEvent.Flash
import Dodge.WorldEvent.ThingsHit
import Picture
@@ -16,6 +17,8 @@ import Geometry.Vector
import Data.Maybe
import Control.Lens
import qualified Data.IntMap.Strict as IM
import qualified Data.Set as S
import qualified SDL
{- |
Controls resetting a weapon, allows for non-continuous fire needing a button release. -}
wpRecock :: ItEffect
@@ -98,3 +101,17 @@ autoSonarEffect = ItInvEffect {_itInvEffect = f 50 ,_itEffectCounter = 0 }
. itEffect . itInvEffect .~ f 140
f t cr i w = w & creatures . ix (_crID cr) . crInv . ix i
. itEffect . itInvEffect .~ f (t-1)
bezierTargetEffect :: ItEffect
bezierTargetEffect = ItInvEffect
{_itInvEffect = setBezierTarget
,_itEffectCounter = 0
}
setBezierTarget :: Creature -> Int -> World -> World
setBezierTarget cr invid w
| _crInvSel cr /= invid = w
| SDL.ButtonRight `S.member` _mouseButtons w = w
& creatures . ix (_crID cr) . crInv . ix invid . itAttachment
%~ maybe (Just $ ItTargetPos $ mouseWorldPos w) Just
| otherwise = w & creatures . ix (_crID cr) . crInv . ix invid . itAttachment .~ Nothing