Replace particle pictures with draw functions

This commit is contained in:
2021-03-24 13:42:31 +01:00
parent 27fc9d19d2
commit 3cce959d00
8 changed files with 70 additions and 80 deletions
+47 -13
View File
@@ -878,7 +878,7 @@ aFlame a cid w
makeFlame :: Point2 -> Point2 -> Maybe Int -> World -> World
makeFlame pos vel maycid = over particles' ((:) theFlame)
where theFlame =
Pt' { _ptPict' = blank
Pt' { _ptDraw = drawFlame
, _ptUpdate' = moveFlame vel
, _btVel' = vel
, _btColor' = red
@@ -889,6 +889,40 @@ makeFlame pos vel maycid = over particles' ((:) theFlame)
, _btHitEffect' = destroyOnImpact (doFlameDam 1) noEff noEff
}
drawFlame :: Particle' -> Picture
drawFlame pt = thePic ep
where ep = _btPos' pt
rotd = _btVel' pt
thePic p' = pictures $ reverse [ pic p' , piu p' , pi2 p' , glow p' ]
pic p' = setLayer 1 . setDepth 0.2994 $ uncurry translate (prot3 p')
$ rotate (pi * 0.5 + argV rotd)
$ scale scaleChange 1
$ pictures $ reverse [color white $ circleSolid 4
,color (withAlpha 0.5 white) $ circleSolid 5
]
piu p' = setLayer 1 . setDepth 0.2998 $ uncurry translate (prot2 p')
$ rotate (pi*0.5 + argV rotd)
$ scale (scaleChange + 1) 2
$ pictures $ reverse [color red $ circleSolid 4.5
,color (withAlpha 0.5 red) $ circleSolid 5
]
pi2 p' = setLayer 1
. setDepth 0.2996
. uncurry translate (prot p')
$ rotate (pi * 0.5 + argV rotd)
$ scale (scaleChange + 0.5) 1.5
$ pictures $ reverse [color orange $ circleSolid 4.5
,color (withAlpha 0.5 orange) $ circleSolid 5
]
glow p' = setLayer 1 $ setDepth 0.3 $ uncurry translate p'
$ circleSolidCol (withAlpha 0 orange) (withAlpha 0.02 orange) 50
time = _btTimer' pt
scaleChange | time < 80 = 3
| otherwise = 3 - (fromIntegral time - 80) * 0.2
prot p' = p' +.+ rotateV (fromIntegral time * 1) (0,1)
prot2 p' = p' +.+ rotateV (negate $ fromIntegral time * 1) (0,1)
prot3 p' = p' +.+ rotateV (2 + fromIntegral time * 0.1) (0,2)
moveFlame :: Point2 -> World -> Particle' -> (World, Maybe Particle')
moveFlame rotd w pt
| time <= 0 = (smokeGen w, Nothing)
@@ -902,10 +936,10 @@ moveFlame rotd w pt
sp = _btPos' pt
vel = _btVel' pt
ep = sp +.+ vel
mvPt = Just $ pt {_btTimer' = time - 1, _btPos' = ep, _ptPict' = thepic ep
mvPt = Just $ pt {_btTimer' = time - 1, _btPos' = ep--, _ptDraw = const $ thepic ep
, _btPassThrough' = Nothing
,_btVel' = 0.98 *.* vel}
mvPt' = Just $ pt {_btTimer' = time - 1, _btPos' = ep, _ptPict' = thepic ep
mvPt' = Just $ pt {_btTimer' = time - 1, _btPos' = ep--, _ptDraw = const $ thepic ep
, _btPassThrough' = Nothing
,_btVel' = 0.7 *.* vel}
damcrs = foldr ($) w $ map (\cr -> fst . hiteff [(ep,E3x1 cr)]) $ filter closeCrs
@@ -940,7 +974,7 @@ moveFlame rotd w pt
,color (withAlpha 0.5 red) $ circleSolid 5
]
rfl wl p = Just $ pt {_btTimer' = time -1, _btPos' = pOut p
, _btVel' = reflV wl, _ptPict' = thepic $ pOut p
, _btVel' = reflV wl--, _ptDraw = const $ thepic $ pOut p
}
glow p' = setLayer 1 $ setDepth 0.3 $ uncurry translate p'
$ circleSolidCol (withAlpha 0 orange) (withAlpha 0.02 orange) 50
@@ -1133,7 +1167,7 @@ rateIncAB startRate fastRate shooteff1 shooteff2 cid w
makeLaserAt :: Float -> Point2 -> Float -> Maybe Int -> Particle'
makeLaserAt phaseV pos dir mcid = Particle'
{ _ptPict' = blank
{ _ptDraw = const blank
, _ptUpdate' = moveLaser phaseV pos dir mcid
}
@@ -1142,7 +1176,7 @@ moveLaser phaseV pos dir mcid w pt
= ( set randGen g
-- $ over worldEvents ((.) flares)
$ hitEffect w
, Just pt {_ptPict' = onLayer PtLayer $ pic
, Just pt {_ptDraw = const $ onLayer PtLayer $ pic
,_ptUpdate' = ptTimer' 0
}
)
@@ -1900,7 +1934,7 @@ aRadarPulse cid w = over particles' ((:) $ radarPulseAt (_crPos (_creatures w IM
blipAt :: Point2 -> Color -> Int -> Particle'
blipAt p col i = Particle'
{_ptPict' = blank
{_ptDraw = const blank
,_ptUpdate' = mvBlip p col i i
}
@@ -1908,7 +1942,7 @@ mvBlip :: Point2 -> Color -> Int -> Int -> World -> Particle' -> (World, Maybe P
mvBlip p col maxt 0 w pt = (w, Nothing)
mvBlip p col maxt t w pt
= (w, Just $ pt & ptUpdate' .~ mvBlip p col maxt (t-1)
& ptPict' .~ (onLayerL [levLayer ShadowLayer, 2]
& ptDraw .~ (const $ onLayerL [levLayer ShadowLayer, 2]
$ uncurry translate p
$ color (withAlpha (fromIntegral t / fromIntegral maxt) col)
$ circleSolid 2)
@@ -1916,13 +1950,13 @@ mvBlip p col maxt t w pt
sonarPulseAt :: Point2 -> Particle'
sonarPulseAt p = Particle'
{ _ptPict' = blank
{ _ptDraw = const blank
, _ptUpdate' = mvSonar 100 p
}
mvSonar :: Int -> Point2 -> World -> Particle' -> (World, Maybe Particle')
mvSonar 0 _ w _ = (w, Nothing)
mvSonar x p w pt = (w, Just $ pt {_ptPict' = pic
mvSonar x p w pt = (w, Just $ pt {_ptDraw = const pic
,_ptUpdate' = mvSonar (x-1) p
}
)
@@ -1949,13 +1983,13 @@ mvSonar x p w pt = (w, Just $ pt {_ptPict' = pic
radarPulseAt :: Point2 -> Particle'
radarPulseAt p = Particle'
{ _ptPict' = blank
{ _ptDraw = const blank
, _ptUpdate' = mvRadar 50 p
}
mvRadar :: Int -> Point2 -> World -> Particle' -> (World, Maybe Particle')
mvRadar 0 _ w _ = (w, Nothing)
mvRadar x p w pt = (putBlips w, Just $ pt {_ptPict' = pic
mvRadar x p w pt = (putBlips w, Just $ pt {_ptDraw = const pic
,_ptUpdate' = mvRadar (x-1) p
}
)
@@ -2057,7 +2091,7 @@ itemLaserScopeEffect
makeLaserScope :: Point2 -> Point2 -> Float -> Float -> Particle'
makeLaserScope p ep d relFrac = Particle'
{_ptPict' = onLayer PtLayer $ pictures
{_ptDraw = const $ onLayer PtLayer $ pictures
[color (withAlpha 0.5 $ mixColors relFrac (1-relFrac) red green)
$ lineOfThickness 0.5 [p,ep]
,color (withAlpha 0.2 $ mixColors relFrac (1-relFrac) red green)
+2 -2
View File
@@ -223,7 +223,7 @@ bulletParticleSideEffect pt = destroyOnImpact mkPt mkPt noEff
aGenBulAt' :: Maybe Int -> Color -> Point2 -> Point2 -> HitEffect -> Float -> Particle'
aGenBulAt' maycid col pos vel hiteff width = Bul'
{ _ptPict' = blank
{ _ptDraw = drawBul
, _ptUpdate' = mvGenBullet'
, _btVel' = vel
, _btColor' = col
@@ -236,7 +236,7 @@ aGenBulAt' maycid col pos vel hiteff width = Bul'
aCurveBulAt :: Maybe Int -> Color -> Point2 -> Point2 -> Point2 -> HitEffect -> Float -> Particle'
aCurveBulAt maycid col pos control targ hiteff width = Bul'
{ _ptPict' = blank
{ _ptDraw = drawBul
, _ptUpdate' = mvBulletTrajectory f
, _btVel' = (0,0)
, _btColor' = col