Create datatypes for radar sweeps

This commit is contained in:
2022-07-19 20:38:56 +01:00
parent b4c0074d43
commit 29e25f61d3
14 changed files with 139 additions and 123 deletions
-2
View File
@@ -5,7 +5,6 @@ module Dodge.Item.Weapon
, module Dodge.Item.Weapon.Shatter
, module Dodge.Item.Weapon.TriggerType
, module Dodge.Item.Weapon.ExtraEffect
, module Dodge.Item.Weapon.UseEffect
, module Dodge.Item.Weapon.Remote
, module Dodge.Item.Weapon.Grenade
, module Dodge.Item.Weapon.Spawn
@@ -23,7 +22,6 @@ import Dodge.Item.Weapon.TriggerType
import Dodge.Item.Weapon.SonicGuns
import Dodge.Item.Weapon.Shatter
import Dodge.Item.Weapon.ExtraEffect
import Dodge.Item.Weapon.UseEffect
import Dodge.Item.Weapon.Remote
import Dodge.Item.Weapon.Grenade
import Dodge.Item.Weapon.Spawn
+3 -4
View File
@@ -17,9 +17,8 @@ module Dodge.Item.Weapon.ExtraEffect
import Dodge.Data
import Dodge.Base
import Dodge.Zone
import Dodge.RadarSweep
import Dodge.SoundLogic
--import Dodge.Item.Weapon.Decoration
import Dodge.Item.Weapon.UseEffect
import Dodge.Item.Weapon.LaserPath
--import Dodge.Item.Attachment.Data
import Dodge.Creature.Test
@@ -49,10 +48,10 @@ autoEffect eff t sid itm cr w
{- | Automatically send out radar pulses that detect walls. -}
autoRadarEffect :: Item -> Creature -> World -> World
autoRadarEffect = autoEffect (const aWallPulse) 100 click1S
autoRadarEffect = autoEffect (const (aRadarPulse ObWall)) 100 click1S
{- | Automatically send out sonar pulses that detect creatures. -}
autoSonarEffect :: Item -> Creature -> World -> World
autoSonarEffect = autoEffect (const aSonarPulse) 50 click1S
autoSonarEffect = autoEffect (const (aRadarPulse ObCreature)) 50 click1S
defaultTargeting :: Targeting
defaultTargeting = Targeting
{ _tgPos = Nothing
+4 -6
View File
@@ -1,11 +1,9 @@
module Dodge.Item.Weapon.Radar where
import Dodge.Data
--import Dodge.Picture.Layer
import Dodge.RadarSweep
import Dodge.Default
import Dodge.Item.Weapon.TriggerType
import Dodge.Item.Weapon.ExtraEffect
import Dodge.Item.Weapon.UseEffect
--import Dodge.Item.Weapon.Remote
import Dodge.SoundLogic
import Control.Lens
@@ -34,6 +32,6 @@ autoDetector dt = defaultEquipment
detectorEffect :: Detector -> Item -> Creature -> World -> World
detectorEffect dt = case dt of
ITEMDETECTOR -> const anItemFindPulse
CREATUREDETECTOR -> const aSonarPulse
WALLDETECTOR -> const aWallPulse
ITEMDETECTOR -> const (aRadarPulse ObItem)
CREATUREDETECTOR -> const (aRadarPulse ObCreature)
WALLDETECTOR -> const (aRadarPulse ObWall)
-86
View File
@@ -1,86 +0,0 @@
{- |
Effects centered on creatures.
These are typically item effects, and typical occur when an item is explictly used. -}
module Dodge.Item.Weapon.UseEffect
( anItemFindPulse
, aWallPulse
, aSonarPulse
) where
import Dodge.Data
import Dodge.Zone
import Picture
import Geometry
import LensHelp
import qualified Data.IntMap.Strict as IM
import qualified Streaming.Prelude as S
{- | Creates an outwardly increasing circle that draws creatures, even those behind walls. -}
aSonarPulse :: Creature -> World -> World
aSonarPulse = aRadarPulse crBlips (blipAt 8) (withAlpha 0.2 green)
aWallPulse :: Creature -> World -> World
aWallPulse = aRadarPulse wallBlips (blipAt 2) red
{- | Creates an outwardly increasing circle that displays items. -}
anItemFindPulse :: Creature -> World -> World
anItemFindPulse = aRadarPulse itemBlips (blipAt 6) blue
aRadarPulse :: (Point2 -> Float -> World -> [Point2])
-> (Point2 -> Color -> Int -> RadarBlip)
-> Color
-> Creature
-> World -> World
aRadarPulse blipsF bf col cr = instantParticles .:~ RadarCircleParticle
{ _ptUpdate = mvRadar blipsF bf col (_crPos cr)
, _ptTimer = 100
, _ptRad = 0
, _ptPos = _crPos cr
, _ptColor = col
}
{- | Radar blip at a point. -}
blipAt :: Float -> Point2 -> Color -> Int -> RadarBlip
blipAt r p col i = RadarBlip
{_rbColor = col
,_rbTime = i
,_rbMaxTime = i
,_rbRad = r
,_rbPos = p
}
mvRadar
:: (Point2 -> Float -> World -> [Point2])
-> (Point2 -> Color -> Int -> RadarBlip)
-> Color
-> Point2 -- ^ Center of expanding circle
-> World -> Particle -> (World, Maybe Particle)
mvRadar blipsF bf col p w pt
| x < 1 = (w, Nothing)
| otherwise =
( putBlips w
, Just $ pt & ptRad .~ r & ptTimer .~ (x-1)
)
where
x = _ptTimer pt
putBlips = radarBlips .++~ blips
blips = map (\bp -> bf bp (withAlpha (0.5*globalAlpha) col) 50) circPoints
circPoints = blipsF p r w
r = fromIntegral (400 - x*4)
globalAlpha | x > 10 = 1
| otherwise = fromIntegral x / 10
itemBlips :: Point2 -> Float -> World -> [Point2]
itemBlips p r = IM.elems . IM.filter f . fmap _flItPos . _floorItems
where
f q = dist p q <= r && dist p q > r - 4
wallBlips :: Point2 -> Float -> World -> [Point2]
wallBlips p r w = runIdentity . S.toList_ $ S.mapMaybe (uncurry (intersectCircSegFirst p r) . _wlLine)
$ S.map (over wlLine swp) (wlsInsideCirc p r w)
<> wlsInsideCirc p r w
where
swp (a,b) = (b,a)
crBlips :: Point2 -> Float -> World -> [Point2]
crBlips p r = IM.elems . IM.filter f . fmap _crPos . IM.filter g . _creatures
where
f q = dist p q <= r && dist p q > r - 100
g cr = _crID cr /= 0