Files
loop/src/Dodge/WorldEvent/Flash.hs
T
2022-04-10 10:48:17 +01:00

60 lines
1.9 KiB
Haskell

{- | Flashes.
projected naming conventions: three base types of light:
glare : Draws color onto surfaces (not done)
flare : coloured light drawn in space, fixed shapes
light : removal of shadows (onto surfaces)
duration (subject to modification):
flash : short, abrupt changes in alpha
glow : continuous, potentially long, fading, slow changes in alpha
flicker : potentially long, moving, abrupt changes in alpha
-}
module Dodge.WorldEvent.Flash
( explosionFlashAt
, muzFlareAt
, ptFlicker
, flareCircleAt
) where
import Dodge.Data
import Dodge.LightSource
import Dodge.WorldEvent.HelperParticle
--import Dodge.Default
import Picture
import Geometry
import LensHelp
import System.Random
muzFlareAt :: Color -> Point3 -> Float -> World -> World
muzFlareAt col tranv dir w = w & instantParticles .:~ theFlare
where
theFlare = Particle
{ _ptDraw = const $ setLayer BloomNoZWrite . translate3 tranv $ theShape
, _ptUpdate = ptSimpleTime 2
}
theShape = rotate dir . color col $ polygon
[ V2 0 0
, V2 a (-b)
, V2 c d
]
(a:b:c:d:_) = randomRs (2,20) (_randGen w)
flareCircleAt :: Color -> Float -> Point3 -> World -> World
flareCircleAt col alphax tranv = instantParticles .:~ Particle
{ _ptDraw = const . setLayer BloomNoZWrite . translate3 tranv
$ circleSolidCol (withAlpha 0 0) (withAlpha alphax col) 50
, _ptUpdate = ptSimpleTime 1
}
explosionFlashAt :: Point2 -> World -> World
explosionFlashAt p = tempLightSources .:~ tlsTimeRadFunPos 20 150 intensityFunc (addZ 20 p)
where
intensityFunc x
| x < 10 = 1 / (10 - fromIntegral x)
| otherwise = 1
ptFlicker :: Particle -> World -> World
ptFlicker pt
| _ptTimer pt `mod` 7 == 0 = tempLightSources
.:~ tlsTimeRadColPos 1 70 (0.5 *.*.* xyzV4 (_ptColor pt)) (addZ 10 $ _ptPos pt)
| otherwise = id