Start simplifying projectile update

This commit is contained in:
2025-08-03 13:46:20 +01:00
parent 5f158cc87a
commit c3b2bb30f5
10 changed files with 218 additions and 228 deletions
+2 -8
View File
@@ -48,9 +48,8 @@ createShell (p,q) mdetonator mscreen stab pjtype payload muz cr w =
, _pjTimer = lifespan
, _pjUpdates =
anyspin
<> [ RemoteDirectionPU (lifespan - thrustdelay) 0
]
<> thrustorgrav
-- <> [ RemoteDirectionPU 330 0
-- ]
, _pjType = pjtype
, _pjDetonatorID = mdetonator
, _pjScreenID = mscreen
@@ -72,11 +71,6 @@ createShell (p,q) mdetonator mscreen stab pjtype payload muz cr w =
Rocket{} -> 1
RetiredProjectile -> 0
lifespan = 350
thrustorgrav = case pjtype of
Grenade{} -> []
Rocket{} -> [ThrustPU (lifespan - thrustdelay) 0]
RetiredProjectile -> []
thrustdelay = 20
updatedetonator = fromMaybe id $ do
screenid <- mdetonator
return $
+13 -8
View File
@@ -5,6 +5,7 @@ module Dodge.Projectile.Update (
updateProjectile,
) where
import Control.Monad
import Data.Foldable
import Data.List (delete, deleteBy)
import Data.Maybe
@@ -34,18 +35,15 @@ updateProjectile pj w =
upProjectile :: Projectile -> ProjectileUpdate -> World -> World
upProjectile pj = \case
ThrustPU st et
| act st et -> doThrust pj (pj ^? pjType . rkSmoke . _Just)
| otherwise -> id
StartSpinPU t cid spinamount
| time == t -> trySpinByCID cid spinamount pj
| otherwise -> id
RemoteDirectionPU st et
| act st et -> pjRemoteSetDirection (pj ^? pjType . rkHoming) pj
| otherwise -> id
-- RemoteDirectionPU st et
-- | act st et -> pjRemoteSetDirection (pj ^? pjType . rkHoming) pj
-- | otherwise -> id
where
time = _pjTimer pj
act st et = time <= st && time >= et
-- act st et = time <= st && time >= et
doGravityPU :: Projectile -> World -> World
doGravityPU pj
@@ -143,6 +141,12 @@ destroyProjectile mitid pjid w =
loc <- w ^? cWorld . lWorld . itemLocations . ix itid
return $ pointerToItemLocation loc . itUse . uaParams . apProjectiles %~ delete pjid
tryThrust :: Projectile -> World -> World
tryThrust pj = fromMaybe id $ do
Rocket y x <- pj ^? pjType
guard $ pj ^. pjTimer <= 330 && pj ^. pjTimer >= 0
return $ doThrust pj x . pjRemoteSetDirection (Just y) pj
doThrust :: Projectile -> Maybe RocketSmoke -> World -> World
doThrust pj smoke w =
w
@@ -184,7 +188,7 @@ trySpinByCID cid i pj w =
& cWorld . lWorld . projectiles . ix pjid . pjUpdates %~ deleteBy f (StartSpinPU 0 0 0)
where
f _ StartSpinPU{} = True
f _ _ = False
-- f _ _ = False
pjid = _pjID pj
dir = argV $ _pjVel pj
newSpin = case w ^? cWorld . lWorld . creatures . ix cid of
@@ -237,6 +241,7 @@ moveProjectile pj w
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjPos +~ _pjVel pj
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir
+~ (_pjSpin pj * _pjSpinFactor pj)
& tryThrust pj
explodeShell ::
Projectile ->