Add electrical bullets

This commit is contained in:
2022-03-22 21:45:08 +00:00
parent bda65968b0
commit f030d8264f
10 changed files with 202 additions and 57 deletions
+69 -20
View File
@@ -16,12 +16,17 @@ import LensHelp
import System.Random
import Control.Monad.State
-- | Basic bullet hit creature effect.
bulHitCr :: Particle -> Point2 -> Creature -> World -> World
bulHitCr bt p cr w
| crIsArmouredFrom p cr
= colSpark 8 (_ptColor bt) p1 (argV (p1 -.- p)) $ addDamageArmoured w
| otherwise = addDamage . bulletHitSound p $ w
crArmourSplit
:: (Particle -> Point2 -> Creature -> World -> World) -- | normal effect
-> (Particle -> Point2 -> Creature -> World -> World) -- | armoured effect
-> Particle -> Point2 -> Creature -> World -> World
crArmourSplit normalf armourf bt p cr
| crIsArmouredFrom p cr = armourf bt p cr
| otherwise = normalf bt p cr
basicHitCr :: Particle -> Point2 -> Creature -> World -> World
basicHitCr bt p cr = addDamage . bulletHitSound p
where
sp = head $ _ptTrail bt
bulVel = _ptVel bt
@@ -29,24 +34,27 @@ bulHitCr bt p cr w
mvDams = [ Damage PushDam 1 sp p ep . PushBackDamage $ 2 *.* bulVel ]
addDamage = creatures . ix cid . crState . crDamage .++~
(Damage Piercing 100 sp p ep NoDamageEffect : mvDams)
cid = _crID cr
-- | Basic bullet hit creature effect.
basicHitArmour :: Particle -> Point2 -> Creature -> World -> World
basicHitArmour bt p cr w = colSpark 8 (_ptColor bt) p1 (argV (p1 -.- p)) $ addDamageArmoured w
where
sp = head $ _ptTrail bt
bulVel = _ptVel bt
ep = sp +.+ bulVel
mvDams = [ Damage PushDam 1 sp p ep . PushBackDamage $ 2 *.* bulVel ]
addDamageArmoured = creatures . ix cid . crState . crDamage .++~ mvDams
cid = _crID cr
p1 = p +.+ 2 *.* squashNormalizeV (p -.- _crPos cr)
bulletHitSound :: Point2 -> World -> World
bulletHitSound p = soundMultiFrom [CrHitSound 0] p hit1S (Just 10)
{- | Bounce off armoured creatures, otherwise do damage. -}
bulBounceArmCr' :: Particle -> Point2 -> Creature -> World -> World
bulBounceArmCr' bt p cr w
| crIsArmouredFrom p cr = addBouncer . addDamageArmoured $ w
| otherwise = addDamage . bulletHitSound p $ w
bounceArmour :: Particle -> Point2 -> Creature -> World -> World
bounceArmour bt p cr = addBouncer . addDamageArmoured
where
sp = head $ _ptTrail bt
bulVel = _ptVel bt
ep = sp +.+ bulVel
mvDams = [ Damage PushDam 1 sp p ep . PushBackDamage $ 2 *.* bulVel ]
addDamage = creatures . ix cid . crState . crDamage .++~
(Damage Piercing 100 sp p ep NoDamageEffect : mvDams)
addDamageArmoured = creatures . ix cid . crState . crDamage .++~ mvDams
cid = _crID cr
newDir = squashNormalizeV (p -.- _crPos cr)
@@ -56,6 +64,16 @@ bulBounceArmCr' bt p cr w
bouncer = (aBulAt Nothing id (Just (_ptColor bt)) Nothing pOut reflectVel (_btDrag bt)
(_ptHitEff bt) (_ptWidth bt)
) {_ptTimer = _ptTimer bt - 1}
-- | Basic bullet hit creature effect.
bulHitCr :: Particle -> Point2 -> Creature -> World -> World
bulHitCr = crArmourSplit basicHitCr basicHitArmour
bulletHitSound :: Point2 -> World -> World
bulletHitSound p = soundMultiFrom [CrHitSound 0] p hit1S (Just 10)
{- | Bounce off armoured creatures, otherwise do damage. -}
bulBounceArmCr :: Particle -> Point2 -> Creature -> World -> World
bulBounceArmCr = crArmourSplit basicHitCr bounceArmour
{- | Bullet pass through creatures. -}
bulPenCr' :: Particle -> Point2 -> Creature -> World -> World
bulPenCr' bt p cr w = w
@@ -77,11 +95,6 @@ hvBulHitCr :: Particle -> Point2 -> Creature -> World -> World
hvBulHitCr bt p cr w = w
& creatures . ix cid . crState . crDamage .++~
damageGamut 200 100 d1 sp p ep
-- [Piercing 200 sp p ep
-- ,Blunt 100 sp p ep
-- ,TorqueDam 1 d1
-- ,PushDam 1 $ 3 *.* (ep -.- sp)
-- ]
& bulletHitSound ep
where
(d1,_) = randomR (-0.7,0.7) $ _randGen w
@@ -97,6 +110,42 @@ damageGamut pdam bdam tor sp p ep =
,Damage PushDam 1 sp p ep . PushBackDamage $ 3 *.* (ep -.- sp)
]
bulletDestroySpawn :: (Point2 -> Particle)
-> Particle
-> [(Point2, Either Creature Wall)]
-> World
-> (World, Maybe Particle)
bulletDestroySpawn f = destroyOnImpact (bulDestroyCr f) (bulDestroyWall f)
{- | Create a flamelet when hitting a creature. -}
bulDestroyCr :: (Point2 -> Particle) -> Particle -> Point2 -> Creature -> World -> World
bulDestroyCr f bt p cr w = w
& instantParticles .:~ (f v & ptPos .~ p)
& bulletHitSound p
& creatures . ix cid . crState . crDamage .:~ Damage Piercing 60 sp p ep NoDamageEffect
where
cid = _crID cr
sp = head $ _ptTrail bt
ep = sp +.+ _ptVel bt
v = evalState (randInCirc 1) $ _randGen w
{- | Create flamelet on wall. -}
bulDestroyWall
:: (Point2 -> Particle)
-> Particle
-> Point2 -- Impact point
-> Wall
-> World
-> World
bulDestroyWall f bt p wl = damageWall (Damage Blunt 50 sp p ep NoDamageEffect) wl
. (instantParticles .:~ (f reflectVel & ptPos .~ pOut))
where
ep = sp +.+ _ptVel bt
sp = head $ _ptTrail bt
pOut = p +.+ squashNormalizeV (sp -.- p)
wallV = uncurry (-.-) (_wlLine wl)
reflectVel = squashNormalizeV $ reflectIn wallV (_ptVel bt)
{- | Create a flamelet when hitting a creature. -}
bulIncCr :: Particle -> Point2 -> Creature -> World -> World
bulIncCr bt p cr w = w