Files
loop/src/Dodge/Wall/DamageEffect.hs
T
2022-06-03 10:18:47 +01:00

49 lines
1.5 KiB
Haskell

module Dodge.Wall.DamageEffect where
import Dodge.Data
import Dodge.Particle.Spark
import Dodge.Particle.Bullet.Spawn
import Dodge.Wall.Reflect
import Dodge.Wall.Dust
import Geometry
import LensHelp
import Control.Monad.State
defaultWallDamage :: Damage -> Wall -> World -> World
defaultWallDamage dm wl = wallDamageEffect dm wl . case _dmType dm of
LASERING -> colSparkRandDir 0.2 8 lSparkCol outTo (reflDirWall sp p wl)
PIERCING -> colSparkRandDir 0.2 8 pSparkCol outTo (reflDirWall sp p wl) . wlDustAt wl outTo
BLUNT -> wlDustAt wl outTo
EXPLOSIVE -> id
CUTTING -> id
SPARKING -> id
FLAMING -> id
ELECTRICAL -> id
CONCUSSIVE -> id
TORQUEDAM -> id
PUSHDAM -> id
POISONDAM -> id
ENTERREMENT -> id
where
sp = _dmFrom dm
p = _dmAt dm
outTo = p +.+ squashNormalizeV (sp -.- p)
pSparkCol = V4 5 1 0.5 2
lSparkCol = V4 20 (-5) 0 1
wallDamageEffect :: Damage -> Wall -> World -> World
wallDamageEffect dm wl w = case _dmEffect dm of
BounceBullet bt -> w & instantParticles .:~ thebouncer
where
reflectVel = reflVelWall wl (_ptVel bt)
thebouncer = aBulAt Nothing id (Just (_ptColor bt)) Nothing pOut reflectVel (_btDrag bt) (_ptHitEff bt) (_ptWidth bt)
& ptTimer .~ _ptTimer bt - 1
pOut = p +.+ squashNormalizeV (sp -.- p)
p = _dmAt dm
sp = _dmFrom dm
DamageSpawn f -> w & instantParticles .:~ thepart
& randGen .~ g
where
(thepart,g) = runState (f (Right wl) dm) $ _randGen w
_ -> w