Rethink damage data type, work on damage sensors

This commit is contained in:
2022-03-13 09:27:35 +00:00
parent d340fd73c3
commit 06a501ff88
30 changed files with 356 additions and 240 deletions
+36 -22
View File
@@ -26,8 +26,9 @@ bulHitCr bt p cr w
sp = head $ _ptTrail bt
bulVel = _ptVel bt
ep = sp +.+ bulVel
mvDams = [ PushDam 1 $ 2 *.* bulVel ]
addDamage = creatures . ix cid . crState . crDamage .++~ (Piercing 100 sp p ep : mvDams)
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
p1 = p +.+ 2 *.* squashNormalizeV (p -.- _crPos cr)
@@ -43,8 +44,9 @@ bulBounceArmCr' bt p cr w
sp = head $ _ptTrail bt
bulVel = _ptVel bt
ep = sp +.+ bulVel
mvDams = [ PushDam 1 $ 2 *.* bulVel ]
addDamage = creatures . ix cid . crState . crDamage .++~ (Piercing 100 sp p ep : mvDams)
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)
@@ -60,11 +62,12 @@ bulPenCr' bt p cr w = w
& instantParticles .:~ piercer
& bulletHitSound ep
& creatures . ix cid . crState . crDamage .++~
[Piercing 50 sp p ep
,Blunt 50 sp p ep
,TorqueDam 1 d1
,PushDam 1 $ 3 *.* (ep -.- sp)
]
damageGamut 50 50 d1 sp p ep
-- [Damage Piercing 50 sp p ep NoDamageEffect
-- ,Damage Blunt 50 sp p ep NoDamageEffect
-- ,Damage TorqueDam 1 sp p ep $ TorqueDamage d1
-- ,Damage PushDam 1 sp p ep . PushBackDamage $ 3 *.* (ep -.- sp)
-- ]
where
(d1,_) = randomR (-0.7,0.7) $ _randGen w
cid = _crID cr
@@ -78,23 +81,33 @@ piercing, blunt, twisting and pushback damage all applied. -}
hvBulHitCr :: Particle -> Point2 -> Creature -> World -> World
hvBulHitCr bt p cr w = w
& creatures . ix cid . crState . crDamage .++~
[Piercing 200 sp p ep
,Blunt 100 sp p ep
,TorqueDam 1 d1
,PushDam 1 $ 3 *.* (ep -.- sp)
]
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
cid = _crID cr
sp = head $ _ptTrail bt
ep = sp +.+ _ptVel bt
damageGamut :: Int -> Int -> Float -> Point2 -> Point2 -> Point2
-> [Damage]
damageGamut pdam bdam tor sp p ep =
[Damage Piercing pdam sp p ep NoDamageEffect
,Damage Blunt bdam sp p ep NoDamageEffect
,Damage TorqueDam 1 sp p ep $ TorqueDamage tor
,Damage PushDam 1 sp p ep . PushBackDamage $ 3 *.* (ep -.- sp)
]
{- | Create a flamelet when hitting a creature. -}
bulIncCr :: Particle -> Point2 -> Creature -> World -> World
bulIncCr bt p cr w = w
& makeFlamelet p 20 v Nothing 3 20
& bulletHitSound p
& creatures . ix cid . crState . crDamage .:~ Piercing 60 sp p ep
& creatures . ix cid . crState . crDamage .:~ Damage Piercing 60 sp p ep NoDamageEffect
where
cid = _crID cr
sp = head $ _ptTrail bt
@@ -102,7 +115,8 @@ bulIncCr bt p cr w = w
v = evalState (randInCirc 1) $ _randGen w
{- | Creates a shockwave when hitting a creature. -}
bulConCr :: Particle -> Point2 -> Creature -> World -> World
bulConCr bt p cr = over (creatures . ix cid . crState . crDamage) (Blunt 10 sp p ep :)
bulConCr bt p cr
= over (creatures . ix cid . crState . crDamage) (Damage Blunt 10 sp p ep NoDamageEffect :)
. makeShockwaveAt [] p 15 4 1 white
. bulletHitSound p
where
@@ -111,13 +125,13 @@ bulConCr bt p cr = over (creatures . ix cid . crState . crDamage) (Blunt 10 sp p
ep = sp +.+ _ptVel bt
{- | Hitting wall effects: create a spark, damage blocks. -}
bulHitWall :: Particle -> Point2 -> Wall -> World -> World
bulHitWall bt p = damageWall (Piercing 100 sp p ep)
bulHitWall bt p = damageWall (Damage Piercing 100 sp p ep NoDamageEffect)
where
ep = sp +.+ _ptVel bt
sp = head $ _ptTrail bt
{- | Bounce off walls, do damage to blocks. -}
bulBounceWall :: Particle -> Point2 -> Wall -> World -> World
bulBounceWall bt p wl = damageWall (Blunt 50 sp p ep) wl
bulBounceWall bt p wl = damageWall (Damage Blunt 50 sp p ep NoDamageEffect) wl
. over instantParticles (bouncer :)
where
ep = sp +.+ _ptVel bt
@@ -137,7 +151,7 @@ bulIncWall
-> Wall
-> World
-> World
bulIncWall bt p wl = damageWall (Blunt 50 sp p ep) wl
bulIncWall bt p wl = damageWall (Damage Blunt 50 sp p ep NoDamageEffect) wl
. makeFlamelet pOut 20 reflectVel Nothing 3 20
where
ep = sp +.+ _ptVel bt
@@ -152,7 +166,7 @@ bulConWall
-> Wall
-> World
-> World
bulConWall bt p wl = damageWall (Blunt 10 sp p ep) wl .
bulConWall bt p wl = damageWall (Damage Blunt 10 sp p ep NoDamageEffect) wl .
makeShockwaveAt [] p 15 4 1 white
where
ep = sp +.+ _ptVel bt
@@ -164,8 +178,8 @@ hvBulHitWall
-> Wall
-> World
-> World
hvBulHitWall bt p wl w = damageWall (Piercing 200 sp p ep) wl
. damageWall (Blunt 100 sp p ep) wl
hvBulHitWall bt p wl w = damageWall (Damage Piercing 200 sp p ep NoDamageEffect) wl
. damageWall (Damage Blunt 100 sp p ep NoDamageEffect) wl
$ set randGen g $ foldr ($) w (sparks pOut sv)
where
ep = sp +.+ _ptVel bt
+4 -2
View File
@@ -29,7 +29,8 @@ createBarrelSpark pos dir maycid time colid = instantParticles .:~ BulletPt
, _ptHitEff = destroyOnImpact sparkEff noEff
}
where
sparkEff bt p cr = creatures . ix (_crID cr) . crState . crDamage .:~ SparkDam 1 sp p ep
sparkEff bt p cr = creatures . ix (_crID cr) . crState . crDamage
.:~ Damage SparkDam 1 sp p ep NoDamageEffect
where
sp = head (_ptTrail bt)
ep = sp +.+ _ptVel bt
@@ -54,7 +55,8 @@ colSparkRandDir randDir time col pos baseDir w = w
, _ptTimer = time
, _ptHitEff = destroyOnImpact sparkEff noEff
}
sparkEff bt p cr = creatures . ix (_crID cr) . crState . crDamage .:~ SparkDam 1 sp p ep
sparkEff bt p cr = creatures . ix (_crID cr) . crState . crDamage
.:~ Damage SparkDam 1 sp p ep NoDamageEffect
where
sp = head (_ptTrail bt)
ep = sp +.+ _ptVel bt
+5 -3
View File
@@ -12,8 +12,8 @@ import Dodge.RandomHelp
import Picture
import Geometry
import qualified IntMapHelp as IM
import LensHelp
import Control.Lens
import System.Random
import Control.Monad.State
import Data.Function (on)
@@ -44,7 +44,8 @@ moveTeslaArc
moveTeslaArc p d w pt
| t == 2 =
(foldr damCrs w hitCrs & randGen .~ g & colSpark 8 nc q2 (argV sv)
& damThingHitWith (Electrical 50) q1 ((2 *.* q2) -.- q1) thHit
& damThingHitWith (\p1 p2 p3 -> Damage Electrical 50 p1 p2 p3 NoDamageEffect)
q1 ((2 *.* q2) -.- q1) thHit
, Just $ pt & ptTimer -~ 1 & ptPoints .~ ps'
)
| t < 1 = (w , Nothing)
@@ -62,7 +63,8 @@ moveTeslaArc p d w pt
f1 (E3x1 cr) = Just $ _crID cr
f1 _ = Nothing
hitCrs = mapMaybe f1 $ take 14 $ crsLightChain p d 0 w
damCrs cid = over (creatures . ix cid . crState . crDamage) (Electrical 5 cpos cpos cpos :)
damCrs cid = creatures . ix cid . crState . crDamage
.:~ Damage Electrical 5 cpos cpos cpos NoDamageEffect
where
cpos = _crPos (_creatures w IM.! cid)
q1 = last $ init ps'