Files
loop/src/Dodge/Creature/Inanimate.hs
T
2021-06-25 18:43:45 +02:00

90 lines
2.5 KiB
Haskell

{-
Inanimate objects such as lamps, barrels, etc
-}
module Dodge.Creature.Inanimate
where
import Dodge.Data
import Dodge.Creature.Picture
--import Dodge.Creature.Stance.Data
import Dodge.Creature.State.Data
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 IntMapHelp as IM
import Geometry
import Control.Lens
defaultInanimate :: Creature
defaultInanimate = defaultCreature & crActionPlan .~ Inanimate
lamp :: Creature
lamp = defaultInanimate
{ _crUpdate = initialiseLamp
, _crHP = 100
, _crPict = picAtCrPos lampPic
, _crRad = 3
, _crMass = 3
}
lampPic :: Picture
lampPic = pictures
[ setDepth (0.09) $ color white $ p
, setDepth (0) $ color yellow $ p
]
where
p = pictures [circleSolid 3, polygon $ rectNSEW 5 0 5 0]
initialiseLamp :: CRUpdate
initialiseLamp w (f,g) cr = ( (addLS . f , g), Just $ cr & crUpdate .~ updateLamp i)
where
i = IM.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 .~ f cPos
where
cPos = _crPos cr
f (x,y) = (x,y,0)
internalUpdate cr
| _crHP cr < 0 = Nothing
| otherwise = Just $ doDamage cr
barrel :: Creature
barrel = defaultInanimate
{ _crUpdate = updateBarrel
, _crHP = 500
, _crPict = picAtCrPos $ onLayer CrLayer $ pictures
[ color orange $ circleSolid 10
, color (greyN 0.5) $ circleSolid 8
]
, _crState = defaultState
{_crSpState = Barrel []
}
, _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
}
explosiveBarrel :: Creature
explosiveBarrel = defaultInanimate
{ _crUpdate = updateExpBarrel
, _crHP = 400
, _crPict = picAtCrPos $ onLayer CrLayer $ pictures
[ color red $ circleSolid 8
, color orange $ circleSolid 10
]
, _crState = defaultState
{_crSpState = Barrel []
}
, _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
,_crApplyDamage = \_ c -> (id, c)
}