From f18bf2348acee400b431997d3e7e2da193b3dc09 Mon Sep 17 00:00:00 2001 From: jgk Date: Tue, 16 Mar 2021 14:16:27 +0100 Subject: [PATCH] Abstract out direction accuracy --- src/Dodge/Item/Weapon.hs | 15 +++++++++------ src/Dodge/Item/Weapon/Recock.hs | 28 ++++++++++++++++++++++++++++ src/Dodge/Item/Weapon/TriggerType.hs | 9 +++++---- 3 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 src/Dodge/Item/Weapon/Recock.hs diff --git a/src/Dodge/Item/Weapon.hs b/src/Dodge/Item/Weapon.hs index b2f414a0b..62186d116 100644 --- a/src/Dodge/Item/Weapon.hs +++ b/src/Dodge/Item/Weapon.hs @@ -61,7 +61,8 @@ pistol = Weapon , _wpFireRate = 8 , _wpFireState = 0 , _wpFire = shootWithSound 0 - $ withAccVelWthHiteff' 0.1 (30,0) 2 + . withRandomDir 0.1 + . withVelWthHiteff (30,0) 2 $ threeEff' bulHitCr' bulHitWall' bulHitFF' , _wpSpread = 0.02 , _wpRange = 20 @@ -125,12 +126,14 @@ autoGun = defaultGun autoFireMode = shootWithSound (fromIntegral autoGunSound) $ withRecoil 40 $ torqueBefore 0.05 - $ withAccVelWthHiteff' (autogunSpread/2) (50,0) 3 + $ withRandomDir (autogunSpread/2) + $ withVelWthHiteff (50,0) 3 $ threeEff' bulHitCr' bulHitWall' bulHitFF' singleFireMode = shootWithSound (fromIntegral autoGunSound) $ withRecoil 40 $ torqueAfter 0.03 - $ withAccVelWthHiteff' (autogunSpread/2) (50,0) 3 + $ withRandomDir (autogunSpread/2) + $ withVelWthHiteff (50,0) 3 $ threeEff' bulHitCr' bulHitWall' bulHitFF' incMode :: Int -> World -> World @@ -417,7 +420,7 @@ hvAutoGun = defaultAutoGun } where mkHvBul = withSound (fromIntegral longGunSound) $ withThinSmoke - $ withAccVelWthHiteff' 0 (80,0) 6 + $ withVelWthHiteff (80,0) 6 $ threeEff' hvBulHitCr' hvBulHitWall' bulHitFF' @@ -430,7 +433,7 @@ ltAutoGun = defaultAutoGun , _wpReloadState = 0 , _wpFireRate = 4 , _wpFireState = 0 - , _wpFire = shootWithSound 0 $ withAccVelWthHiteff' 0.3 (30,0) 2 bulletEffect' + , _wpFire = shootWithSound 0 . withRandomDir 0.3 $ withVelWthHiteff (30,0) 2 bulletEffect' , _wpSpread = 0.5 , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ color green $ pictures [polygon $ rectNSWE 4 (-4) (-4) 0 @@ -549,7 +552,7 @@ longGun = defaultGun , _wpFire = shootWithSound (fromIntegral longGunSound) $ withThickSmoke $ torqueAfter 0.05 - $ withAccVelWthHiteff' 0 (60,0) 6 + $ withVelWthHiteff (60,0) 6 $ threeEff' hvBulHitCr' hvBulHitWall' bulHitFF' diff --git a/src/Dodge/Item/Weapon/Recock.hs b/src/Dodge/Item/Weapon/Recock.hs new file mode 100644 index 000000000..c950ea477 --- /dev/null +++ b/src/Dodge/Item/Weapon/Recock.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE BangPatterns #-} +module Dodge.Item.Weapon.Recock + where +import Dodge.Data + +import Control.Lens +import qualified Data.IntMap.Strict as IM + +wpRecock :: ItEffect +wpRecock = ItInvEffect {_itInvEffect = f + ,_itEffectCounter = 0 + } + where f cr i = creatures . ix (_crID cr) . crInv + %~ IM.adjust fOnIt i + moveHammerUp !HammerDown = HammerReleased + moveHammerUp !HammerReleased = HammerUp + moveHammerUp !HammerUp = HammerUp + fOnIt it = it & itHammer %~ moveHammerUp + +bezierRecock :: ItEffect +bezierRecock = ItInvEffect {_itInvEffect = f + ,_itEffectCounter = 0 + } + where f cr i = creatures . ix (_crID cr) . crInv + %~ IM.adjust fOnIt i + fOnIt it = case _itHammer it of + HammerDown -> it & itHammer .~ HammerUp + _ -> it & itAttachment .~ Nothing diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 6299314c7..f359ee66c 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -112,8 +112,8 @@ withRandomDir acc f cid w = over (creatures . ix cid . crDir) (\d -> d - a) w where (a, g) = randomR (-acc,acc) $ _randGen w -withAccVelWthHiteff' :: Float -> Point2 -> Float -> HitEffect' -> Int -> World -> World -withAccVelWthHiteff' acc vel width hiteff cid w +withVelWthHiteff :: Point2 -> Float -> HitEffect' -> Int -> World -> World +withVelWthHiteff vel width hiteff cid w = over particles' ((:) newbul) . over tempLightSources ((:) (tLightAt 4 pos)) . lowLightAt pos2 @@ -122,11 +122,12 @@ withAccVelWthHiteff' acc vel width hiteff cid 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 + dir = _crDir cr 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 )