Flash refactor

This commit is contained in:
jgk
2021-03-24 20:28:31 +01:00
parent 7c9cba9ee1
commit 7fd49d9b41
3 changed files with 26 additions and 18 deletions
+11 -2
View File
@@ -427,11 +427,20 @@ data ItemIdentity
| PoisonSprayer
deriving (Eq,Show,Ord,Enum)
data Particle' =
Particle'
data Particle'
= Particle'
{ _ptDraw :: Particle' -> Picture
, _ptUpdate' :: World -> Particle' -> (World, Maybe Particle')
}
| GlareLine
{ _ptDraw :: Particle' -> Picture
, _ptUpdate' :: World -> Particle' -> (World, Maybe Particle')
, _glareTimer :: Int
, _glareLength :: Float
, _glareWidth :: Float
, _glareColor :: Color
, _glareLine :: (Point2,Point2)
}
| Bul' { _ptDraw :: Particle' -> Picture
, _ptUpdate' :: World -> Particle' -> (World, Maybe Particle')
, _btVel' :: Point2
+1 -2
View File
@@ -857,7 +857,7 @@ cloudPoisonDamage c w = w & creatures %~ flip (foldr (IM.adjust doDam)) damagedC
aFlame :: Float -> Int -> World -> World
aFlame a cid w
= shakeCr cid 2
$ soundFrom Flame fireSound 2 500
-- $ soundFrom Flame fireSound 2 500
$ insertFlame $ resetAngle $ set randGen g $
w
where
@@ -867,7 +867,6 @@ aFlame a cid w
dir = _crDir cr + angle
pos = _crPos cr +.+ ((_crRad cr + 2.9) *.* unitVectorAtAngle (_crDir cr))
w1 = set randGen g w
i = newProjectileKey w1
vel = (_crPos cr -.- _crOldPos cr) +.+ 4 *.* unitVectorAtAngle dir
insertFlame = makeFlame pos vel (Just cid) -- . makeFlame pos2 vel (Just cid)
resetAngle = set (creatures . ix cid . crInv . ix (_crInvSel cr) . wpFire)
+14 -14
View File
@@ -23,7 +23,7 @@ import Control.Lens
-- flicker : potentially long, moving, abrupt changes in alpha
glareAt :: Int -> Float -> Float -> Color -> Float -> Int -> Float -> Point2 -> World -> World
glareAt t len wdth col alphay nrays rad p w = foldr (glareLine t len wdth col alphay p) w ps
glareAt t len wdth col alphay nrays rad p w = foldr (glareLine' t len wdth col alphay p) w ps
where ps = map ((+.+) p) $ nRaysRad nrays rad
sparkFlashAt :: Point2 -> World -> World
@@ -47,20 +47,20 @@ laserGunFlashAt p =
. glareAt 2 10 5 yellow 0.05 20 30 p
glareLine :: Int -> Float -> Float -> Color -> Float -> Point2 -> Point2 -> World -> World
glareLine t len wdth col alphay a b w = w & particles' %~ (maybeToList linePt ++)
glareLine' :: Int -> Float -> Float -> Color -> Float -> Point2 -> Point2 -> World -> World
glareLine' t len wdth col alphay a b w = w & particles' %~ (maybeToList linePt ++)
where linePt :: Maybe Particle'
linePt = glareBetween t len wdth col alphay a b w
linePt = glareBetween t len wdth (withAlpha alphay col) a b w
glareBetween :: Int -> Float -> Float -> Color -> Float -> Point2 -> Point2 -> World -> Maybe Particle'
glareBetween 0 _ _ _ _ _ _ _ = Nothing
glareBetween t len wdth col alphay a b w
= Just $ Particle' {_ptDraw = const $ lowLightPic len wdth col alphay a b w
,_ptUpdate' = \ w' _ -> (w',glareBetween (t-1) len wdth col alphay a b w')
glareBetween :: Int -> Float -> Float -> Color -> Point2 -> Point2 -> World -> Maybe Particle'
glareBetween 0 _ _ _ _ _ _ = Nothing
glareBetween t len wdth col a b w
= Just $ Particle' {_ptDraw = const $ lowLightPic len wdth col a b w
,_ptUpdate' = \ w' _ -> (w',glareBetween (t-1) len wdth col a b w')
}
lowLightPic :: Float -> Float -> Color -> Float -> Point2 -> Point2 -> World -> Picture
lowLightPic len wdth col alphay a b w
lowLightPic :: Float -> Float -> Color -> Point2 -> Point2 -> World -> Picture
lowLightPic len wdth col a b w
= case thingsHitLongLine a b w of
((p, E3x2 wall):_)
-> setCol . lineOfThickness wdth $ [p +.+ x, p -.- x]
@@ -71,7 +71,7 @@ lowLightPic len wdth col alphay a b w
$ thickArc 0 (pi/2) (_crRad cr) wdth
where cp = _crPos cr
_ -> blank
where setCol = color (withAlpha alphay col) . setDepth (-0.5) . setLayer 2
where setCol = color col . setDepth (-0.5) . setLayer 2
flashFlareAt :: Color -> Float -> Point2 -> Particle'
flashFlareAt col alphax (x,y) =
@@ -88,11 +88,11 @@ explosionFlashAt p = over tempLightSources ((:) $ tLightFade 20 150 intensityFu
| x < 10 = 1 / (10 - fromIntegral x)
| otherwise = 1
flameGlareAt = glareAt 2 10 5 orange 0.05 8 50
flameGlareAt = glareAt 1 10 5 orange 0.05 8 40
lowLightDirected :: Color -> Float -> Point2 -> Point2 -> [Float] -> World -> World
lowLightDirected col alpha a b angles w
= foldr (\angle w' -> glareLine 2 10 5 col alpha a (a +.+ rotateV angle b) w') w angles
= foldr (\angle w' -> glareLine' 2 10 5 col alpha a (a +.+ rotateV angle b) w') w angles
muzzleFlashAt :: Point2 -> World -> World