From 30be7b0983515799cd868b9869bdcf738546e0c5 Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 28 Dec 2024 21:58:45 +0000 Subject: [PATCH] Continue projectile udpate refactor --- src/Dodge/Data/Item/Use/Consumption/Ammo.hs | 10 +++----- src/Dodge/Projectile/Create.hs | 5 ++-- src/Dodge/Projectile/Draw.hs | 3 +-- src/Dodge/Projectile/Update.hs | 26 +++++++++++++-------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Dodge/Data/Item/Use/Consumption/Ammo.hs b/src/Dodge/Data/Item/Use/Consumption/Ammo.hs index 97f4cf410..0b5ea6f9f 100644 --- a/src/Dodge/Data/Item/Use/Consumption/Ammo.hs +++ b/src/Dodge/Data/Item/Use/Consumption/Ammo.hs @@ -22,13 +22,9 @@ data ProjectileUpdate | StartSpinPU {_pjuTime :: Int, _pjuCID :: Int, _pjuSpinAmound :: Int} | RemoteDirectionPU {_pjuStart :: Int, _pjuEnd :: Int} | ReduceSpinPU {_pjuReduceSpin :: Float} - | DestroyPU {_pjuScreenID :: Maybe (NewInt ItmInt) - ,_pjuTimer :: Int} - | TimePU - | CollisionEffectPU --- {_pjuDetonatorID :: Maybe (NewInt ItmInt) --- ,_pjuScreenID :: Maybe (NewInt ItmInt) --- } +-- | DestroyPU {_pjuScreenID :: Maybe (NewInt ItmInt) +-- ,_pjuTimer :: Int} +-- | TimePU | ApplyGravityPU deriving (Show, Eq, Ord, Read) --Generic, Flat) diff --git a/src/Dodge/Projectile/Create.hs b/src/Dodge/Projectile/Create.hs index 1e1526b30..ed1ce96f2 100644 --- a/src/Dodge/Projectile/Create.hs +++ b/src/Dodge/Projectile/Create.hs @@ -32,9 +32,8 @@ createShell mdetonator mscreen pjtype payload muz cr w = w , _pjPayload = payload , _pjTimer = lifespan , _pjUpdates = - [ CollisionEffectPU - , TimePU - , StartSpinPU (lifespan - 15) (_crID cr) spinamount + [-- TimePU + StartSpinPU (lifespan - 15) (_crID cr) spinamount , RemoteDirectionPU (lifespan - thrustdelay) 0 , ReduceSpinPU (1 - spindrag * 2 / 200) ] <> thrustorgrav diff --git a/src/Dodge/Projectile/Draw.hs b/src/Dodge/Projectile/Draw.hs index 5aff444bf..28b5663a8 100644 --- a/src/Dodge/Projectile/Draw.hs +++ b/src/Dodge/Projectile/Draw.hs @@ -4,7 +4,6 @@ module Dodge.Projectile.Draw ( import Control.Lens import Data.Strict.Tuple -import Dodge.Data.Item.Use.Consumption.Ammo import Dodge.Data.Projectile import Geometry import Picture @@ -13,7 +12,7 @@ import ShapePicture drawProjectile :: Projectile -> SPic drawProjectile pj - | Just DestroyPU{} <- pj ^? pjUpdates . ix 0 = mempty + | RetiredProjectile <- pj ^. pjType = mempty | Just NoHoming <- pj ^? pjType . rkHoming = drawShell Nothing pj | Just _ <- pj ^? pjType . rkHoming = diff --git a/src/Dodge/Projectile/Update.hs b/src/Dodge/Projectile/Update.hs index 59b23e3e5..0d414b33b 100644 --- a/src/Dodge/Projectile/Update.hs +++ b/src/Dodge/Projectile/Update.hs @@ -22,16 +22,17 @@ import NewInt import RandomHelp updateProjectile :: Projectile -> World -> World -updateProjectile pj w = foldl' (flip $ upProjectile pj) w (_pjUpdates pj) - -upProjectile :: Projectile -> ProjectileUpdate -> World -> World -upProjectile pj pu = case pu of - CollisionEffectPU -> +updateProjectile pj w = + decTimMvVel pj . shellCollisionCheck (pj ^. pjDetonatorID) (pj ^. pjScreenID) - pj - TimePU -> decTimMvVel pj + pj $ + foldl' (flip $ upProjectile pj) w (_pjUpdates pj) + +upProjectile :: Projectile -> ProjectileUpdate -> World -> World +upProjectile pj pu = case pu of +-- TimePU -> decTimMvVel pj ThrustPU st et | act st et -> doThrust pj (pj ^? pjType . rkSmoke . _Just) | otherwise -> id @@ -42,10 +43,10 @@ upProjectile pj pu = case pu of | act st et -> pjRemoteSetDirection (pj ^? pjType . rkHoming) pj | otherwise -> id ReduceSpinPU x -> reduceSpinBy x (_pjID pj) - DestroyPU mitid 0 -> destroyProjectile mitid (_pjID pj) +-- DestroyPU mitid 0 -> destroyProjectile mitid (_pjID pj) -- the following requires that this is at the top of the update list, which is -- not ideal - DestroyPU _ _ -> cWorld . lWorld . projectiles . ix (_pjID pj) . pjUpdates . ix 0 . pjuTimer -~ 1 +-- DestroyPU _ _ -> cWorld . lWorld . projectiles . ix (_pjID pj) . pjUpdates . ix 0 . pjuTimer -~ 1 ApplyGravityPU -> applyGravityPU pj where time = _pjTimer pj @@ -87,6 +88,10 @@ shellCollisionCheck :: World -> World shellCollisionCheck detid screenid pj w + | RetiredProjectile <- pj ^. pjType + , time <= -30 + = destroyProjectile (pj ^. pjScreenID) (_pjID pj) w + | RetiredProjectile <- pj ^. pjType = w | anythingHitCirc 2 oldPos (oldPos + _pjVel pj) w = g | time <= 0 = g | otherwise = w @@ -186,7 +191,8 @@ explodeShell :: World explodeShell mdetid screenid pj w = w - & cWorld . lWorld . projectiles . ix pjid . pjUpdates .~ [DestroyPU screenid 30] +-- & cWorld . lWorld . projectiles . ix pjid . pjUpdates .~ [DestroyPU screenid 30] + & cWorld . lWorld . projectiles . ix pjid . pjType .~ RetiredProjectile & usePayload (_pjPayload pj) (_pjPos pj) (_pjVel pj) & stopSoundFrom (ShellSound pjid) & updatedetonator