Add destroyable lighting
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
module Dodge.Creature.Inanimate
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Default
|
||||
import Dodge.CreatureState
|
||||
import Dodge.LightSources
|
||||
|
||||
import Dodge.Creature.Update hiding (CRUpdate)
|
||||
|
||||
import Picture
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
|
||||
lamp :: Creature
|
||||
lamp = defaultCreature
|
||||
{ _crUpdate = initialiseLamp
|
||||
, _crHP = 500
|
||||
, _crPict = \ _ -> onLayer CrLayer $ color white $ circleSolid 10
|
||||
}
|
||||
|
||||
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 = w & lightSources %~ IM.delete i
|
||||
| otherwise = w & lightSources . ix i . lsPos .~ _crPos cr
|
||||
internalUpdate cr
|
||||
| _crHP cr < 0 = Nothing
|
||||
| otherwise = Just $ doDamage cr
|
||||
|
||||
|
||||
barrel :: Creature
|
||||
barrel = defaultCreature
|
||||
{ _crUpdate = updateBarrel
|
||||
, _crHP = 500
|
||||
, _crPict = \ _ -> onLayer CrLayer $ pictures
|
||||
[ color orange $ circleSolid 10
|
||||
, color (greyN 0.5) $ circleSolid 8
|
||||
]
|
||||
, _crState = defaultState
|
||||
{_goals = [[Wait]]
|
||||
,_faction = ChaseCritters
|
||||
,_crSpState = Barrel []
|
||||
}
|
||||
, _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
|
||||
}
|
||||
|
||||
explosiveBarrel :: Creature
|
||||
explosiveBarrel = defaultCreature
|
||||
{ _crUpdate = updateExpBarrel
|
||||
, _crHP = 400
|
||||
, _crPict = \ _ -> onLayer CrLayer $ pictures [ color orange $ circleSolid 10
|
||||
, color red $ circleSolid 8
|
||||
]
|
||||
, _crState = defaultState {_goals = [[Wait]]
|
||||
,_faction = ChaseCritters
|
||||
,_crSpState = Barrel []
|
||||
,_crApplyDamage = \_ c -> (id, c)
|
||||
}
|
||||
, _crInv = IM.empty -- IM.fromList [(0,frontArmour)]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
module Dodge.Creature.Update
|
||||
where
|
||||
import Dodge.Data
|
||||
|
||||
import System.Random
|
||||
-- combinators for helping with dealing with creature update
|
||||
|
||||
type CRUpdate = World -> (World -> World,StdGen) -> Creature -> ((World -> World,StdGen), Maybe Creature)
|
||||
|
||||
unrandUpdate :: (Creature -> World -> World) -> (Creature -> Maybe Creature)
|
||||
-> CRUpdate
|
||||
unrandUpdate h cF w (f,g) cr = ( ( h cr . f , g) , cF cr )
|
||||
Reference in New Issue
Block a user