Move flame into its own datatype

This commit is contained in:
2022-07-18 22:41:40 +01:00
parent c14b3ff787
commit 54ba0fbedc
29 changed files with 444 additions and 318 deletions
+2 -3
View File
@@ -9,8 +9,7 @@ module Dodge.WorldEvent.Explosion
) where
import Dodge.Data
import Dodge.LightSource
--import Dodge.Default
--import Dodge.Zone
import Dodge.Flame
import Dodge.Base.Collide
import Dodge.WorldEvent.SpawnParticle
--import Dodge.WorldEvent.Flash
@@ -58,7 +57,7 @@ makeFlameExplosionAt
-> World
makeFlameExplosionAt p w
= soundMultiFrom [Explosion 0,Explosion 1] p bangS Nothing w
& instantParticles .++~ newFlames
& flames .++~ newFlames
where
newFlames = zipWith makeFlameWithVelAndTime velocities timers
makeFlameWithVelAndTime vel time = aFlameParticle time p vel
-57
View File
@@ -1,7 +1,6 @@
{- | Creation of particles in the world. -}
module Dodge.WorldEvent.SpawnParticle
( makeGasCloud
, aFlameParticle
, makeFlamelet
, aStaticBall
, incBall
@@ -11,12 +10,8 @@ import Dodge.Data
import Dodge.Zone
import Dodge.Particle.HitEffect.ExpireAndDamage
import Dodge.Particle.Damage
--import Dodge.WorldEvent.HitEffect
import Dodge.WorldEvent.ThingsHit
import Dodge.WorldEvent.Cloud
import Dodge.WorldEvent.Flash
import Dodge.WorldEvent.Shockwave
import Dodge.SoundLogic
import RandomHelp
import Picture
import Geometry
@@ -24,59 +19,7 @@ import qualified IntMapHelp as IM
import LensHelp
import Data.Foldable
import Data.Tuple
import qualified Streaming.Prelude as S
aFlameParticle
:: Int -- ^ Timer
-> Point2 -- ^ Position
-> Point2 -- ^ Velocity
-> Particle
aFlameParticle t pos vel = PtFlame
{ _ptUpdate = moveFlame
, _ptVel = vel
, _ptColor = red
, _ptPos = pos
, _ptWidth = 4
, _ptTimer = t
, _ptHitEff = expireAndDamage $ simpleDam FLAMING 1
, _ptZ = 20
, _ptOriginalVel = vel
}
{- TODO: add generalised area damage particles/hiteffects. -}
moveFlame :: World
-> Particle
-> (World, Maybe Particle)
moveFlame w pt
| time <= 0 = (makeFlamerSmokeAt (addZ 20 ep) w, Nothing)
| otherwise = case runIdentity . S.head_ $ thingsHit sp ep w of
Just (_,Left _) -> (doSound $ dodamage w , mvPt' 0.7)
Just (p,Right wl) -> (doSound $ dodamage w , rfl wl p)
_ -> (ptFlicker pt $ doSound $ dodamage w , mvPt' 0.98)
where
rotd = _ptOriginalVel pt
time = _ptTimer pt
doSound = soundContinue Flame (V2 x y) fireLoudS (Just 2)
sp@(V2 x y) = _ptPos pt
vel = _ptVel pt
ep = sp +.+ vel
mvPt' drag = Just $ pt
& ptTimer -~ 1
& ptPos .~ ep
& ptVel %~ (drag *.*)
dodamage = damageInArea closeCrs closeWls pt
closeWls wl = uncurry segOnCirc (_wlLine wl) ep 5
closeCrs cr = dist ep (_crPos cr)
< _crRad cr + 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
{ _ptTimer = time - 1
, _ptPos = pOut p
, _ptVel = reflV wl
}
pOut p = p +.+ squashNormalizeV (sp -.- p)
reflV wall = (0.3 *.* reflectIn (uncurry (-.-) . swap $ _wlLine wall) vel )
+.+ (0.2 *.* vel)
concBall :: Point2 -> State g Particle