From bc4aeef35ebb2b8e8d0dbabecb2255e33305e02c Mon Sep 17 00:00:00 2001 From: jgk Date: Mon, 22 Mar 2021 14:36:20 +0100 Subject: [PATCH] Cleanup muzzle flare --- src/Dodge/Item/Weapon.hs | 14 +++++---- src/Dodge/Item/Weapon/Bullet.hs | 2 +- src/Dodge/Item/Weapon/TriggerType.hs | 18 +++++------- src/Dodge/WorldActions.hs | 2 +- src/Dodge/WorldActions/Flash.hs | 43 +++++++++------------------- 5 files changed, 30 insertions(+), 49 deletions(-) diff --git a/src/Dodge/Item/Weapon.hs b/src/Dodge/Item/Weapon.hs index 1a630061f..78a10bfbb 100644 --- a/src/Dodge/Item/Weapon.hs +++ b/src/Dodge/Item/Weapon.hs @@ -489,8 +489,9 @@ spreadGun = defaultGun , _wpFireRate = 20 , _wpFireState = 0 , _wpFire = shootWithSound (fromIntegral shotgunSound) - $ withRecoil 100 - $ spreadNumVelWthHiteff' spreadGunSpread 9 (30,0) 2 bulletEffect' + . withRecoil 100 + . withMuzFlare + $ spreadNumVelWthHiteff spreadGunSpread 9 (30,0) 2 bulletEffect' , _wpSpread = spreadGunSpread , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ color green $ pictures [ polygon [(-3,0),(3,6),(3,-6)] @@ -531,8 +532,9 @@ multGun = defaultGun , _wpFireRate = 20 , _wpFireState = 0 , _wpFire = shootWithSound (fromIntegral shotgunSound) - $ withRecoil 200 - $ numVelWthHitEff' 5 (50,0) 4 bulletEffect' + . withRecoil 200 + . withMuzFlare + $ numVelWthHitEff 5 (50,0) 4 bulletEffect' , _wpSpread = spreadGunSpread , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ multGunPic @@ -905,13 +907,13 @@ moveFlame rotd w pt = -- ((p,(E3x1 cr)):_) -> (damcr cr p $ smokeGen damcrs, Nothing) ((p,(E3x1 cr)):_) -> (soundFrom Flame fireSound 2 500 - $ over worldEvents ((.) $ lowLightRadAt orange 0.05 8 50 ep) + $ over worldEvents ((.) $ flameGlareAt ep) damcrs , mvPt') (thing@(p,(E3x2 wl)):_) -> (fst $ hiteff [thing] damcrs, rfl wl p) _ -> (soundFrom Flame fireSound 2 500 -- adding reflective glare is too intensive for this laptop - $ over worldEvents ((.) $ lowLightRadAt orange 0.05 8 50 ep) + $ over worldEvents ((.) $ flameGlareAt ep) damcrs , mvPt) where sp = _btPos' pt diff --git a/src/Dodge/Item/Weapon/Bullet.hs b/src/Dodge/Item/Weapon/Bullet.hs index 8ccffbebd..7f074fb14 100644 --- a/src/Dodge/Item/Weapon/Bullet.hs +++ b/src/Dodge/Item/Weapon/Bullet.hs @@ -28,7 +28,7 @@ bulHitCr' bt p cr w = addDamageArmoured = over (creatures . ix cid . crState . crDamage) (\dams -> mvDams ++ dams) hitSound = soundMultiFrom [CrHitSound 0] 15 10 0 - flashEff = over worldEvents ((.) $ flareAt red p) + flashEff = over worldEvents ((.) $ flareAt' red 0.02 0.05 p) bulVel = _btVel' bt ck cid = (+.+) (crKnockBack cid *.* bulVel) crKnockBack cid = (/) 1 $ (+) 2 $ _crMass $ _creatures w IM.! cid diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 6d51caf4b..523ec9f1d 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -95,7 +95,7 @@ shoot f cid w | fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> am withMuzFlare :: (Int -> World -> World) -> Int -> World -> World withMuzFlare f cid w = over tempLightSources (tLightAt 3 pos :) - . lowLightAt pos2 $ f cid w + . muzFlareAt pos2 $ f cid w where cr = _creatures w IM.! cid dir = _crDir cr pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr) @@ -157,32 +157,29 @@ torqueAfter torque feff cid w rotateScope w = w & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) . itAttachment . _Just . scopePos %~ rotateV rot -spreadNumVelWthHiteff' :: Float -> Int -> Point2 -> Float -> HitEffect -> Int -> World -> World -spreadNumVelWthHiteff' spread num vel wth eff cid w +spreadNumVelWthHiteff :: Float -> Int -> Point2 -> Float -> HitEffect -> Int -> World -> World +spreadNumVelWthHiteff spread num vel wth eff cid w = over particles' (newbuls ++) - $ flip (foldr muzFlareAt) poss w where cr = _creatures w IM.! cid newbuls = zipWith3 (\pos d colid -> aGenBulAt' (Just cid) (numColor colid) pos (rotateV d vel) eff wth ) poss dirs colids - pos' = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr) poss = map ((+.+) $ _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)) $ evalState ((sequence . take num . repeat . randInCirc) 5) $ _randGen w dirs = map ((+) (_crDir cr)) $ zipWith (+) [-spread,-spread+(2*spread/(fromIntegral num))..] $ randomRs (0,spread/5) (_randGen w) - -- $ randomRs (0,spreadGunSpread/5) (_randGen w) colids = take num $ randomRs (0,11) (_randGen w) -numVelWthHitEff' :: Int -> Point2 -> Float -> HitEffect -> Int -> World -> World -numVelWthHitEff' num vel wth eff cid w +numVelWthHitEff :: Int -> Point2 -> Float -> HitEffect -> Int -> World -> World +numVelWthHitEff num vel wth eff cid w = over particles' (newbuls ++) - $ flip (foldr muzFlareAt) (take num poss) w where cr = _creatures w IM.! cid newbuls = zipWith (\pos colid -> aGenBulAt' (Just cid) (numColor colid) - pos (rotateV d vel) eff wth) + pos (rotateV d vel) eff wth + ) poss colids d = _crDir cr poss = map (\o -> o +.+ pos) offsets @@ -190,4 +187,3 @@ numVelWthHitEff' num vel wth eff cid w offsets = map (\y -> rotateV d (0,y)) [-maxOffset,5-maxOffset..] colids = take num $ randomRs (0,11) (_randGen w) pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle d - pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr) diff --git a/src/Dodge/WorldActions.hs b/src/Dodge/WorldActions.hs index c481ad747..c831d2b98 100644 --- a/src/Dodge/WorldActions.hs +++ b/src/Dodge/WorldActions.hs @@ -69,7 +69,7 @@ explosionWaveDamage time p ptid = set (particles . ix ptid . ptUpdate) (explosionWaveDamage (time-1) p ptid) . shockWaveDamage p rad 20 . set (particles . ix ptid . ptPict) shockwavePic - . lowLightRadAt white 0.3 75 150 p + . explosionFlashAt p where shockwavePic = onLayer PtLayer $ uncurry translate p $ color (withAlpha 0.9 white) $ thickCircle rad (thickness*2) thickness = max 0 $ sqrt $ (fromIntegral time - 2) * 8 diff --git a/src/Dodge/WorldActions/Flash.hs b/src/Dodge/WorldActions/Flash.hs index 5720ae40a..004549982 100644 --- a/src/Dodge/WorldActions/Flash.hs +++ b/src/Dodge/WorldActions/Flash.hs @@ -11,9 +11,6 @@ import Geometry import Control.Lens -flareAt :: Color -> Point2 -> World -> World -flareAt c p = flareAt' c 0.02 0.5 p - flareAt' :: Color -> Float -> Float -> Point2 -> World -> World flareAt' col alphax alphay p = -- over particles' ((:) (flashColAt col alphax p)) @@ -21,17 +18,16 @@ flareAt' col alphax alphay p lowLightColAt col alphay p lowLightColAt :: Color -> Float -> Point2 -> World -> World -lowLightColAt col alphay p w = foldr (lowLightColHit col alphay p) w ps +lowLightColAt col alphay p w = foldr (lowLightWidthHit 10 5 col alphay p) w ps where ps = map ((+.+) p) $ nRaysRad 20 30 - -lowLightColHit :: Color -> Float -> Point2 -> Point2 -> World -> World -lowLightColHit col alphay a b w +lowLightWidthHit :: Float -> Float -> Color -> Float -> Point2 -> Point2 -> World -> World +lowLightWidthHit len wdth col alphay a b w = case thingsHitLongLine a b w of ((p, E3x2 wall):_) - -> over particles' ((:) (wallGlareWidth 10 5 col alphay p wall)) w + -> over particles' ((:) (wallGlareWidth len wdth col alphay p wall)) w ((p, E3x1 cr):_) - -> over particles' ((:) (crGlareCol col alphay p cr)) w + -> over particles' ((:) (crGlareWidth wdth col alphay p cr)) w _ -> w flashColAt :: Color -> Float -> Point2 -> Particle' @@ -45,9 +41,6 @@ flashColAt col alphax (x,y) = , _ptUpdate' = ptTimer' 1 } -crGlareCol :: Color -> Float -> Point2 -> Creature -> Particle' -crGlareCol col alphay p cr = crGlareWidth 5 col alphay p cr - wallGlareWidth :: Float -> Float -> Color -> Float -> Point2 -> Wall -> Particle' wallGlareWidth len wdth col alphay p wl = Particle' @@ -85,7 +78,7 @@ flareWidth len wdth rad rays col ax ay p flareRad :: Float -> Int -> Color -> Float -> Float -> Point2 -> World -> World flareRad rad rays col ax ay p = over particles' ((:) (flashRadAt rad col ax p)) - . lowLightRadAt col ay rays rad p + . lowLightWidthAt 10 5 col ay rays rad p flashRadAt :: Float -> Color -> Float -> Point2 -> Particle' flashRadAt rad col alphax (x,y) = @@ -102,23 +95,13 @@ lowLightWidthAt :: Float -> Float -> Color -> Float -> Int -> Float -> Point2 -> lowLightWidthAt len wdth col alphay rays rad p w = foldr (lowLightWidthHit len wdth col alphay p) w ps where ps = map ((+.+) p) $ nRaysRad rays rad -lowLightRadAt :: Color -> Float -> Int -> Float -> Point2 -> World -> World -lowLightRadAt col alphay rays rad p w = foldr (lowLightColHit col alphay p) w ps - where ps = map ((+.+) p) $ nRaysRad rays rad +explosionFlashAt = lowLightWidthAt 10 5 white 0.3 75 150 +flameGlareAt = lowLightWidthAt 10 5 orange 0.05 8 50 lowLightDirected :: Color -> Float -> Point2 -> Point2 -> [Float] -> World -> World lowLightDirected col alpha a b angles w - = foldr (\angle w' -> lowLightColHit col alpha a (a +.+ rotateV angle b) w') w angles - -lowLightWidthHit :: Float -> Float -> Color -> Float -> Point2 -> Point2 -> World -> World -lowLightWidthHit len wdth col alphay a b w - = case thingsHitLongLine a b w of - ((p, E3x2 wall):_) - -> over particles' ((:) (wallGlareWidth len wdth col alphay p wall)) w - ((p, E3x1 cr):_) - -> over particles' ((:) (crGlareWidth wdth col alphay p cr)) w - _ -> w + = foldr (\angle w' -> lowLightWidthHit 10 5 col alpha a (a +.+ rotateV angle b) w') w angles muzFlareAt :: Point2 -> World -> World @@ -128,10 +111,10 @@ muzFlareAt p = over particles' ((:) (muzzleFlareAt p)) muzzleFlareAt :: Point2 -> Particle' muzzleFlareAt (x,y) = Particle' - { _ptPict' = pictures - $ map (\i -> onLayer PtLayer $ color (withAlpha 0.02 white) $ translate x y $ circleSolid i - ) - [20,25,30,35,40,45,50] + { _ptPict' = setDepth 0 + . setLayer 1 + . translate x y + $ circleSolidCol (withAlpha 0 white) (withAlpha 0.2 white) 20 , _ptUpdate' = ptTimer' 1 }