Partial (not working) refactor of damages, energyballs
This commit is contained in:
+54
-19
@@ -1,3 +1,4 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
module Dodge.EnergyBall
|
||||
( updateEnergyBall
|
||||
, incBallAt
|
||||
@@ -5,9 +6,11 @@ module Dodge.EnergyBall
|
||||
, makeFlamelet
|
||||
) where
|
||||
|
||||
import Data.List (foldl')
|
||||
import Dodge.WorldEvent.ThingsHit
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Dodge.Base.Collide
|
||||
import Data.Maybe
|
||||
import Dodge.DamageCircle
|
||||
import Dodge.Data.World
|
||||
import Geometry
|
||||
import LensHelp
|
||||
@@ -19,24 +22,19 @@ makeFlamelet ::
|
||||
Point2 ->
|
||||
-- | Velocity
|
||||
Point2 ->
|
||||
-- | Size
|
||||
Float ->
|
||||
-- | Timer
|
||||
Int ->
|
||||
World ->
|
||||
World
|
||||
makeFlamelet (V2 x y) vel size time w =
|
||||
makeFlamelet (V2 x y) vel time w =
|
||||
w
|
||||
& randGen .~ g
|
||||
& cWorld . lWorld . energyBalls
|
||||
.:~ EnergyBall
|
||||
{ _ebVel = vel
|
||||
, _ebColor = red
|
||||
, _ebPos = V2 x y
|
||||
, _ebWidth = size
|
||||
, _ebTimer = time
|
||||
, _ebEff = (FLAMING, 1)
|
||||
-- , _ebZ = z
|
||||
, _ebEff = FlameletBall
|
||||
, _ebRot = rot
|
||||
}
|
||||
where
|
||||
@@ -46,8 +44,7 @@ updateEnergyBall :: World -> EnergyBall -> (World, Maybe EnergyBall)
|
||||
updateEnergyBall w eb
|
||||
| _ebTimer eb <= 0 = (w, Nothing)
|
||||
| otherwise =
|
||||
( ebFlicker eb $ uncurry (damageCircle 5 (_ebPos eb)) (_ebEff eb) w
|
||||
-- , Just $ eb & ebTimer -~ 1 & ebPos .+.+~ _ebVel eb & ebVel .*.*~ 0.9
|
||||
( ebFlicker eb $ damageCircle (_ebPos eb) (_ebEff eb) w
|
||||
, Just $ eb & ebTimer -~ 1 & ebPos .~ bp & ebVel .~ 0.85 * bv
|
||||
)
|
||||
where
|
||||
@@ -66,12 +63,9 @@ incBallAt p w =
|
||||
return
|
||||
EnergyBall
|
||||
{ _ebVel = 0
|
||||
, _ebColor = red
|
||||
, _ebPos = p
|
||||
, _ebWidth = 3
|
||||
, _ebTimer = 20
|
||||
, _ebEff = (FLAMING, 1)
|
||||
-- , _ebZ = 20
|
||||
, _ebEff = FlamingBall
|
||||
, _ebRot = rot
|
||||
}
|
||||
|
||||
@@ -86,12 +80,9 @@ makeFlashBall p w =
|
||||
return
|
||||
EnergyBall
|
||||
{ _ebVel = 0
|
||||
, _ebColor = yellow
|
||||
, _ebPos = p
|
||||
, _ebWidth = 3
|
||||
, _ebTimer = 20
|
||||
, _ebEff = (LASERING, 1)
|
||||
-- , _ebZ = 20
|
||||
, _ebEff = FlashBall
|
||||
, _ebRot = rot
|
||||
}
|
||||
|
||||
@@ -99,5 +90,49 @@ ebFlicker :: EnergyBall -> World -> World
|
||||
ebFlicker pt
|
||||
| _ebTimer pt `mod` 7 == 0 =
|
||||
cWorld . lWorld . lights
|
||||
.:~ LSParam (addZ 20 $ _ebPos pt) 70 (0.5 *.*.* xyzV4 (_ebColor pt))
|
||||
.:~ LSParam (addZ 20 $ _ebPos pt) 70 (0.5 *.*.* xyzV4 (ebColor pt))
|
||||
| otherwise = id
|
||||
|
||||
ebColor :: EnergyBall -> Color
|
||||
ebColor eb = case eb ^. ebEff of
|
||||
FlamingBall -> red
|
||||
FlameletBall -> red
|
||||
ElectricalBall -> cyan
|
||||
ExplosiveBall -> yellow
|
||||
FlashBall -> white
|
||||
|
||||
damageCircle :: Point2 -> EnergyBallType -> World -> World
|
||||
damageCircle sp dt w =
|
||||
w
|
||||
& cWorld . lWorld . wallDamages %~ addwalldamages
|
||||
& cWorld . lWorld . creatures %~ addcreaturedamages
|
||||
where
|
||||
r = 5
|
||||
addwalldamages wlds = foldl' (damageWlCircle wldam) wlds wlstodam
|
||||
wlstodam = wlsHitRadial sp r w
|
||||
wldam p = ebtToDamage p dt
|
||||
addcreaturedamages crs = foldl' (damageCrCircle crdam) crs crstodam
|
||||
crdam p cr = ebtToDamage sp dt
|
||||
crstodam = crsHitRadial sp r w
|
||||
|
||||
ebtToDamage :: Point2 -> EnergyBallType -> Damage
|
||||
ebtToDamage p = \case
|
||||
FlamingBall -> Flaming 10
|
||||
FlameletBall -> Flaming 1
|
||||
ElectricalBall -> Electrical 10
|
||||
ExplosiveBall -> Explosive 10 p
|
||||
FlashBall -> Flashing 10 p
|
||||
|
||||
damageWlCircle ::
|
||||
(Point2 -> Damage) ->
|
||||
IM.IntMap [Damage] ->
|
||||
(Point2, Wall) ->
|
||||
IM.IntMap [Damage]
|
||||
damageWlCircle f wldams (p, wl) = IM.insertWith (++) (_wlID wl) [f p] wldams
|
||||
|
||||
damageCrCircle ::
|
||||
(Point2 -> Creature -> Damage) ->
|
||||
IM.IntMap Creature ->
|
||||
(Point2, Creature) ->
|
||||
IM.IntMap Creature
|
||||
damageCrCircle crdam crs (p, cr) = crs & ix (_crID cr) . crState . csDamage .:~ crdam p cr
|
||||
|
||||
Reference in New Issue
Block a user