83 lines
2.3 KiB
Haskell
83 lines
2.3 KiB
Haskell
{-
|
|
Inanimate objects such as lamps, barrels, etc
|
|
-}
|
|
module Dodge.Creature.Inanimate
|
|
where
|
|
import Dodge.Data
|
|
import Dodge.Creature.Stance.Data
|
|
import Dodge.Creature.State.Data
|
|
import Dodge.Creature.Impulse.Data
|
|
import Dodge.Base
|
|
import Dodge.Picture.Layer
|
|
import Dodge.Default
|
|
import Dodge.Creature.State
|
|
import Dodge.LightSources
|
|
import Dodge.WorldEvent.Flash
|
|
import Dodge.WorldEvent.Sound
|
|
import Dodge.Creature.Update hiding (CRUpdate)
|
|
import Picture
|
|
|
|
import qualified Data.IntMap.Strict as IM
|
|
import Control.Lens
|
|
|
|
defaultInanimate = defaultCreature & crActionPlan .~ Inanimate
|
|
|
|
lamp :: Creature
|
|
lamp = defaultInanimate
|
|
{ _crUpdate = initialiseLamp
|
|
, _crHP = 100
|
|
, _crPict = \ _ -> onLayer CrLayer $ color white $ circleSolid 3
|
|
, _crRad = 3
|
|
, _crMass = 3
|
|
}
|
|
|
|
initialiseLamp :: CRUpdate
|
|
initialiseLamp w (f,g) cr = ( (addLS . f , g), Just $ cr & crUpdate .~ updateLamp i)
|
|
where
|
|
i = newKey $ _lightSources $ f w -- to give different lights different keys
|
|
addLS = over lightSources (IM.insert i (lightAt (_crPos cr) i))
|
|
|
|
updateLamp :: Int -> CRUpdate
|
|
updateLamp i = unrandUpdate handleLS internalUpdate
|
|
where
|
|
handleLS cr w
|
|
| _crHP cr < 0 = explosionFlashAt cPos
|
|
$ mkSoundBreakGlass cPos w & lightSources %~ IM.delete i
|
|
| otherwise = w & lightSources . ix i . lsPos .~ cPos
|
|
where
|
|
cPos = _crPos cr
|
|
internalUpdate cr
|
|
| _crHP cr < 0 = Nothing
|
|
| otherwise = Just $ doDamage cr
|
|
|
|
barrel :: Creature
|
|
barrel = defaultInanimate
|
|
{ _crUpdate = updateBarrel
|
|
, _crHP = 500
|
|
, _crPict = \ _ -> onLayer CrLayer $ pictures
|
|
[ color orange $ circleSolid 10
|
|
, color (greyN 0.5) $ circleSolid 8
|
|
]
|
|
, _crState = defaultState
|
|
{_goals = [[Wait]]
|
|
,_crSpState = Barrel []
|
|
}
|
|
, _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
|
|
}
|
|
|
|
explosiveBarrel :: Creature
|
|
explosiveBarrel = defaultInanimate
|
|
{ _crUpdate = updateExpBarrel
|
|
, _crHP = 400
|
|
, _crPict = \ _ -> onLayer CrLayer $ pictures
|
|
[ color red $ circleSolid 8
|
|
, color orange $ circleSolid 10
|
|
]
|
|
, _crState = defaultState
|
|
{_goals = [[Wait]]
|
|
,_crSpState = Barrel []
|
|
}
|
|
, _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
|
|
,_crApplyDamage = \_ c -> (id, c)
|
|
}
|