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
+6 -7
View File
@@ -20,6 +20,8 @@ import System.Random
updateBullet :: World -> Bullet -> (World, Maybe Bullet)
updateBullet w bu
| magV (_buVel bu) < 10
, BulBall _ <- _buPayload bu = (useBulletPayload bu (_buPos bu) w, Nothing)
| magV (_buVel bu) < 1 = (useBulletPayload bu (_buPos bu) w, Nothing)
-- have to be slightly carefull not to accelerate bullets using magnets
| otherwise = second (Just . updateBulVel) . hitEffFromBul w $ applyMagnetsToBul bu w
@@ -114,11 +116,10 @@ useBulletPayload bu = case _buPayload bu of
BulFlak -> makeFlak bu
BulFrag -> makeFragBullets
BulGas -> (`makeGasCloud` V2 0 0)
-- BulBall FlamingBall -> incBallAt
BulBall ExplosiveBall -> \p -> cWorld . lWorld . shockwaves .:~ concBall p
BulBall ElectricalBall -> makeStaticBall
BulBall FlashBall -> makeFlashBall
BulBall (FlameletBall x _) -> \p -> makeFlamelet p 0 x 10
BulBall ElectricalBall -> makeMovingEB (_buVel bu) ElectricalBall
BulBall FlashBall -> makeMovingEB (_buVel bu) FlashBall
BulBall (FlameletBall x r) -> makeMovingEB (_buVel bu) (FlameletBall x r)
makeFragBullets :: Point2 -> World -> World
makeFragBullets p w = w & cWorld . lWorld . bullets .++~ bus
@@ -134,7 +135,6 @@ makeFragBullets p w = w & cWorld . lWorld . bullets .++~ bus
& buPos .~ p
& buOldPos .~ p
& buWidth .~ 1
-- & buDamages .~ [Damage PIERCING 5 0 0 0 $ PushBackDamage 2]
makeFlak :: Bullet -> Point2 -> World -> World
makeFlak bu _ w = w & cWorld . lWorld . bullets .++~ [f x | x <- xs]
@@ -144,7 +144,6 @@ makeFlak bu _ w = w & cWorld . lWorld . bullets .++~ [f x | x <- xs]
f x = bu & buVel %~ g x
& buPayload .~ BulPlain 25
& buWidth .~ 0.5
-- & buDamages .~ [Damage PIERCING 25 0 0 0 $ PushBackDamage 2]
g x v = v +.+ x *.* normalizeV (vNormal v)
hitEffFromBul :: World -> Bullet -> (World, Bullet)
@@ -196,7 +195,7 @@ moveBullet pt = pt & buPos +~ _buVel pt & buOldPos .~ _buPos pt
stopBulletAt :: Point2 -> Bullet -> Bullet
stopBulletAt hitp pt =
pt
& buPos .~ hitp
& buPos .~ hitp + squashNormalizeV (_buPos pt - hitp)
& buOldPos .~ _buPos pt
& buVel .~ 0
-1
View File
@@ -24,7 +24,6 @@ data Bullet = Bullet
, _buPos :: Point2
, _buOldPos :: Point2
, _buWidth :: Float
-- , _buDamages :: [Damage]
}
deriving (Show, Eq, Ord, Read) --Generic, Flat)
+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)
+26
View File
@@ -3,6 +3,7 @@ module Dodge.Spark (
sparkRandDir,
randDirSpark,
randSpark,
randSparkExtraVel,
makeSpark,
) where
@@ -14,6 +15,7 @@ import Geometry
import LensHelp
import System.Random
-- should probably reduce spark speed more if it is very fast
updateSpark :: World -> Spark -> (World, Maybe Spark)
updateSpark w sk
| magV (_skVel sk) < 1 = (w, Nothing)
@@ -87,5 +89,29 @@ randSpark dt randspeed randdir pos w =
x <- randspeed
return (d, x)
randSparkExtraVel ::
Point2 ->
SparkType ->
State StdGen Float ->
State StdGen Float ->
Point2 ->
World ->
World
randSparkExtraVel v dt randspeed randdir pos w =
w
& randGen .~ g
& cWorld . lWorld . sparks
.:~ Spark
{ _skVel = v + rotateV dir (V2 speed 0)
, _skPos = pos
, _skOldPos = pos
, _skType = dt
}
where
((dir, speed), g) = (`runState` _randGen w) $ do
d <- randdir
x <- randspeed
return (d, x)
sparkRandDir :: Float -> Point2 -> Float -> World -> World
sparkRandDir a pos dir = randDirSpark (state $ randomR (dir - a, dir + a)) pos