Simplify explosions

This commit is contained in:
2025-12-05 12:05:30 +00:00
parent 4777b94dfc
commit a4f8369420
4 changed files with 83 additions and 78 deletions
+4 -13
View File
@@ -53,7 +53,6 @@ makeTeslaExplosionAt = undefined
-- [1 .. 29]
makeFlameExplosionAt ::
-- | Position
Point2 ->
World ->
World
@@ -66,9 +65,6 @@ makeFlameExplosionAt p w =
velocities = replicateM 15 (randInCirc 1) & evalState $ _randGen w
timers = randomRs (80, 100) $ _randGen w
-- the ( Nthing :: Maybe Int ) here is "maybe" a creature id that the
-- particle passes through for the first frame of its existence
makeExplosionAt :: Point3 -> Point3 -> World -> World
makeExplosionAt p vel w =
w
@@ -78,15 +74,10 @@ makeExplosionAt p vel w =
.:~ MakeTempLight (LSParam p 150 (V3 1 0.5 0)) 20
& makeShockwaveAt [] p 50 100 1 white
where
fVs = fmap (`v2z` 0) $ replicateM 100 (randInCirc 1) & evalState $ _randGen w
fPs' = fmap (`v2z` 0) $ replicateM 100 (randInCirc 5) & evalState $ _randGen w
fVs = fmap (`v2z` 0) $ replicateM 100 (randInCirc 8) & evalState $ _randGen w
fdamps = replicateM 100 (state $ randomR (0,1)) & evalState $ _randGen w
inversePushOut v = (15 - norm v) * 0.01 *^ v
fVs' = zipWith (+.+.+) fVs $ map inversePushOut fPs'
sizes = randomRs (2, 9) $ _randGen w
times = randomRs (15, 20) $ _randGen w
mF q v damp size time = makeFlamelet
--(q - (2*v + 2* vel)) (v + damp *.*.* vel) size time
(q - (2*v )) (v + damp *.*.* vel) size time
newFs = zipWith4 (mF p) (zipWith (+) fPs' (fmap (3 *.*.*) fVs')) fdamps sizes times
addFlames w' = foldl' (flip ($)) w' newFs
mF v damp size time = makeFlamelet p (v + damp *^ vel) size time
newFs = zipWith4 mF fVs fdamps sizes times
addFlames w' = foldl' (&) w' newFs
+7 -1
View File
@@ -11,12 +11,14 @@ module Dodge.WorldEvent.ThingsHit (
thingsHitExceptCr,
crsHitRadial,
wlsHitRadial,
wlHitPos,
crHit,
crWlPbHit,
wlsHitUnsorted,
isWalkable,
) where
import ListHelp
import Control.Applicative
import Dodge.Wall.Pathing
import Data.Monoid
@@ -28,7 +30,7 @@ import Control.Monad
import Control.Lens
import Data.Bifunctor
import qualified Data.IntSet as IS
import Data.List (sortOn)
--import Data.List (sortOn)
import Data.Maybe
import Dodge.Base
import Dodge.Data.World
@@ -139,6 +141,10 @@ thingsHitExceptCr (Just cid) sp ep = filter t . thingsHit sp ep
wlsHit :: Point2 -> Point2 -> World -> [(Point2, Wall)]
wlsHit sp ep = sortOn (dist sp . fst) . wlsHitUnsorted sp ep
---- pushes out any hit point by one
wlHitPos :: Point2 -> Point2 -> World -> Point2
wlHitPos sp ep = maybe ep ((+ normalize (ep - sp)) . fst) . safeHead . wlsHit sp ep
wlsHitUnsorted :: Point2 -> Point2 -> World -> [(Point2, Wall)]
wlsHitUnsorted sp ep
| sp == ep = const mempty
+1
View File
@@ -66,6 +66,7 @@ xs !? n
{-# INLINABLE (!?) #-}
safeHead :: [a] -> Maybe a
{-# INLINE safeHead #-}
safeHead (x:_) = Just x
safeHead _ = Nothing