Simplify flames

This commit is contained in:
2025-06-08 12:12:58 +01:00
parent ba9e9278c4
commit 54937fd159
4 changed files with 126 additions and 87 deletions
+50 -13
View File
@@ -4,9 +4,9 @@ module Dodge.Flame (
updateFlame,
) where
import Dodge.Flame.Size
import Data.Foldable
import Data.Tuple
import Dodge.Creature.Radius
import Dodge.Data.World
import Dodge.SoundLogic
import Dodge.WorldEvent.Cloud
@@ -31,10 +31,8 @@ aFlameParticle t pos vel =
Flame
{ _flVel = vel
, _flPos = pos
, _flWidth = 4
, _flTimer = t
, _flZ = 20
, _flOriginalVel = vel
-- , _flOriginalVel = vel
}
expireAndDamageFL ::
@@ -63,11 +61,10 @@ updateFlame :: World -> Flame -> (World, Maybe Flame)
updateFlame w pt
| time <= 0 = (makeFlamerSmokeAt (addZ 20 ep) w, Nothing)
| otherwise = case List.safeHead $ thingsHit sp ep w of
Just (_, Left _) -> (doSound $ dodamage w, mvPt' 0.7)
Just (p, Right wl) -> (doSound $ dodamage w, rfl wl p)
_ -> (flFlicker pt $ doSound $ dodamage w, mvPt' 0.98)
Just (_, Left _) -> (doSound $ dodamage, mvPt' 0.7)
Just (p, Right wl) -> (doSound $ dodamage, rfl wl p)
_ -> (flFlicker pt $ doSound $ dodamage, mvPt' 0.98)
where
rotd = _flOriginalVel pt
time = _flTimer pt
doSound = soundContinue FlameSound (V2 x y) fireLoudS (Just 2)
sp@(V2 x y) = _flPos pt
@@ -79,12 +76,15 @@ updateFlame w pt
& flTimer -~ 1
& flPos .~ ep
& flVel %~ (drag *.*)
dodamage = flDamageInArea closeCrs closeWls pt
dodamage :: World
dodamage = foldl' damcr
(foldl' damwl w (wlsHitRadial ep r w)) (crsHitRadial ep r w)
r = flameSize pt
damcr w' (_,cr) = w' & cWorld . lWorld . creatures . ix (_crID cr) . crState . csDamage
.:~ Flaming 1
damwl w' (_,wl) = w' & cWorld . lWorld . wallDamages . ix (_wlID wl)
.:~ Flaming 1
closeWls wl = uncurry segOnCirc (_wlLine wl) ep 5
closeCrs cr =
dist ep (_crPos cr)
< crRad (cr ^. crType) + 10 - min 9 (max 0 (fromIntegral time - 80))
+ 5 * angleCoeff (angleVV (ep -.- _crPos cr) rotd)
angleCoeff x' = abs $ 1 - abs ((x' * 2 - pi) / pi)
rfl wl p =
Just $
@@ -97,6 +97,43 @@ updateFlame w pt
reflV wall =
(0.3 *.* reflectIn (uncurry (-.-) . swap $ _wlLine wall) vel)
+.+ (0.2 *.* vel)
--updateFlame w pt
-- | time <= 0 = (makeFlamerSmokeAt (addZ 20 ep) w, Nothing)
-- | otherwise = case List.safeHead $ thingsHit sp ep w of
-- Just (_, Left _) -> (doSound $ dodamage w, mvPt' 0.7)
-- Just (p, Right wl) -> (doSound $ dodamage w, rfl wl p)
-- _ -> (flFlicker pt $ doSound $ dodamage w, mvPt' 0.98)
-- where
-- rotd = _flOriginalVel pt
-- time = _flTimer pt
-- doSound = soundContinue FlameSound (V2 x y) fireLoudS (Just 2)
-- sp@(V2 x y) = _flPos pt
-- vel = _flVel pt
-- ep = sp +.+ vel
-- mvPt' drag =
-- Just $
-- pt
-- & flTimer -~ 1
-- & flPos .~ ep
-- & flVel %~ (drag *.*)
-- dodamage = flDamageInArea closeCrs closeWls pt
-- closeWls wl = uncurry segOnCirc (_wlLine wl) ep 5
-- closeCrs cr =
-- dist ep (_crPos cr)
-- < crRad (cr ^. crType) + 10 - min 9 (max 0 (fromIntegral time - 80))
-- + 5 * angleCoeff (angleVV (ep -.- _crPos cr) rotd)
-- angleCoeff x' = abs $ 1 - abs ((x' * 2 - pi) / pi)
-- rfl wl p =
-- Just $
-- pt
-- { _flTimer = time - 1
-- , _flPos = pOut p
-- , _flVel = reflV wl
-- }
-- pOut p = p +.+ squashNormalizeV (sp -.- p)
-- reflV wall =
-- (0.3 *.* reflectIn (uncurry (-.-) . swap $ _wlLine wall) vel)
-- +.+ (0.2 *.* vel)
flDamageInArea :: (Creature -> Bool) -> (Wall -> Bool) -> Flame -> World -> World
{-# INLINE flDamageInArea #-}