Add z level to energy balls

This commit is contained in:
2025-08-04 22:49:36 +01:00
parent bde0fa2a5c
commit 09428f2707
14 changed files with 125 additions and 110 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ updateExpBarrel ps cr w
& flip (foldl' f) ps
| otherwise =
w
& makeExplosionAt (cr ^. crPos) 0
& makeExplosionAt ((cr ^. crPos) `v2z` 20) 0
& cWorld . lWorld . creatures . at (_crID cr) .~ Nothing
where
f w' p = makeSpark NormalSpark (p + normalizeV p + cr ^. crPos) (argV p) w'
+3 -4
View File
@@ -1,14 +1,13 @@
module Dodge.Bullet.Draw (
drawBul,
drawBullet,
) where
import Dodge.Data.Bullet
import Linear
import Picture
drawBul :: Bullet -> Picture
drawBul pt =
--setLayer BloomNoZWrite
drawBullet :: Bullet -> Picture
drawBullet pt =
setLayer BloomLayer
. setDepth 20
. color (V4 200 200 200 2)
+1 -2
View File
@@ -18,8 +18,7 @@ import Geometry.Data
data Bullet = Bullet
{ _buEffect :: BulletEffect
, _buPayload :: BulletPayload
, -- , _buTrajectory :: BulletTrajectory
_buVel :: Point2
, _buVel :: Point2
, _buDrag :: Float
, _buPos :: Point2
, _buOldPos :: Point2
+2 -2
View File
@@ -15,8 +15,8 @@ import Dodge.Data.EnergyBall.Type
import Geometry.Data
data EnergyBall = EnergyBall
{ _ebVel :: Point2
, _ebPos :: Point2
{ _ebVel :: Point3
, _ebPos :: Point3
, _ebTimer :: Int
, _ebType :: EnergyBallType
}
+19 -15
View File
@@ -17,8 +17,9 @@ import Geometry
import LensHelp
import Picture
import RandomHelp
import Linear.V3
makeFlamelet :: Point2 -> Point2 -> Float -> Int -> World -> World
makeFlamelet :: Point3 -> Point3 -> Float -> Int -> World -> World
makeFlamelet p v s t w =
w
& randGen .~ g
@@ -36,29 +37,29 @@ updateEnergyBall :: World -> EnergyBall -> (World, Maybe EnergyBall)
updateEnergyBall w eb
| _ebTimer eb <= 0 = (w, Nothing)
| otherwise =
( ebEffect eb . ebFlicker eb $ ebDamage (_ebPos eb) (_ebType eb) w
, Just $ eb & ebTimer -~ 1 & ebPos .~ bp & ebVel .~ drag * bv
( ebEffect eb . ebFlicker eb $ ebDamage (eb ^. ebPos) (_ebType eb) w
, Just $ eb & ebTimer -~ 1 & ebPos . _xy .~ bp & ebVel . _xy .~ drag * bv
)
where
drag = case eb ^. ebType of
ExplosiveBall -> 0.9
_ -> 0.85
p = eb ^. ebPos + eb ^. ebVel
(bp, bv) = fromMaybe (p, eb ^. ebVel) $ bouncePoint (const True) 0 (eb ^. ebPos) p w
p = (eb ^. ebPos + eb ^. ebVel) ^. _xy
(bp, bv) = fromMaybe (p, eb ^. ebVel . _xy) $ bouncePoint (const True) 0 (eb ^. ebPos . _xy) p w
ebEffect :: EnergyBall -> World -> World
ebEffect eb = case _ebType eb of
ElectricalBall i ->
soundContinue (EBSound i) (_ebPos eb) elecCrackleS (Just 2)
soundContinue (EBSound i) (eb ^. ebPos . _xy) elecCrackleS (Just 2)
. randSparkExtraVel
(_ebVel eb)
(eb ^. ebVel . _xy)
ElectricSpark
(state (randomR (3, 6)))
(state (randomR (0, 2 * pi)))
(_ebPos eb)
(eb ^. ebPos . _xy)
IncendiaryBall{}
| _ebTimer eb == 20 ->
soundStart (EBSound (-1)) (_ebPos eb) fireFadeS Nothing
soundStart (EBSound (-1)) (eb ^. ebPos . _xy) fireFadeS Nothing
_ -> id
energyBallAt :: EnergyBallType -> Point2 -> World -> World
@@ -66,7 +67,7 @@ energyBallAt ebt p =
cWorld . lWorld . energyBalls
.:~ EnergyBall
{ _ebVel = 0
, _ebPos = p
, _ebPos = p `v2z` 20
, _ebTimer = 20
, _ebType = ebt
}
@@ -75,8 +76,8 @@ makeMovingEB :: Point2 -> EnergyBallType -> Point2 -> World -> World
makeMovingEB v ebt p =
cWorld . lWorld . energyBalls
.:~ EnergyBall
{ _ebVel = v
, _ebPos = p
{ _ebVel = v `v2z` 0
, _ebPos = p `v2z` 20
, _ebTimer = 20
, _ebType = ebt
}
@@ -88,7 +89,7 @@ ebFlicker :: EnergyBall -> World -> World
ebFlicker pt
| _ebTimer pt `mod` 7 == 0 =
cWorld . lWorld . lights
.:~ LSParam (addZ 5 $ _ebPos pt) 70 (0.5 * xyzV4 (ebColor pt))
.:~ LSParam (pt ^. ebPos) 70 (0.5 * xyzV4 (ebColor pt))
| otherwise = id
ebColor :: EnergyBall -> Color
@@ -99,9 +100,12 @@ ebColor eb = case eb ^. ebType of
ExplosiveBall -> white
FlashBall -> white
ebDamage :: Point2 -> EnergyBallType -> World -> World
ebDamage sp dt = damageInCircle (const $ ebtToDamage sp dt) sp r
ebDamage :: Point3 -> EnergyBallType -> World -> World
ebDamage sp dt
| z > 0 && z < 25 = damageInCircle (const $ ebtToDamage (sp ^. _xy) dt) (sp ^. _xy) r
| otherwise = id
where
z = sp ^. _z
r = fromMaybe 5 $ dt ^? fbSize
ebtToDamage :: Point2 -> EnergyBallType -> Damage
+16 -12
View File
@@ -15,8 +15,9 @@ drawEnergyBall eb = case _ebType eb of
drawExplosiveBall :: EnergyBall -> Picture
drawExplosiveBall eb =
setLayer BloomLayer
. setDepth 20
. uncurryV translate (_ebPos eb)
-- . setDepth 20
-- . uncurryV translate (_ebPos eb)
. translate3 (_ebPos eb)
. color white
$ thickCircle r x
where
@@ -27,9 +28,10 @@ drawExplosiveBall eb =
drawStaticBall :: EnergyBall -> Picture
drawStaticBall pt =
setLayer BloomNoZWrite
. setDepth 20
-- . setDepth (_ebZ pt + 20)
. uncurryV translate (_ebPos pt)
-- . setDepth 20
-- -- . setDepth (_ebZ pt + 20)
-- . uncurryV translate (_ebPos pt)
. translate3 (_ebPos pt)
$ circleSolidCol blue (withAlpha 0.5 white) 8
drawFlamelet :: Float -> Float -> EnergyBall -> Picture
@@ -40,13 +42,13 @@ drawFlamelet size rot pt =
, setLayer BloomNoZWrite pi2
]
where
z = 20
sp = _ebPos pt
siz2 = size + 0.2
time = _ebTimer pt
piu =
setDepth (z + 5)
. uncurryV translate sp
translate3 sp
-- setDepth (z + 5)
-- . uncurryV translate sp
. color
( mixColors
(fromIntegral (max 0 (time -2)))
@@ -61,8 +63,9 @@ drawFlamelet size rot pt =
. polygon
$ reverse (rectNSWE siz2 (- siz2) (- siz2) siz2)
pi2 =
setDepth (z + 5)
. uncurryV translate sp
translate3 sp
--setDepth (z + 5)
-- . uncurryV translate sp
. color
( mixColors
(fromIntegral (max 0 (time -2)))
@@ -78,8 +81,9 @@ drawFlamelet size rot pt =
. reverse
$ rectNSWE siz2 (- siz2) (- siz2) siz2
pic =
setDepth (z + 2)
. uncurryV translate sp
translate3 sp
--setDepth (z + 2)
-- . uncurryV translate sp
. color
( mixColors
(fromIntegral (max 0 (time -2)))
+2 -1
View File
@@ -1,5 +1,6 @@
module Dodge.Machine.Destroy where
import Geometry.Vector3D
import Dodge.FloorItem
import Data.Maybe
import Dodge.Data.World
@@ -13,7 +14,7 @@ destroyMachine :: Machine -> World -> World
destroyMachine mc =
(cWorld . lWorld . machines %~ IM.delete (_mcID mc))
. deleteWallIDs (_mcWallIDs mc)
. makeExplosionAt (_mcPos mc) 0
. makeExplosionAt (_mcPos mc `v2z` 20) 0
. mcKillTerm mc
. mcKillBut mc
. destroyMcType (mc ^. mcType) mc
+6 -3
View File
@@ -14,15 +14,16 @@ import Dodge.SoundLogic
import Dodge.WorldEvent.Explosion
import Geometry.Data
import LensHelp
import Linear.V3
usePayload :: Payload -> Point2 -> Point2 -> World -> World
usePayload :: Payload -> Point3 -> Point3 -> World -> World
usePayload = \case
ExplosionPayload -> makeExplosionAt
ShrapnelBomb -> makeShrapnelAt
DudPayload -> const (const id)
makeShrapnelAt :: Point2 -> Point2 -> World -> World
makeShrapnelAt p v w =
makeShrapnelAt :: Point3 -> Point3 -> World -> World
makeShrapnelAt p' vel' w =
w
& soundMultiFrom [Explosion 0, Explosion 1] p bangS Nothing
& cWorld . lWorld . worldEvents
@@ -30,6 +31,8 @@ makeShrapnelAt p v w =
& makeShockwaveAt [] p 50 5 0 white
& cWorld . lWorld . bullets .++~ buls
where
p = p' ^. _xy
v = vel' ^. _xy
vs = replicateM 75 (randInCirc 10) & evalState $ _randGen w
drags :: [Float]
drags = replicateM 75 (state $ randomR (0.85,0.9)) & evalState $ _randGen w
+1 -1
View File
@@ -12,5 +12,5 @@ doPressPlateEvent ppe = case ppe of
ppLevelReset :: PressPlate -> World -> World
ppLevelReset pp w
| dist (_crPos $ you w) (_ppPos pp) < 20 = makeExplosionAt (_ppPos pp) 0 w
| dist (_crPos $ you w) (_ppPos pp) < 20 = makeExplosionAt (_ppPos pp `v2z` 20) 0 w
| otherwise = w
+3 -2
View File
@@ -187,7 +187,8 @@ doThrust pj smoke w =
& randGen .~ g
& cWorld . lWorld . projectiles . ix i . pjVel . _xy %~ (\v -> accel +.+ frict *.* v)
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& makeFlamelet (oldPos -.- vel) (vel +.+ rotateV (pi + sparkD) accel) 3 10
& makeFlamelet ((oldPos -.- vel) `v2z` 20)
((vel +.+ rotateV (pi + sparkD) accel) `v2z` 0) 3 10
& makeCloudAt
RocketSmoke
lifetime
@@ -285,7 +286,7 @@ explodeShell pj w =
& cWorld . lWorld . projectiles . ix pjid . pjType .~ RetiredProjectile
& cWorld . lWorld . projectiles . ix pjid . pjVel .~ 0
& cWorld . lWorld . projectiles . ix pjid . pjTimer .~ 30
& usePayload (_pjPayload pj) (pj ^. pjPos . _xy) (pj ^. pjVel . _xy)
& usePayload (_pjPayload pj) (pj ^. pjPos) (pj ^. pjVel)
& stopSoundFrom (ShellSound pjid)
& updatedetonator
where
+1 -1
View File
@@ -102,7 +102,7 @@ extraPics cfig u =
<> foldMap drawFlame (_flames lw)
<> foldMap drawEnergyBall (_energyBalls lw)
<> foldMap drawSpark (_sparks lw)
<> foldMap drawBul (_bullets lw)
<> foldMap drawBullet (_bullets lw)
<> foldMap drawBlip (_radarBlips lw)
<> _flares lw
<> foldMap drawLightSource (_lightSources lw)
+1 -1
View File
@@ -659,7 +659,7 @@ updatePulseLaser pz = case pz ^. pzTimer of
((_, OPulseBall pb):xs) -> dodam xs
.
(cWorld . lWorld . pulseBalls . ix (_pbID pb) . pbTimer .~ 0)
. makeExplosionAt (_pbPos pb) 0
. makeExplosionAt (_pbPos pb `v2z` 20) 0
_ -> id
phasev = _pzPhaseV pz
sp = _pzPos pz
+12 -8
View File
@@ -19,6 +19,8 @@ import Geometry
import LensHelp
import Picture
import RandomHelp
import Linear.V3
import Linear.Metric
makePoisonExplosionAt ::
-- | Position
@@ -68,8 +70,8 @@ makeFlameExplosionAt p w =
-- the ( Nthing :: Maybe Int ) here is "maybe" a creature id that the
-- particle passes through for the first frame of its existence
makeExplosionAt :: Point2 -> Point2 -> World -> World
makeExplosionAt p vel w =
makeExplosionAt :: Point3 -> Point3 -> World -> World
makeExplosionAt p' vel' w =
w
& soundStart (Explosion (w ^. cWorld . lWorld . lClock)) (p) bangS Nothing
& addFlames
@@ -77,13 +79,15 @@ makeExplosionAt p vel w =
.:~ MakeTempLight (LSParam (addZ 20 p) 150 (V3 1 0.5 0)) 20
& makeShockwaveAt [] p 50 50 1 white
where
fVs = replicateM 100 (randInCirc 1) & evalState $ _randGen w
fPs' = replicateM 100 (randInCirc 5) & evalState $ _randGen w
p = p' ^. _xy
fVs = fmap (`v2z` 0) $ replicateM 100 (randInCirc 1) & evalState $ _randGen w
fPs' = fmap (`v2z` 0) $ replicateM 100 (randInCirc 5) & evalState $ _randGen w
fdamps = replicateM 100 (state $ randomR (0,1)) & evalState $ _randGen w
inversePushOut v = (15 - magV v) * 0.01 *.* v
fVs' = zipWith (+.+) fVs $ map inversePushOut fPs'
inversePushOut v = (15 - norm v) * 0.01 *.*.* v
fVs' = zipWith (+.+.+) fVs $ map inversePushOut fPs'
sizes = randomRs (2, 9) $ _randGen w
times = randomRs (15, 20) $ _randGen w
mF q v damp size time = makeFlamelet (q - (2*v + 2* vel)) (v + damp *.* vel) size time
newFs = zipWith4 (mF p) (zipWith (+) fPs' (fmap (3 *.*) fVs')) fdamps sizes times
mF q v damp size time = makeFlamelet
(q - (2*v + 2* vel')) (v + damp *.*.* vel') size time
newFs = zipWith4 (mF p') (zipWith (+) fPs' (fmap (3 *.*.*) fVs')) fdamps sizes times
addFlames w' = foldl' (flip ($)) w' newFs