Simplify shockwave damages
This commit is contained in:
+19
-21
@@ -1,6 +1,4 @@
|
||||
module Dodge.Bullet (
|
||||
updateBullet,
|
||||
) where
|
||||
module Dodge.Bullet (updateBullet) where
|
||||
|
||||
import Data.Bifunctor
|
||||
import Data.Foldable
|
||||
@@ -20,8 +18,9 @@ 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) < 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
|
||||
@@ -106,8 +105,8 @@ updateBulVel bt = bt & buVel .*.*~ _buDrag bt
|
||||
-- return $ BezierTrajectory sp tpos (mouseWorldPos (w ^. input) (w ^. wCam))
|
||||
|
||||
bounceDir :: (Point2, Either Creature Wall) -> Maybe Point2
|
||||
bounceDir (_, Right wl) | _wlBouncy wl = Just $ uncurry (-.-) (_wlLine wl)
|
||||
bounceDir (p, Left cr) | crIsArmouredFrom p cr = Just $ vNormal $ p -.- _crPos cr
|
||||
bounceDir (_, Right wl) | _wlBouncy wl = Just $ uncurry (-) (_wlLine wl)
|
||||
bounceDir (p, Left cr) | crIsArmouredFrom p cr = Just $ vNormal $ p - _crPos cr
|
||||
bounceDir _ = Nothing
|
||||
|
||||
useBulletPayload :: Bullet -> Point2 -> World -> World
|
||||
@@ -117,10 +116,12 @@ useBulletPayload bu = case _buPayload bu of
|
||||
BulFrag -> makeFragBullets
|
||||
BulGas -> (`makeGasCloud` V2 0 0)
|
||||
BulBall ExplosiveBall -> makeMovingEB (_buVel bu) ExplosiveBall
|
||||
BulBall ElectricalBall{} -> makeMovingEB (_buVel bu)
|
||||
(ElectricalBall (round $ bu ^. buPos . _1))
|
||||
BulBall ElectricalBall{} ->
|
||||
makeMovingEB
|
||||
(_buVel bu)
|
||||
(ElectricalBall (round $ bu ^. buPos . _1))
|
||||
BulBall FlashBall -> makeMovingEB (_buVel bu) FlashBall
|
||||
BulBall (FlameletBall x r) -> makeMovingEB (_buVel bu) (FlameletBall x r)
|
||||
BulBall (FlameletBall x r) -> makeMovingEB (_buVel bu) (FlameletBall x r)
|
||||
BulBall IncendiaryBall -> makeMovingEB (_buVel bu) IncendiaryBall
|
||||
|
||||
makeFragBullets :: Point2 -> World -> World
|
||||
@@ -130,7 +131,7 @@ makeFragBullets p w = w & cWorld . lWorld . bullets .++~ bus
|
||||
as = randomRs (0, 2 * pi) $ _randGen w
|
||||
ss = randomRs (5, 15) $ _randGen w
|
||||
f a s =
|
||||
defaultBullet
|
||||
defaultBullet
|
||||
& buPayload .~ BulPlain 5
|
||||
& buVel .~ s *.* unitVectorAtAngle a
|
||||
& buDrag .~ 0.8
|
||||
@@ -143,7 +144,8 @@ makeFlak bu _ w = w & cWorld . lWorld . bullets .++~ [f x | x <- xs]
|
||||
where
|
||||
s = min 10 (0.5 * magV (_buVel bu))
|
||||
xs = take 5 $ randomRs (- s, s) $ _randGen w
|
||||
f x = bu & buVel %~ g x
|
||||
f x =
|
||||
bu & buVel %~ g x
|
||||
& buPayload .~ BulPlain 25
|
||||
& buWidth .~ 0.5
|
||||
g x v = v +.+ x *.* normalizeV (vNormal v)
|
||||
@@ -171,13 +173,12 @@ setFromToDams bu p = case _buPayload bu of
|
||||
_ -> []
|
||||
where
|
||||
v = _buVel bu
|
||||
|
||||
-- f = (dmFrom .~ _buPos bu) . (dmAt .~ p) . (dmTo .~ _buPos bu +.+ _buVel bu)
|
||||
|
||||
damageThingHit :: Bullet -> (Point2, Either Creature Wall) -> World -> World
|
||||
damageThingHit bu (p, crwl) = case crwl of
|
||||
Left cr -> cWorld . lWorld . creatures . ix (_crID cr) . crDamage .++~ dams
|
||||
-- Right wl -> cWorld . lWorld . wallDamages %~ IM.insertWith (++) (_wlID wl) dams
|
||||
-- hopefully the following doesn't introduce a space leak
|
||||
Left cr -> cWorld . lWorld . creatures . ix (_crID cr) . crDamage <>~ dams
|
||||
Right wl -> cWorld . lWorld . wallDamages . at (_wlID wl) . non mempty <>~ dams
|
||||
where
|
||||
dams = setFromToDams bu p
|
||||
@@ -195,16 +196,13 @@ moveBullet :: Bullet -> Bullet
|
||||
moveBullet pt = pt & buPos +~ _buVel pt & buOldPos .~ _buPos pt
|
||||
|
||||
stopBulletAt :: Point2 -> Bullet -> Bullet
|
||||
stopBulletAt hitp pt =
|
||||
pt
|
||||
& buPos .~ hitp
|
||||
& buOldPos .~ _buPos pt
|
||||
& buVel .~ 0
|
||||
stopBulletAt hitp pt = pt & buPos .~ hitp & buOldPos .~ _buPos pt & buVel .~ 0
|
||||
|
||||
movePenBullet :: Bullet -> [(Point2, Either Creature Wall)] -> World -> (World, Bullet)
|
||||
movePenBullet bu hitstream w = case hitstream of
|
||||
[] -> (w, moveBullet bu)
|
||||
((p, crwl) : strm) | penThing crwl ->
|
||||
((p, crwl) : strm)
|
||||
| penThing crwl ->
|
||||
first (damageThingHit bu (p, crwl)) $ movePenBullet bu strm w
|
||||
_ -> expireAndDamage bu hitstream w
|
||||
|
||||
|
||||
Reference in New Issue
Block a user