Refactor, try to limit dependencies

This commit is contained in:
2022-07-28 00:59:56 +01:00
parent 8aa5c17ab9
commit 160560af5f
418 changed files with 15104 additions and 13342 deletions
+77 -68
View File
@@ -1,15 +1,15 @@
{- | Creation of particles in the world. -}
module Dodge.WorldEvent.SpawnParticle
( makeGasCloud
, makeStaticBall
, concBall
-- , randParticleAt
) where
import Dodge.Data
import RandomHelp
import Picture
-- | Creation of particles in the world.
module Dodge.WorldEvent.SpawnParticle (
makeGasCloud,
makeStaticBall,
concBall,
) where
import Dodge.Data.World
import Geometry
import LensHelp
import Picture
import RandomHelp
--randParticleAt :: (Point2 -> State StdGen Particle) -> Point2 -> World -> World
--randParticleAt f p w = w
@@ -18,11 +18,12 @@ import LensHelp
-- where
-- (thepart,g) = runState (f p) (_randGen w)
randEnergyBallAt :: (Point2 -> State StdGen EnergyBall) -> Point2 -> World -> World
randEnergyBallAt f p w = w
& cWorld . energyBalls .:~ thepart
& randGen .~ g
randEnergyBallAt f p w =
w
& cWorld . energyBalls .:~ thepart
& randGen .~ g
where
(thepart,g) = runState (f p) (_randGen w)
(thepart, g) = runState (f p) (_randGen w)
makeStaticBall :: Point2 -> World -> World
makeStaticBall p = randEnergyBallAt aStaticBall p . (cWorld . posEvents .:~ thesparker)
@@ -30,37 +31,41 @@ makeStaticBall p = randEnergyBallAt aStaticBall p . (cWorld . posEvents .:~ thes
thesparker = PosEvent SparkSpawner 10 p
concBall :: Point2 -> Shockwave
concBall p = Shockwave
{ _swDirection = OutwardShockwave
, _swInvulnerableCrs = []
, _swColor = white
, _swPos = p
, _swRad = 15
, _swDam = 4
, _swPush = 1
, _swMaxTime = 10
, _swTimer = 10
}
concBall p =
Shockwave
{ _swDirection = OutwardShockwave
, _swInvulnerableCrs = []
, _swColor = white
, _swPos = p
, _swRad = 15
, _swDam = 4
, _swPush = 1
, _swMaxTime = 10
, _swTimer = 10
}
aStaticBall :: Point2 -> State g EnergyBall
aStaticBall p = return EnergyBall
{ _ebVel = 0
, _ebColor = blue
, _ebPos = p
, _ebWidth = 3
, _ebTimer = 20
, _ebEff = (ELECTRICAL,1)
, _ebZ = 20
, _ebRot = 0
}
aStaticBall p =
return
EnergyBall
{ _ebVel = 0
, _ebColor = blue
, _ebPos = p
, _ebWidth = 3
, _ebTimer = 20
, _ebEff = (ELECTRICAL, 1)
, _ebZ = 20
, _ebRot = 0
}
-- | Note damgeInRadius by itself never destroys the particle
--damageInRadius :: Float -> Particle -> World -> World
--damageInRadius size pt = damageInArea isClose closeWls pt
-- where
-- p = _ptPos pt
-- closeWls wl = uncurry segOnCirc (_wlLine wl) p size
-- isClose cr = dist p (_crPos cr) < _crRad cr + size
{- | Note damgeInRadius by itself never destroys the particle
damageInRadius :: Float -> Particle -> World -> World
damageInRadius size pt = damageInArea isClose closeWls pt
where
p = _ptPos pt
closeWls wl = uncurry segOnCirc (_wlLine wl) p size
isClose cr = dist p (_crPos cr) < _crRad cr + size
-}
--damageInArea :: (Creature -> Bool) -> (Wall -> Bool) -> Particle -> World -> World
--{-# INLINE damageInArea #-}
@@ -69,46 +74,50 @@ aStaticBall p = return EnergyBall
-- p = _ptPos pt
-- damcrs = foldl' (flip $ \cr -> fst . hiteff (S.yield (p,Left cr))) w $ IM.filter crt $ _creatures w
-- damwls w' = runIdentity
-- . S.fold_
-- (flip $ \wl -> fst . hiteff (S.yield (p,Right wl)))
-- w'
-- . S.fold_
-- (flip $ \wl -> fst . hiteff (S.yield (p,Right wl)))
-- w'
-- id
-- . S.filter wlt
-- $ wlsNearPoint p w'
-- hiteff = _ptHitEff pt pt
-- | At writing the radius is half the size of the effect area
makeGasCloud
:: Point2 -- ^ Position
-> Point2 -- ^ Velocity
-> World
-> World
makeGasCloud pos vel w = w
& cWorld . clouds .:~ theCloud
& randGen .~ g
where
theCloud = Cloud
{ _clPos = addZ 20 pos
, _clVel = addZ 0 vel
, _clPict = DrawGasCloud col
, _clRad = 10
, _clAlt = 25
, _clTimer = 400
, _clType = GasCloud
}
(col, g) = runState (takeOne [green,yellow]) $ _randGen w
{- Attach poison cloud damage to creatures near cloud. -}
makeGasCloud ::
-- | Position
Point2 ->
-- | Velocity
Point2 ->
World ->
World
makeGasCloud pos vel w =
w
& cWorld . clouds .:~ theCloud
& randGen .~ g
where
theCloud =
Cloud
{ _clPos = addZ 20 pos
, _clVel = addZ 0 vel
, _clPict = DrawGasCloud col
, _clRad = 10
, _clAlt = 25
, _clTimer = 400
, _clType = GasCloud
}
(col, g) = runState (takeOne [green, yellow]) $ _randGen w
{- Attach poison cloud damage to creatures near cloud. -}
{- Update of a flamelet.
Applies movement and attaches damage to nearby creatures. -}
-- This should be unified in many ways with moveFlame
--moveFlamelet :: World -> Particle -> (World, Maybe Particle)
--moveFlamelet w pt
--moveFlamelet w pt
-- | _ptTimer pt <= 0 = ( w, Nothing)
-- | otherwise = (ptFlicker pt $ damageInRadius 5 mvPt' w, Just mvPt')
-- where
-- mvPt' = pt
-- where
-- mvPt' = pt
-- & ptTimer -~ 1
-- & ptPos .~ _ptPos pt +.+ _ptVel pt
-- & ptVel .*.*~ 0.8