From 5fb71cec39c443ce3d793bcdb1b0e3032cb7d4b0 Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 9 Jan 2025 11:01:17 +0000 Subject: [PATCH] Start simplifying tesla arcs --- src/Dodge/Data/Item/Params.hs | 2 -- src/Dodge/Data/TeslaArc.hs | 6 ++--- src/Dodge/HeldUse.hs | 3 +-- src/Dodge/Projectile/Update.hs | 12 ++++----- src/Dodge/Tesla.hs | 46 +++++++++++++++++----------------- src/Dodge/Tesla/Draw.hs | 3 ++- 6 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/Dodge/Data/Item/Params.hs b/src/Dodge/Data/Item/Params.hs index 0fb34e498..f6c7f550c 100644 --- a/src/Dodge/Data/Item/Params.hs +++ b/src/Dodge/Data/Item/Params.hs @@ -23,8 +23,6 @@ data ItemParams , _newArcStep :: NextArcStep --ItemParams -> World -> ArcStep -> State StdGen (Maybe ArcStep) , _previousArcEffect :: PreviousArcEffect } --- | ParamMID {_paramMID :: Maybe Int} --- | BoostPropIX {_boostPropIX :: Maybe Int} data ShrinkGunStatus = FullSize | Shrunk --deriving (Eq, Ord, Show, Read) --Generic, Flat) diff --git a/src/Dodge/Data/TeslaArc.hs b/src/Dodge/Data/TeslaArc.hs index fc25c84ed..40c4a9434 100644 --- a/src/Dodge/Data/TeslaArc.hs +++ b/src/Dodge/Data/TeslaArc.hs @@ -10,11 +10,11 @@ import Control.Lens import Data.Aeson import Data.Aeson.TH import Dodge.Data.ArcStep -import Geometry.Data +--import Geometry.Data data TeslaArc = TeslaArc - { _taPoints :: [Point2] - , _taTimer :: Int +-- { _taPoints :: [Point2] + { _taTimer :: Int , _taArcSteps :: [ArcStep] , _taColor :: Color } diff --git a/src/Dodge/HeldUse.hs b/src/Dodge/HeldUse.hs index a184d6823..070c49a3b 100644 --- a/src/Dodge/HeldUse.hs +++ b/src/Dodge/HeldUse.hs @@ -644,8 +644,7 @@ mcShootAuto itm mc w -- | assumes that the item is held shootTeslaArc :: Item -> Creature -> Muzzle -> World -> World shootTeslaArc itm cr mz w = - w' - & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itParams .~ ip + w' & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itParams .~ ip where -- use items item location instead itRef = cr ^?! crManipulation . manObject . imRootSelectedItem -- unsafe!! TODO change diff --git a/src/Dodge/Projectile/Update.hs b/src/Dodge/Projectile/Update.hs index f8b279fea..b3373c335 100644 --- a/src/Dodge/Projectile/Update.hs +++ b/src/Dodge/Projectile/Update.hs @@ -209,11 +209,11 @@ pjRemoteSetDirection ph pj w = case ph of .~ 0.5 * diffAngles ((w ^. wCam . camRot) + argV (w ^. input . mousePos)) (_pjDir pj) Just (HomeUsingTargeting itid) | Just tp <- w ^? pointerToItemID itid . itTargeting . itTgPos . _Just -> - w & cWorld . lWorld . projectiles . ix (_pjID pj) . pjDir - %~ turnTo 0.2 (_pjPos pj) tp - & cWorld . lWorld . projectiles . ix (_pjID pj) . pjSpin + w + & cWorld . lWorld . projectiles . ix (_pjID pj) . pjDir + %~ turnTo 0.2 (_pjPos pj) tp + & cWorld . lWorld . projectiles . ix (_pjID pj) . pjSpin .~ 0.5 * diffAngles (turnTo 0.2 (_pjPos pj) tp (_pjDir pj)) (_pjDir pj) - _ -> w where lw = w ^. cWorld . lWorld @@ -239,8 +239,8 @@ moveProjectile pj w w & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjSpin *~ 0.99 & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjPos +~ _pjVel pj - & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir +~ - (_pjSpin pj * _pjSpinFactor pj) + & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir + +~ (_pjSpin pj * _pjSpinFactor pj) explodeShell :: Projectile -> diff --git a/src/Dodge/Tesla.hs b/src/Dodge/Tesla.hs index 86cf8b50c..2b88403e7 100644 --- a/src/Dodge/Tesla.hs +++ b/src/Dodge/Tesla.hs @@ -20,35 +20,35 @@ import Picture import RandomHelp import Shape -updateTeslaArc :: - World -> - TeslaArc -> - (World, Maybe TeslaArc) +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, Nothing) - | otherwise = (w, Just $ pt & taTimer -~ 1) + | _taTimer pt >= 0 = (w, Just $ pt & taTimer -~ 1) + | otherwise = (w, Nothing) where thearc = _taArcSteps pt - rcol = brightX 100 1.5 <$> takeOne [white, azure, blue, cyan] - rspeed = state (randomR (3, 6)) - makeaspark = randSpark ELECTRICAL rspeed rcol rdir lp + 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) = case last thearc of - ArcStep lp' ld' NothingID -> (lp', rp ld') - ArcStep lp' ld' (CrID crid) -> case w ^? cWorld . lWorld . creatures . ix crid of - Nothing -> (lp', rp ld') - Just cr -> (lp' -.- (_crRad cr + 1) *.* unitVectorAtAngle ld', rp $ ld' + pi) - ArcStep lp' ld' (WlID wlid) -> case w ^? cWorld . lWorld . walls . ix wlid of - Nothing -> (lp', rp ld') - Just wl -> - ( lp' -.- 2 *.* unitVectorAtAngle ld' - , randWallReflect ld' wl - ) + (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 @@ -67,8 +67,8 @@ makeTeslaArc ip pos dir w = ( w & randGen .~ g & cWorld . lWorld . teslaArcs .:~ TeslaArc - { _taPoints = map (^. asPos) newarc - , _taArcSteps = newarc + --{ _taPoints = map (^. asPos) newarc + { _taArcSteps = newarc , _taTimer = 2 , _taColor = brightX 100 1.5 col } @@ -97,7 +97,7 @@ updateArc :: updateArc ip w p dir = take (_arcNumber ip) <$> zipArcs ip w (ArcStep p dir NothingID) carc where carc = case _currentArc ip of - (_:xs) -> xs + (_ : xs) -> xs [] -> [] -- tail $ _currentArc ip zipArcs :: diff --git a/src/Dodge/Tesla/Draw.hs b/src/Dodge/Tesla/Draw.hs index 3daa2284a..fe7b0bb74 100644 --- a/src/Dodge/Tesla/Draw.hs +++ b/src/Dodge/Tesla/Draw.hs @@ -4,6 +4,7 @@ module Dodge.Tesla.Draw ( import Picture.Base import Dodge.Data.TeslaArc +import Dodge.Data.ArcStep import Control.Lens drawTeslaArc :: TeslaArc -> Picture @@ -17,4 +18,4 @@ drawTeslaArc pt = x | pt ^. taTimer > 0 = 3 | pt ^. taTimer >= 0 = 2 | otherwise = 0.5 - ps = _taPoints pt + ps = pt ^.. taArcSteps . each . asPos