Play around with tesla arcs

This commit is contained in:
2025-01-16 12:18:25 +00:00
parent 5fb71cec39
commit 881b866ed2
11 changed files with 227 additions and 230 deletions
+46 -1
View File
@@ -7,6 +7,9 @@ Description : Simulation update
-}
module Dodge.Update (updateUniverse) where
import Dodge.Damage
import RandomHelp
import Dodge.Data.CrWlID
import Dodge.ListDisplayParams
import Color
import Control.Applicative
@@ -46,7 +49,6 @@ import Dodge.SmoothScroll
import Dodge.SoundLogic
import Dodge.Spark
import Dodge.Terminal.Type
import Dodge.Tesla
import Dodge.TmTm
import Dodge.TractorBeam.Update
import Dodge.Update.Camera
@@ -530,6 +532,49 @@ updateBullets w = w' & cWorld . lWorld . bullets <>~ catMaybes ps
updateTeslaArcs :: World -> World
updateTeslaArcs = updateObjCatMaybes teslaArcs updateTeslaArc
updateTeslaArc :: World -> TeslaArc -> (World, Maybe TeslaArc)
updateTeslaArc w pt
| _taTimer pt == 2 =
( makesparks $ foldl' (flip damthings) w thearc
, Just $ pt & taTimer -~ 1
)
| _taTimer pt >= 0 = (w, Just $ pt & taTimer -~ 1)
| otherwise = (w, Nothing)
where
thearc = _taArcSteps pt
makeaspark =
randSpark
ELECTRICAL
(state (randomR (3, 6)))
(brightX 100 1.5 <$> takeOne [white, azure, blue, cyan])
rdir
lp
makesparks = makeaspark . makeaspark . makeaspark
rp x = randPeakedParam 2 (x - 0.7) x (x + 0.7)
(lp, rdir)
| ArcStep lp' ld' (CrID crid) <- last thearc
, Just cr <- w ^? cWorld . lWorld . creatures . ix crid =
(lp' -.- (_crRad cr + 1) *.* unitVectorAtAngle ld', rp $ ld' + pi)
| ArcStep lp' ld' (WlID wlid) <- last thearc
, Just wl <- w ^? cWorld . lWorld . walls . ix wlid =
( lp' -.- 2 *.* unitVectorAtAngle ld'
, randWallReflect ld' wl
)
| ArcStep lp' ld' _ <- last thearc = (lp', rp ld')
damthings (ArcStep p dir crwl) = damageCrWlID (thedamage p dir) crwl
thedamage p dir = Damage ELECTRICAL 50 (p -.- q) p (p +.+ q) NoDamageEffect
where
q = 5 *.* unitVectorAtAngle dir
randWallReflect :: RandomGen g => Float -> Wall -> State g Float
randWallReflect a wl = randPeaked a1 outa a2
where
(x, y) = _wlLine wl
outa = reflectAngle a x y
a1 = nearestAngleRep outa $ argV (x - y)
a2 = if a1 < outa then a1 + pi else a1 - pi
updateTractorBeams :: World -> World
updateTractorBeams = updateObjCatMaybes tractorBeams updateTractorBeam