Continue work on projectiles

This commit is contained in:
2025-08-04 11:54:07 +01:00
parent a68013b934
commit 80d6133fd6
2 changed files with 39 additions and 40 deletions
+19 -21
View File
@@ -41,16 +41,6 @@ doGravityPU pj
applyGravityPU :: Projectile -> World -> World
applyGravityPU pj w
-- | newz <= 0 && abs (pj ^. pjZVel) < 1 =
-- w
-- & topj . pjVel %~ decvel
-- & topj . pjSpin %~ decspin
-- | newz < 0 =
-- w & topj . pjZ .~ 0
-- & topj . pjZVel %~ bouncez
-- & topj . pjVel %~ decvel
-- & topj . pjSpin %~ decspin
-- & soundStart (ShellSound (pj ^. pjID)) (pj ^. pjPos) click1S Nothing
| _pjZ pj < 1 && abs (norm $ _pjVel pj `v2z` _pjZVel pj) < 1 = w
& topj . pjVel .~ 0
| otherwise =
@@ -58,15 +48,6 @@ applyGravityPU pj w
& topj . pjZVel -~ 0.5
where
topj = cWorld . lWorld . projectiles . ix (pj ^. pjID)
bouncez z
| z < -1 = -0.5 * z
| otherwise = 0
decvel v
| magV v > 1 = rotateV (5 * pj ^. pjSpin) $ 0.8 * v
| otherwise = 0
decspin x
| abs x < 0.01 = 0
| otherwise = x * 0.9
newz = pj ^. pjZ + pj ^. pjZVel
-- consider pushing any hit creature back
@@ -102,6 +83,23 @@ shellHitWall p' n wl pj w
p = xyV3 p'
hitline = normalizeV $ uncurry (-) $ _wlLine wl
shellHitCreature :: Point3 -> Point3 -> Creature -> Projectile -> World -> World
shellHitCreature p' n cr pj w
| Just GStick <- pj ^? pjType . gnHitEffect =
w
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjType
.~ Grenade
( GStuckCreature
(cr ^. crID)
(rotate3z (- cr ^. crDir) (p' - ((cr ^. crPos)`v2z`0)))
(pj ^. pjDir - cr ^. crDir)
)
& soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos)
| otherwise = w & cWorld . lWorld . projectiles . ix (_pjID pj) . pjPos .~ p
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjTimer .~ 0
where
p = xyV3 p'
shellHitFloor :: Point3 -> Point3 -> Projectile -> World -> World
shellHitFloor p' n pj w
| z < 1 && abs (norm $ _pjVel pj `v2z` zvel) < 1 = w
@@ -271,8 +269,8 @@ moveProjectile pj w
= shellHitWall p n wl pj w
| (p,Just (n,OFloor)) <- collide3 (p `v2z` (_pjZ pj)) ((p + _pjVel pj)`v2z` (_pjZ pj + _pjZVel pj) ) w
= shellHitFloor p n pj w
| (p,Just po) <- collide3 (p `v2z` (_pjZ pj)) ((p + _pjVel pj)`v2z` (_pjZ pj + _pjZVel pj) ) w
= tryShellBounce p po pj w
| (p,Just (n,OCreature cr)) <- collide3 (p `v2z` (_pjZ pj)) ((p + _pjVel pj)`v2z` (_pjZ pj + _pjZVel pj) ) w
= shellHitCreature p n cr pj w
| otherwise =
w
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjSpin *~ 0.99