module Dodge.Machine.Sensor ( lightSensor ) where import Color import Dodge.Data import Dodge.LevelGen.Data import Dodge.Default import Dodge.Data.DamageType import Geometry import ShapePicture import Shape import Control.Lens lightSensor :: Point2 -> Float -> Placement lightSensor p r = Placement (PS p r $ PutLS theLS) $ \lsid -> jsps p r $ PutMachine blue (reverse $ square wdth) defaultMachine { _mcDraw = lightSensorSPic , _mcUpdate = lightSensorUpdate , _mcLSs = [lsid] } where theLS = defaultLS { _lsPos = V3 0 0 30 , _lsIntensity = 0.1 } lightSensorUpdate :: Machine -> World -> World lightSensorUpdate mc w = w & machines . ix mcid %~ upmc & lightSources . ix lsid %~ upls where upmc = ( mcSensor %~ \x' -> min 750 (max 0 (x' - 5 + newSense)) ) . (mcDamage .~ []) x = _mcSensor mc mcid = _mcID mc lsid = head (_mcLSs mc) newSense = sum . map _dmAmount $ filter isLasering $ _mcDamage mc ni = fromIntegral x / 500 upls = lsIntensity .~ V3 ni ni ni isLasering Lasering {} = True isLasering _ = False isElectrical Electrical {} = True isElectrical _ = False lightSensorSPic :: Machine -> SPic lightSensorSPic mc = ( colorSH blue $ upperPrismPoly 25 (square wdth) , mempty ) wdth :: Float wdth = 5