Implement basic laser sensor

This commit is contained in:
2021-11-01 18:20:45 +00:00
parent 0dcb1d2c07
commit 82de39657b
7 changed files with 59 additions and 21 deletions
+35 -6
View File
@@ -5,17 +5,46 @@ import Color
import Dodge.Data
import Dodge.LevelGen.Data
import Dodge.Default
import Dodge.Data.DamageType
import Geometry
import ShapePicture
import Shape
lightSensor :: PSType
lightSensor = PutMachine blue (reverse $ square wdth) defaultMachine
{ _mcDraw = const lightSensorSPic
}
import Control.Lens
lightSensorSPic :: SPic
lightSensorSPic = ( colorSH blue $ upperPrismPoly 25 (square wdth)
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