Stun turret turn with electrical damage

This commit is contained in:
2021-11-05 01:41:57 +00:00
parent 92026bf06a
commit 5cbfa6f1ff
24 changed files with 58 additions and 99 deletions
-55
View File
@@ -1,55 +0,0 @@
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
import Data.Either
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 = sensorSPic
, _mcUpdate = sensorUpdate damF
, _mcLSs = [lsid]
}
where
theLS = defaultLS { _lsPos = V3 0 0 30 , _lsIntensity = 0.1 }
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)
(senseData,dam) = partitionEithers $ map damF $ _mcDamage mc
newSense = sum senseData
ni = fromIntegral x / 500
upls = lsIntensity .~ V3 ni ni ni
sensorSPic :: Machine -> SPic
sensorSPic _ = ( colorSH blue $ upperPrismPoly 25 (square wdth)
, mempty )
wdth :: Float
wdth = 5