Abstract out random offset for weapons

This commit is contained in:
jgk
2021-03-16 14:32:30 +01:00
parent f18bf2348a
commit 76a4731785
2 changed files with 13 additions and 19 deletions
+4 -2
View File
@@ -457,8 +457,10 @@ miniGun = defaultAutoGun
, _wpReloadState = 0
, _wpFireRate = 2
, _wpFireState = 0
, _wpFire = withWarmUp 50 $ torqueBefore 0.03 $ withSidePush 50 $ withRecoil 15
$ withOffsetAccVelWthHiteff' 9 0.1 (30,0) 2 bulletEffect'
, _wpFire = withWarmUp 50 . torqueBefore 0.03 . withSidePush 50 . withRecoil 15
. withRandomDir 0.1
. withRandomOffset 9
$ withVelWthHiteff (30,0) 2 bulletEffect'
, _wpSpread = autogunSpread
, _wpRange = 20
, _itFloorPict = onLayer FlItLayer $ color red $ polygon $ rectNESW 9 5 (-9) (-5)
+9 -17
View File
@@ -52,7 +52,6 @@ withSound soundid f cid = soundOnce soundid . f cid
withRecoil :: Float -> (Int -> World -> World) -> Int -> World -> World
withRecoil recoilAmount eff cid w = eff cid . over (creatures . ix cid) pushback $ w
where pushback cr = over crPos
-- where pushback cr = colCrWall w $ over crPos
(+.+ rotateV (_crDir cr) ((-recoilAmount) / _crMass cr ,0))
cr
withSidePush :: Float -> (Int -> World -> World) -> Int -> World -> World
@@ -126,22 +125,15 @@ withVelWthHiteff vel width hiteff cid w
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr)
withOffsetAccVelWthHiteff' :: Float -> Float -> Point2 -> Float -> HitEffect' -> Int -> World -> World
withOffsetAccVelWthHiteff' offsetAmount acc vel width hiteff cid w
= over particles' ((:) newbul )
$ muzFlareAt pos
$ set randGen g
w
where cr = _creatures w IM.! cid
newbul = aGenBulAt' (Just cid) (numColor colid) pos (rotateV dir vel) hiteff width
(colid, g) = randomR (0,11) $ _randGen w
(a, _) = randomR (-acc,acc) $ _randGen w
dir = _crDir cr + a
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr) +.+ offset
(offsetVal , _) = randomR (-offsetAmount,offsetAmount) $ _randGen w
offset = rotateV (_crDir cr) (0,offsetVal)
withRandomOffset :: Float -> (Int -> World -> World) -> Int -> World -> World
withRandomOffset offsetAmount f cid w = over (creatures . ix cid . crPos) (-.- offV)
. f cid
. over (creatures . ix cid . crPos) (+.+ offV)
$ set randGen g
w
where (offsetVal , g) = randomR (-offsetAmount,offsetAmount) $ _randGen w
cr = _creatures w IM.! cid
offV = rotateV (_crDir cr) (0,offsetVal)
torqueBeforeForced :: Float -> (Int -> World -> World) -> Int -> World -> World
torqueBeforeForced torque feff cid w