Make creature update an external function
This commit is contained in:
@@ -3,48 +3,17 @@ module Dodge.Creature.Lamp
|
||||
, colorLamp
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Material.Sound
|
||||
import Dodge.Default
|
||||
import Dodge.LightSource
|
||||
import Dodge.WorldEvent.Flash
|
||||
import Dodge.WorldEvent.Sound
|
||||
import Dodge.Creature.State
|
||||
import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
import LensHelp
|
||||
|
||||
import Geometry.Data
|
||||
colorLamp
|
||||
:: Point3 -- color of lamp
|
||||
-> Float -- height of lamp
|
||||
-> Creature
|
||||
colorLamp col h = defaultInanimate
|
||||
{ _crUpdate = initialiseColorLamp col h
|
||||
, _crHP = 100
|
||||
, _crType = Lampoid h
|
||||
{ _crHP = 100
|
||||
, _crType = Lampoid h col Nothing
|
||||
, _crRad = 3
|
||||
, _crMass = 3
|
||||
}
|
||||
|
||||
lamp :: Float -> Creature
|
||||
lamp = colorLamp 0.75
|
||||
|
||||
initialiseColorLamp :: Point3 -> Float -> Creature -> World -> World
|
||||
initialiseColorLamp col h cr w = w
|
||||
& lightSources . at lsid ?~ lsColPosID col (addZ h $ _crPos cr) lsid
|
||||
& creatures . ix (_crID cr) . crUpdate .~ updateLamp h lsid
|
||||
where
|
||||
lsid = IM.newKey $ _lightSources w
|
||||
|
||||
updateLamp :: Float -> Int -> Creature -> World -> World
|
||||
updateLamp h i cr w
|
||||
| _crHP cr < 0 = w
|
||||
& explosionFlashAt cpos
|
||||
& originsIDsAt [MaterialSound Glass n | n <- [0,1,2]] (destroyMatS Glass) cpos
|
||||
& lightSources . at i .~ Nothing
|
||||
& creatures . at cid .~ Nothing
|
||||
| otherwise = w
|
||||
& lightSources . ix i . lsParam . lsPos .~ addZ h cpos
|
||||
& doDamage cr
|
||||
where
|
||||
cpos = _crPos cr
|
||||
cid = _crID cr
|
||||
|
||||
Reference in New Issue
Block a user