Files
loop/src/Dodge/Lampoid.hs
T

36 lines
1.2 KiB
Haskell

module Dodge.Lampoid where
import Dodge.Creature.State
import Dodge.Data.World
import Dodge.LightSource
import Dodge.Material.Sound
import Dodge.WorldEvent.Flash
import Dodge.WorldEvent.Sound
import Geometry
import qualified IntMapHelp as IM
import LensHelp
updateLampoid :: Creature -> World -> World
updateLampoid cr w = case cr ^?! crType . lampLSID of
Nothing ->
let i = IM.newKey (w ^. cWorld . lWorld . lightSources)
in w & cWorld . lWorld . lightSources %~ IM.insert i (lsColPosID lcol (addZ h cpos) i)
& cWorld . lWorld . creatures . ix (_crID cr) . crType . lampLSID ?~ i
Just i
| _crHP cr < 0 ->
w
& explosionFlashAt cpos
& originsIDsAt [MaterialSound Glass n | n <- [0, 1, 2]] (destroyMatS Glass) cpos
& cWorld . lWorld . lightSources . at i .~ Nothing
& cWorld . lWorld . creatures . at cid .~ Nothing
| otherwise ->
w
& cWorld . lWorld . lightSources . ix i . lsParam . lsPos .~ addZ h cpos
& doDamage cr
where
cpos = _crPos cr
cid = _crID cr
crtype = _crType cr
h = _lampHeight crtype
lcol = _lampColor crtype