Work on sensor machines, remove some datatypes associated with placements

This commit is contained in:
2021-11-01 23:07:58 +00:00
parent 82de39657b
commit 7ef1da9be5
16 changed files with 265 additions and 220 deletions
+21 -14
View File
@@ -11,12 +11,15 @@ import ShapePicture
import Shape
import Control.Lens
import Data.Either
lightSensor :: Point2 -> Float -> Placement
lightSensor p r = Placement (PS p r $ PutLS theLS)
damageSensor
:: (DamageType -> Either Int Int) -- Left gets sensed, Right does damage
-> Point2 -> Float -> Placement
damageSensor damF p r = Placement (PS p r $ PutLS theLS)
$ \lsid -> jsps p r $ PutMachine blue (reverse $ square wdth) defaultMachine
{ _mcDraw = lightSensorSPic
, _mcUpdate = lightSensorUpdate
{ _mcDraw = sensorSPic
, _mcUpdate = sensorUpdate damF
, _mcLSs = [lsid]
}
where
@@ -25,26 +28,30 @@ lightSensor p r = Placement (PS p r $ PutLS theLS)
, _lsIntensity = 0.1
}
lightSensorUpdate :: Machine -> World -> World
lightSensorUpdate mc w = w & machines . ix mcid %~ upmc
lightSensor :: Point2 -> Float -> Placement
lightSensor = damageSensor senseLasering
senseLasering :: DamageType -> Either Int Int
senseLasering Lasering {_dmAmount = x} = Left x
senseLasering _ = Right 0
sensorUpdate :: (DamageType -> Either Int Int) -> Machine -> World -> World
sensorUpdate damF mc w = w & machines . ix mcid %~ upmc
& lightSources . ix lsid %~ upls
where
upmc = ( mcSensor %~ \x' -> min 750 (max 0 (x' - 5 + newSense)) )
. ( mcHP -~ sum dam )
. (mcDamage .~ [])
x = _mcSensor mc
mcid = _mcID mc
lsid = head (_mcLSs mc)
newSense = sum . map _dmAmount $ filter isLasering $ _mcDamage mc
(senseData,dam) = partitionEithers $ map damF $ _mcDamage mc
newSense = sum senseData
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)
sensorSPic :: Machine -> SPic
sensorSPic _ = ( colorSH blue $ upperPrismPoly 25 (square wdth)
, mempty )
wdth :: Float