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
+75 -68
View File
@@ -1,42 +1,44 @@
module Dodge.Spark
( moveSpark
, colSpark
, colSparkRandDir
, createBarrelSpark
, randColDirSpark
, randSpark
) where
import Dodge.Data
module Dodge.Spark (
moveSpark,
colSpark,
colSparkRandDir,
createBarrelSpark,
randColDirSpark,
randSpark,
) where
import Color
import Control.Monad.State
import Dodge.Data.World
import Dodge.WorldEvent.ThingsHit
import Geometry
import LensHelp
import Color
import qualified IntMapHelp as IM
import Control.Monad.State
import LensHelp
import System.Random
moveSpark :: World -> Spark -> (World, Maybe Spark)
moveSpark w sk
| magV (_skVel sk) < 1 = (w,Nothing)
| magV (_skVel sk) < 1 = (w, Nothing)
| otherwise = case thingHit sp ep w of
Nothing -> (w, Just $ sk & skPos .~ ep & skVel .*.*~ 0.9 & skOldPos .~ sp)
Just (hp,hthing) -> (sparkDam sk sp ep (hp,hthing) w
, Just $ sk & skPos .~ hp & skOldPos .~ sp & skVel .~ 0)
Just (hp, hthing) ->
( sparkDam sk sp ep (hp, hthing) w
, Just $ sk & skPos .~ hp & skOldPos .~ sp & skVel .~ 0
)
where
sp = _skPos sk
ep = sp +.+ _skVel sk
sparkDam
:: Spark
-> Point2
-> Point2
-> (Point2, Either Creature Wall)
-> World
-> World
sparkDam ::
Spark ->
Point2 ->
Point2 ->
(Point2, Either Creature Wall) ->
World ->
World
sparkDam sk sp ep mayEiCrWl = case mayEiCrWl of
(hitp,Left cr) -> cWorld . creatures . ix (_crID cr) . crState . csDamage .:~ thedam hitp
(hitp,Right wl) -> cWorld . wallDamages %~ IM.insertWith (++) (_wlID wl) [thedam hitp]
(hitp, Left cr) -> cWorld . creatures . ix (_crID cr) . crState . csDamage .:~ thedam hitp
(hitp, Right wl) -> cWorld . wallDamages %~ IM.insertWith (++) (_wlID wl) [thedam hitp]
where
thedam hitp = Damage (_skDamageType sk) 1 sp hitp ep NoDamageEffect
@@ -46,56 +48,61 @@ createBarrelSpark pos dir colid = colSparkRandDir 0.1 (numColor colid) pos dir
colSpark :: Color -> Point2 -> Float -> World -> World
colSpark = colSparkRandDir 0.7
randColDirSpark
:: State StdGen Color
-> State StdGen Float
-> Point2
-> World
-> World
randColDirSpark randcol randdir pos w = w
& cWorld . sparks .:~ spark
& randGen .~ g
randColDirSpark ::
State StdGen Color ->
State StdGen Float ->
Point2 ->
World ->
World
randColDirSpark randcol randdir pos w =
w
& cWorld . sparks .:~ spark
& randGen .~ g
where
((col,dir),g) = (`runState` _randGen w) $ do
((col, dir), g) = (`runState` _randGen w) $ do
c <- randcol
d <- randdir
return (c,d)
spark = Spark
{ _skVel = rotateV dir (V2 5 0)
, _skColor = col
, _skPos = pos
, _skOldPos = pos
, _skWidth = 1
, _skDamageType = SPARKING
}
return (c, d)
spark =
Spark
{ _skVel = rotateV dir (V2 5 0)
, _skColor = col
, _skPos = pos
, _skOldPos = pos
, _skWidth = 1
, _skDamageType = SPARKING
}
randSpark
:: DamageType
-> State StdGen Float
-> State StdGen Color
-> State StdGen Float
-> Point2
-> World
-> World
randSpark dt randspeed randcol randdir pos w = w
& randGen .~ g
& cWorld . sparks .:~ Spark
{ _skVel = rotateV dir (V2 speed 0)
, _skColor = col
, _skPos = pos
, _skOldPos = pos
, _skWidth = 1
, _skDamageType = dt
}
randSpark ::
DamageType ->
State StdGen Float ->
State StdGen Color ->
State StdGen Float ->
Point2 ->
World ->
World
randSpark dt randspeed randcol randdir pos w =
w
& randGen .~ g
& cWorld . sparks
.:~ Spark
{ _skVel = rotateV dir (V2 speed 0)
, _skColor = col
, _skPos = pos
, _skOldPos = pos
, _skWidth = 1
, _skDamageType = dt
}
where
((col,dir,speed),g) = (`runState` _randGen w) $ do
((col, dir, speed), g) = (`runState` _randGen w) $ do
c <- randcol
d <- randdir
x <- randspeed
return (c,d,x)
return (c, d, x)
colSparkRandDir :: Float -> Color -> Point2 -> Float -> World -> World
colSparkRandDir a col pos dir = randColDirSpark
(return col)
(state $ randomR (dir - a, dir + a))
pos
colSparkRandDir a col pos dir =
randColDirSpark
(return col)
(state $ randomR (dir - a, dir + a))
pos