{-# LANGUAGE TupleSections #-} {- 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 Geometry.Vector3D import Polyhedra import Control.Lens defaultInanimate :: Creature defaultInanimate = defaultCreature & crActionPlan .~ Inanimate lamp :: Float -> Creature lamp h = defaultInanimate { _crUpdate = initialiseLamp h , _crHP = 100 , _crPict = picAtCrPos (lampPic h) , _crRad = 3 , _crMass = 3 } lampPic :: Float -> Picture lampPic h = pictures [ setLayer 0 $ pictures . map (Poly3D . map ((, blue) . (-.-.- (2.5,2.5,0)))) $ boxXYZ 5 5 (h-1) , setLayer 1 $ setDepth h $ color white $ circleSolid 3 ] initialiseLamp :: Float -> CRUpdate initialiseLamp h w (f,g) cr = ( (addLS . f , g), Just $ cr & crUpdate .~ updateLamp h i) where i = IM.newKey $ _lightSources $ f w -- to give different lights different keys addLS = over lightSources (IM.insert i (lightAt (x,y,h) i)) (x,y) = _crPos cr updateLamp :: Float -> Int -> CRUpdate updateLamp h 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,h) 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 , setDepth 0.049 . color (greyN 0.5) $ circleSolid 8 , 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 $ pictures [ color red $ circleSolid 8 , setDepth 0.049 . color (greyN 0.5) $ circleSolid 10 , color orange $ circleSolid 10 ] , _crState = defaultState {_crSpState = Barrel [] } , _crInv = IM.empty -- IM.fromList [(0,frontArmour)] ,_crApplyDamage = \_ c -> (id, c) }