53 lines
1.6 KiB
Haskell
53 lines
1.6 KiB
Haskell
module Dodge.Flame (
|
|
makeFlame,
|
|
updateFlame,
|
|
) where
|
|
|
|
import Dodge.Base.Wall
|
|
import Dodge.Damage
|
|
import Dodge.Data.World
|
|
import Dodge.Flame.Size
|
|
import Dodge.SoundLogic
|
|
import Dodge.WorldEvent.Cloud
|
|
import Dodge.WorldEvent.ThingsHit
|
|
import Geometry
|
|
import LensHelp
|
|
import qualified ListHelp as List
|
|
import Picture
|
|
import RandomHelp
|
|
|
|
updateFlame :: World -> Flame -> (World, Maybe Flame)
|
|
updateFlame w pt
|
|
| _flTimer pt <= 0 = (mcloud w, Nothing)
|
|
| Just (_, Right wl) <- thit = (doupdate, Just $ reflame wl)
|
|
-- might want to move differently if we hit a creature?
|
|
| _flTimer pt <= 1 = (mcloud $ flFlicker pt doupdate
|
|
, Just mvflame)
|
|
| otherwise = (flFlicker pt doupdate, Just mvflame)
|
|
where
|
|
mcloud = makeCloudAt Smoke 200 (addZ 20 ep)
|
|
reflame wl = pt & flTimer -~ 1 & flVel %~ reflVelWallDamp 0.9 wl
|
|
doupdate =
|
|
soundContinue FlameSound sp fireLoudS (Just 2) $
|
|
damageInCircle (const $ Flaming 1 (pt ^. flOrigin)) ep r w
|
|
thit = List.safeHead $ thingsHit sp ep w
|
|
sp = _flPos pt
|
|
ep = sp + _flVel pt
|
|
mvflame = pt & flTimer -~ 1 & flPos .~ ep & flVel *~ 0.98
|
|
r = max 0 $ flameSize pt - 1
|
|
|
|
flFlicker :: Flame -> World -> World
|
|
flFlicker pt
|
|
| _flTimer pt `mod` 7 == 0 =
|
|
cWorld . lWorld . lights
|
|
.:~ LSParam (addZ 10 $ _flPos pt) 70 (0.5 *.*.* xyzV4 red)
|
|
| otherwise = id
|
|
|
|
makeFlame :: Point2 -> Point2 -> DamageOrigin -> World -> World
|
|
makeFlame pos vel d w =
|
|
w
|
|
& cWorld . lWorld . flames .:~ Flame t pos vel d
|
|
& randGen .~ g
|
|
where
|
|
(t, g) = randomR (99, 102) (_randGen w)
|