Refactor bezgun
This commit is contained in:
+30
-31
@@ -180,7 +180,6 @@ rezGun = defaultGun
|
||||
, _itFloorPict = onLayer FlItLayer $ color chartreuse $ pictures [polygon $ rectNESW 7 3 1 (-3)
|
||||
,polygon $ rectNESW (-1) 3 (-7) (-3)
|
||||
]
|
||||
|
||||
, _itAmount = 1
|
||||
, _itMaxStack = 1
|
||||
, _itAimingSpeed = 0.4
|
||||
@@ -204,7 +203,6 @@ teslaGun = defaultAutoGun
|
||||
, _itFloorPict = onLayer FlItLayer $ color blue $ pictures [polygon $ rectNESW 7 3 1 (-3)
|
||||
,polygon $ rectNESW (-1) 3 (-7) (-3)
|
||||
]
|
||||
|
||||
, _itAmount = 1
|
||||
, _itMaxStack = 1
|
||||
, _itAimingSpeed = 0.4
|
||||
@@ -337,7 +335,11 @@ launcher = defaultGun
|
||||
}
|
||||
bezierGun = defaultAutoGun
|
||||
{ _itName = "B-GUN"
|
||||
, _wpFire = maybeSetTarget shootBezier
|
||||
, _wpFire = maybeSetTarget $ \p -> shootWithSound 0
|
||||
. withMuzFlare
|
||||
. withRecoil 40
|
||||
. torqueBefore 0.05 -- I believe that this doesn't affect
|
||||
$ shootBezier p -- <- the start point
|
||||
, _itAttachment = Nothing
|
||||
, _itScrollUp = removeItAttachment 0
|
||||
, _itScrollDown = removeItAttachment 0
|
||||
@@ -349,37 +351,34 @@ bezierGun = defaultAutoGun
|
||||
|
||||
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 .~ Just (ItTargetPos mp)
|
||||
where
|
||||
mp = mouseWorldPos w
|
||||
cr = _creatures w IM.! cid
|
||||
itRef = _crInvSel cr
|
||||
Just (ItTargetPos targetp)
|
||||
-> f targetp cid w
|
||||
_ -> w & creatures . ix cid . crInv . ix itRef . itAttachment .~ Just (ItTargetPos mp)
|
||||
where
|
||||
mp = mouseWorldPos w
|
||||
cr = _creatures w IM.! cid
|
||||
itRef = _crInvSel cr
|
||||
|
||||
shootBezier :: Point2 -> Int -> World -> World
|
||||
shootBezier targetp cid w = (shootWithSound 0
|
||||
. withMuzFlare
|
||||
. withRecoil 40
|
||||
. torqueBefore 0.05
|
||||
) bezBul cid w
|
||||
where
|
||||
-- note that torqueBefore will not affect the startp here
|
||||
bezBul = mkBezierBul startp controlp targetp
|
||||
controlp = mouseWorldPos w
|
||||
cr = _creatures w IM.! cid
|
||||
dir = _crDir cr
|
||||
startp = _crPos cr +.+ rotateV dir (_crRad cr + 1,0)
|
||||
shootBezier targetp cid w = over particles' (theBullet :) w
|
||||
where
|
||||
theBullet = aCurveBulAt
|
||||
(Just cid)
|
||||
white
|
||||
startp
|
||||
(controlp +.+ randPos)
|
||||
(targetp +.+ randPos')
|
||||
(destroyOnImpact bulHitCr' bulHitWall' bulHitFF')
|
||||
5
|
||||
controlp = mouseWorldPos w
|
||||
cr = _creatures w IM.! cid
|
||||
dir = _crDir cr
|
||||
startp = _crPos cr +.+ rotateV dir (_crRad cr + 1,0)
|
||||
(randPos,randPos') = flip evalState (_randGen w)
|
||||
$ do a <- randInCirc 10
|
||||
b <- randInCirc 20
|
||||
return (a,b)
|
||||
|
||||
mkBezierBul :: Point2 -> Point2 -> Point2 -> Int -> World -> World
|
||||
mkBezierBul startp controlp targetp cid w = over particles' (bbul :) w
|
||||
where
|
||||
bbul = aCurveBulAt (Just cid) white startp (controlp +.+ randPos) (targetp +.+ randPos')
|
||||
(passThroughAll bulHitCr' bulHitWall' bulHitFF') 5
|
||||
(randPos,randPos') = flip evalState (_randGen w)
|
||||
$ do 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 cr = _creatures w IM.! i
|
||||
|
||||
Reference in New Issue
Block a user