Cleanup, redo damage direction

This commit is contained in:
2025-06-08 20:40:58 +01:00
parent 5b1e4fba4e
commit 70c78824f3
12 changed files with 105 additions and 147 deletions
+19 -39
View File
@@ -18,17 +18,7 @@ import LensHelp
import Picture
import RandomHelp
makeFlamelet ::
-- | Position
Point2 ->
-- | Velocity
Point2 ->
-- | Size
Float ->
-- | Timer
Int ->
World ->
World
makeFlamelet :: Point2 -> Point2 -> Float -> Int -> World -> World
makeFlamelet p v s t w =
w
& randGen .~ g
@@ -53,35 +43,31 @@ updateEnergyBall w eb
p = eb ^. ebPos + eb ^. ebVel
(bp, bv) = fromMaybe (p, eb ^. ebVel) $ bouncePoint (const True) 0 (eb ^. ebPos) p w
incBallAt :: Point2 -> World -> World
incBallAt p = cWorld . lWorld . energyBalls
.:~ EnergyBall
{ _ebVel = 0
, _ebPos = p
, _ebTimer = 20
, _ebEff = FlamingBall
}
makeFlashBall :: Point2 -> World -> World
makeFlashBall p =
energyBallAt :: EnergyBallType -> Point2 -> World -> World
energyBallAt ebt p =
cWorld . lWorld . energyBalls
.:~ EnergyBall
{ _ebVel = 0
, _ebPos = p
, _ebTimer = 20
, _ebEff = FlashBall
, _ebEff = ebt
}
incBallAt :: Point2 -> World -> World
incBallAt = energyBallAt (FlameletBall 5 0)
makeFlashBall :: Point2 -> World -> World
makeFlashBall = energyBallAt FlashBall
ebFlicker :: EnergyBall -> World -> World
ebFlicker pt
| _ebTimer pt `mod` 7 == 0 =
cWorld . lWorld . lights
.:~ LSParam (addZ 20 $ _ebPos pt) 70 (0.5 *.*.* xyzV4 (ebColor pt))
.:~ LSParam (addZ 20 $ _ebPos pt) 70 (0.5 * xyzV4 (ebColor pt))
| otherwise = id
ebColor :: EnergyBall -> Color
ebColor eb = case eb ^. ebEff of
FlamingBall -> red
FlameletBall{} -> red
ElectricalBall -> cyan
ExplosiveBall -> yellow
@@ -93,28 +79,22 @@ damageCircle sp dt w =
& cWorld . lWorld . wallDamages %~ addwalldamages
& cWorld . lWorld . creatures %~ addcreaturedamages
where
r = 5
addwalldamages wlds = foldl' (damageWlCircle wldam) wlds wlstodam
addwalldamages wlds = foldl' (damageWlCircle dam) wlds wlstodam
addcreaturedamages crs = foldl' (damageCrCircle dam) crs crstodam
wlstodam = wlsHitRadial sp r w
wldam p = ebtToDamage p dt
addcreaturedamages crs = foldl' (damageCrCircle crdam) crs crstodam
crdam = ebtToDamage sp dt
crstodam = crsHitRadial sp r w
r = fromMaybe 5 $ dt ^? fbSize
dam = ebtToDamage sp dt
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
damageWlCircle ::
(Point2 -> Damage) ->
IM.IntMap [Damage] ->
(Point2, Wall) ->
IM.IntMap [Damage]
damageWlCircle f wldams (p, wl) = IM.insertWith (++) (_wlID wl) [f p] wldams
damageWlCircle :: Damage -> IM.IntMap [Damage] -> (Point2, Wall) -> IM.IntMap [Damage]
damageWlCircle dam wls (_, wl) = wls & at (_wlID wl) . non mempty .:~ dam
damageCrCircle :: Damage -> IM.IntMap Creature -> (Point2, Creature) -> IM.IntMap Creature
damageCrCircle crdam crs (_, cr) = crs & ix (_crID cr) . crState . csDamage .:~ crdam
damageCrCircle dam crs (_, cr) = crs & ix (_crID cr) . crState . csDamage .:~ dam