Move radar blips into own grouping

This commit is contained in:
2022-07-10 11:52:51 +01:00
parent 8202d12b6a
commit ce5b596d4f
6 changed files with 101 additions and 74 deletions
+11 -64
View File
@@ -23,10 +23,10 @@ aWallPulse = aRadarPulse wallBlips (blipAt 2) red
{- | Creates an outwardly increasing circle that displays items. -}
anItemFindPulse :: Creature -> World -> World
anItemFindPulse = aRadarPulse itemBlips (openBlipAt 6) blue
anItemFindPulse = aRadarPulse itemBlips (blipAt 6) blue
aRadarPulse :: (Point2 -> Float -> World -> [Point2])
-> (Point2 -> Color -> Int -> Particle)
-> (Point2 -> Color -> Int -> RadarBlip)
-> Color
-> Creature
-> World -> World
@@ -51,70 +51,17 @@ drawPulse col pt = setLayer DebugLayer $ pictures sweepPics
| otherwise = fromIntegral x / 10
x = _ptTimer pt
{- | Radar blip at a point. -}
blipAt :: Float -> Point2 -> Color -> Int -> Particle
blipAt r p col i = BlipParticle
{_ptDraw = drawBlip
,_ptUpdate = \w pt -> if _ptTimer pt <= 0 then (w,Nothing) else (w,Just $ pt & ptTimer -~ 1)
,_ptColor = col
,_ptTimer = i
,_ptMaxTime = i
,_ptRad = r
,_ptPos = p
blipAt :: Float -> Point2 -> Color -> Int -> RadarBlip
blipAt r p col i = RadarBlip
{_rbColor = col
,_rbTime = i
,_rbMaxTime = i
,_rbRad = r
,_rbPos = p
}
drawBlip :: Particle -> Picture
drawBlip pt = setDepth (-0.5)
. setLayer DebugLayer
. uncurryV translate p
. color (withAlpha (fromIntegral t / fromIntegral maxt) col)
$ circleSolid r
where
p = _ptPos pt
t = _ptTimer pt
r = _ptRad pt
col = _ptColor pt
maxt = _ptMaxTime pt
mvBlip :: Float
-> Point2 -> Color
-> Int -- ^ Max possible timer value
-> Int -- ^ Current timer value
-> World -> Particle -> (World, Maybe Particle)
mvBlip r p col maxt t w pt = case t of
0 -> (w, Nothing)
_ -> (w
, Just $ pt & ptUpdate .~ mvBlip r p col maxt (t-1)
& ptDraw .~ ( const
. setDepth (-0.5)
. setLayer DebugLayer
. uncurryV translate p
. color (withAlpha (fromIntegral t / fromIntegral maxt) col)
$ circleSolid r )
)
{- | Radar blip at a point. -}
openBlipAt :: Float -> Point2 -> Color -> Int -> Particle
openBlipAt r p col i = Particle
{_ptDraw = const blank
,_ptUpdate = mvOpenBlip r p col i i
}
mvOpenBlip :: Float
-> Point2 -> Color
-> Int -- ^ Max possible timer value
-> Int -- ^ Current timer value
-> World -> Particle -> (World, Maybe Particle)
mvOpenBlip r p col maxt t w pt = case t of
0 -> (w, Nothing)
_ -> (w
, Just $ pt & ptUpdate .~ mvOpenBlip r p col maxt (t-1)
& ptDraw .~ ( const
. setDepth (-0.5)
. setLayer DebugLayer
. uncurryV translate p
. color (withAlpha (fromIntegral t / fromIntegral maxt) col)
$ thickCircle r 3)
)
mvRadar
:: (Point2 -> Float -> World -> [Point2])
-> (Point2 -> Color -> Int -> Particle)
-> (Point2 -> Color -> Int -> RadarBlip)
-> Color
-> Point2 -- ^ Center of expanding circle
-> World -> Particle -> (World, Maybe Particle)
@@ -126,7 +73,7 @@ mvRadar blipsF bf col p w pt
)
where
x = _ptTimer pt
putBlips = over worldEvents ( over instantParticles (blips ++) . )
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)