Work on energy balls

This commit is contained in:
2025-06-08 23:31:44 +01:00
parent 7e8eaaa34e
commit 3dce133f30
5 changed files with 144 additions and 95 deletions
+23 -1
View File
@@ -5,6 +5,7 @@ module Dodge.EnergyBall (
incBallAt,
makeFlashBall,
makeFlamelet,
makeMovingEB,
) where
import qualified Data.IntMap.Strict as IM
@@ -12,6 +13,7 @@ import Data.List (foldl')
import Data.Maybe
import Dodge.Base.Collide
import Dodge.Data.World
import Dodge.Spark
import Dodge.WorldEvent.ThingsHit
import Geometry
import LensHelp
@@ -36,13 +38,23 @@ updateEnergyBall :: World -> EnergyBall -> (World, Maybe EnergyBall)
updateEnergyBall w eb
| _ebTimer eb <= 0 = (w, Nothing)
| otherwise =
( ebFlicker eb $ damageCircle (_ebPos eb) (_ebEff eb) w
( ebEffect eb . ebFlicker eb $ damageCircle (_ebPos eb) (_ebEff eb) w
, Just $ eb & ebTimer -~ 1 & ebPos .~ bp & ebVel .~ 0.85 * bv
)
where
p = eb ^. ebPos + eb ^. ebVel
(bp, bv) = fromMaybe (p, eb ^. ebVel) $ bouncePoint (const True) 0 (eb ^. ebPos) p w
ebEffect :: EnergyBall -> World -> World
ebEffect eb = case _ebEff eb of
ElectricalBall -> randSparkExtraVel
(_ebVel eb)
ElectricSpark
(state (randomR (3, 6)))
(state (randomR (0, 2 * pi)))
(_ebPos eb)
_ -> id
energyBallAt :: EnergyBallType -> Point2 -> World -> World
energyBallAt ebt p =
cWorld . lWorld . energyBalls
@@ -53,6 +65,16 @@ energyBallAt ebt p =
, _ebEff = ebt
}
makeMovingEB :: Point2 -> EnergyBallType -> Point2 -> World -> World
makeMovingEB v ebt p =
cWorld . lWorld . energyBalls
.:~ EnergyBall
{ _ebVel = v
, _ebPos = p
, _ebTimer = 20
, _ebEff = ebt
}
incBallAt :: Point2 -> World -> World
incBallAt = energyBallAt (FlameletBall 5 0)