Simplify sparks

This commit is contained in:
2025-06-07 10:07:16 +01:00
parent 7bee1549bf
commit b4bdfbf2c3
13 changed files with 101 additions and 102 deletions
+34 -31
View File
@@ -1,14 +1,13 @@
module Dodge.Spark (
updateSpark,
colSpark,
colSparkRandDir,
sparkRandDir,
createBarrelSpark,
randColDirSpark,
randDirSpark,
randSpark,
makeSpark,
) where
import Dodge.Damage
import Color
import Control.Monad.State
import Dodge.Data.World
import Dodge.WorldEvent.ThingsHit
@@ -16,6 +15,7 @@ import Geometry
import LensHelp
import System.Random
updateSpark :: World -> Spark -> (World, Maybe Spark)
updateSpark w sk
| magV (_skVel sk) < 1 = (w, Nothing)
@@ -40,68 +40,71 @@ sparkDam' ::
sparkDam' sk sp ep mayEiCrWl = case mayEiCrWl of
(hitp, eicrwl) -> damageCrWl (thedam hitp) eicrwl
where
thedam hitp = Damage (_skDamageType sk) 1 sp hitp ep NoDamageEffect
thedam hitp = Damage (sparkToDamage sk) 10 sp hitp ep NoDamageEffect
createBarrelSpark :: Point2 -> Float -> Int -> World -> World
createBarrelSpark pos dir colid = colSparkRandDir 0.1 (numColor colid) pos dir
sparkToDamage :: Spark -> DamageType
sparkToDamage sp = case _skType sp of
ElectricSpark ->ELECTRICAL
FireSpark -> FLAMING
NormalSpark -> SPARKING
colSpark :: Color -> Point2 -> Float -> World -> World
colSpark = colSparkRandDir 0.7
createBarrelSpark :: Point2 -> Float -> World -> World
createBarrelSpark pos dir = sparkRandDir 0.1 pos dir
randColDirSpark ::
State StdGen Color ->
makeSpark :: SparkType -> Point2 -> Float -> World -> World
makeSpark st p d = cWorld . lWorld . sparks
.:~ Spark
{ _skVel = rotateV d (V2 5 0)
, _skPos = p
, _skOldPos = p
, _skType = st
}
randDirSpark ::
State StdGen Float ->
Point2 ->
World ->
World
randColDirSpark randcol randdir pos w =
randDirSpark randdir pos w =
w
& randGen .~ g
& cWorld . lWorld . sparks
.:~ Spark
{ _skVel = rotateV dir (V2 5 0)
, _skColor = col
, _skPos = pos
, _skOldPos = pos
, _skWidth = 1
, _skDamageType = SPARKING
, _skType = NormalSpark
}
where
((col, dir), g) = (`runState` _randGen w) $ do
c <- randcol
(dir, g) = (`runState` _randGen w) $ do
d <- randdir
return (c, d)
return d
randSpark ::
DamageType ->
SparkType ->
State StdGen Float ->
State StdGen Color ->
State StdGen Float ->
Point2 ->
World ->
World
randSpark dt randspeed randcol randdir pos w =
randSpark dt randspeed randdir pos w =
w
& randGen .~ g
& cWorld . lWorld . sparks
.:~ Spark
{ _skVel = rotateV dir (V2 speed 0)
, _skColor = col
, _skPos = pos
, _skOldPos = pos
, _skWidth = 1
, _skDamageType = dt
, _skType = dt
}
where
((col, dir, speed), g) = (`runState` _randGen w) $ do
c <- randcol
((dir, speed), g) = (`runState` _randGen w) $ do
d <- randdir
x <- randspeed
return (c, d, x)
return (d, x)
colSparkRandDir :: Float -> Color -> Point2 -> Float -> World -> World
colSparkRandDir a col pos dir =
randColDirSpark
(return col)
sparkRandDir :: Float -> Point2 -> Float -> World -> World
sparkRandDir a pos dir =
randDirSpark
(state $ randomR (dir - a, dir + a))
pos