Implement simple flak and frag bullets

This commit is contained in:
2023-01-12 15:48:32 +00:00
parent 3508d9c266
commit d08b6c5727
14 changed files with 133 additions and 42 deletions
+40 -1
View File
@@ -3,6 +3,8 @@ module Dodge.Bullet (
useAmmoParams,
) where
import Dodge.Item.Weapon.Bullet
import System.Random
import Data.Foldable
import Data.Maybe
import Dodge.Base.Coordinate
@@ -27,7 +29,9 @@ updateBullet w bu = case _buDelayFraction bu of
mvBullet :: Float -> World -> Bullet -> (World, Maybe Bullet)
mvBullet x w bu
| _buTimer bu <= 0 || magV (_buVel bu) < 1 = (endspawn w, Nothing)
-- | magV (_buVel bu) < 1 = (w, Nothing)
-- | _buTimer bu <= 0 = (endspawn w, Nothing)
| magV (_buVel bu) < 1 || _buTimer bu <= 0 = (endspawn w, Nothing)
| otherwise =
second (fmap updateBulVel)
. hitEffFromBul x w
@@ -88,9 +92,44 @@ bounceDir _ = Nothing
bulletSpawn :: Bullet -> Maybe (Point2 -> World -> World)
bulletSpawn bu = case _buSpawn bu of
BulSpark -> Nothing
BulFlak -> Just (makeFlak bu)
BulFrag -> Just makeFragBullets
BulGas -> Just (flip makeGasCloud (V2 0 0))
BulBall IncBall -> Just incBallAt
BulBall ConcBall -> Just $ \p -> cWorld . lWorld . shockwaves .:~ concBall p
BulBall TeslaBall -> Just makeStaticBall
BulBall FlashBall -> Just makeFlashBall
makeFragBullets :: Point2 -> World -> World
makeFragBullets p w = w & cWorld . lWorld . instantBullets .++~ bus
where
bus = zipWith f (take 10 as) (take 10 ss)
as = randomRs (0, 2 * pi) $ _randGen w
ss = randomRs (5, 15) $ _randGen w
f a s = defaultBullet & buVel .~ s *.* (unitVectorAtAngle a)
& buDrag .~ 0.8
& buPos .~ p
& buOldPos .~ p
& buWidth .~ 1
& buDamages .~
[ Damage PIERCING 5 0 0 0 NoDamageEffect
, Damage PUSHDAM 1 0 0 0 . PushBackDamage $ 2
]
makeFlak :: Bullet -> Point2 -> World -> World
makeFlak bu _ w = w & cWorld . lWorld . instantBullets .++~ [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
& buTimer .~ 97
& buSpawn .~ BulSpark
& buWidth .~ 0.5
& buDamages .~
[ Damage PIERCING 25 0 0 0 NoDamageEffect
, Damage PUSHDAM 1 0 0 0 . PushBackDamage $ 2
]
g x v = v +.+ x *.* normalizeV (vNormal v)
hitEffFromBul ::
Float ->