Fix bug in flame wall damages, cleanup

This commit is contained in:
2025-06-08 14:16:59 +01:00
parent 4c3a3d83da
commit 5b1e4fba4e
16 changed files with 93 additions and 253 deletions
+33 -49
View File
@@ -1,17 +1,18 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.EnergyBall
( updateEnergyBall
, incBallAt
, makeFlashBall
, makeFlamelet
) where
import Data.List (foldl')
import Dodge.WorldEvent.ThingsHit
module Dodge.EnergyBall (
updateEnergyBall,
incBallAt,
makeFlashBall,
makeFlamelet,
) where
import qualified Data.IntMap.Strict as IM
import Dodge.Base.Collide
import Data.List (foldl')
import Data.Maybe
import Dodge.Base.Collide
import Dodge.Data.World
import Dodge.WorldEvent.ThingsHit
import Geometry
import LensHelp
import Picture
@@ -28,19 +29,18 @@ makeFlamelet ::
Int ->
World ->
World
makeFlamelet (V2 x y) vel s t w =
makeFlamelet p v s t w =
w
& randGen .~ g
& cWorld . lWorld . energyBalls
.:~ EnergyBall
{ _ebVel = vel
, _ebPos = V2 x y
{ _ebVel = v
, _ebPos = p
, _ebTimer = t
, _ebEff = FlameletBall s
, _ebRot = rot
, _ebEff = FlameletBall s a
}
where
(rot, g) = randomR (0, 3) $ _randGen w
(a, g) = randomR (0, 3) $ _randGen w
updateEnergyBall :: World -> EnergyBall -> (World, Maybe EnergyBall)
updateEnergyBall w eb
@@ -51,42 +51,26 @@ updateEnergyBall w eb
)
where
p = eb ^. ebPos + eb ^. ebVel
(bp,bv) = fromMaybe (p,eb^.ebVel) $ bouncePoint (const True) 0 (eb ^. ebPos) p w
-- (bp,bv) = fromMaybe (p,eb^.ebVel) $ bouncePoint (const True) 0.5 (eb ^. ebPos) p w
(bp, bv) = fromMaybe (p, eb ^. ebVel) $ bouncePoint (const True) 0 (eb ^. ebPos) p w
incBallAt :: Point2 -> World -> World
incBallAt p w =
w & cWorld . lWorld . energyBalls .:~ theincball
& randGen .~ g
where
(theincball, g) = runState thestate (_randGen w)
thestate = do
rot <- state $ randomR (0, 3)
return
EnergyBall
{ _ebVel = 0
, _ebPos = p
, _ebTimer = 20
, _ebEff = FlamingBall
, _ebRot = rot
}
incBallAt p = cWorld . lWorld . energyBalls
.:~ EnergyBall
{ _ebVel = 0
, _ebPos = p
, _ebTimer = 20
, _ebEff = FlamingBall
}
makeFlashBall :: Point2 -> World -> World
makeFlashBall p w =
w & cWorld . lWorld . energyBalls .:~ theincball
& randGen .~ g
where
(theincball, g) = runState thestate (_randGen w)
thestate = do
rot <- state $ randomR (0, 3)
return
EnergyBall
{ _ebVel = 0
, _ebPos = p
, _ebTimer = 20
, _ebEff = FlashBall
, _ebRot = rot
}
makeFlashBall p =
cWorld . lWorld . energyBalls
.:~ EnergyBall
{ _ebVel = 0
, _ebPos = p
, _ebTimer = 20
, _ebEff = FlashBall
}
ebFlicker :: EnergyBall -> World -> World
ebFlicker pt
@@ -98,7 +82,7 @@ ebFlicker pt
ebColor :: EnergyBall -> Color
ebColor eb = case eb ^. ebEff of
FlamingBall -> red
FlameletBall {} -> red
FlameletBall{} -> red
ElectricalBall -> cyan
ExplosiveBall -> yellow
FlashBall -> white
@@ -120,7 +104,7 @@ damageCircle sp dt w =
ebtToDamage :: Point2 -> EnergyBallType -> Damage
ebtToDamage p = \case
FlamingBall -> Flaming 10
FlameletBall _ -> Flaming 1
FlameletBall {} -> Flaming 1
ElectricalBall -> Electrical 10
ExplosiveBall -> Explosive 10 p
FlashBall -> Flashing 10 p