Replace buggy circle seg intersection with a simpler test

This commit is contained in:
2024-12-26 21:53:18 +00:00
parent 91ba6ee148
commit 0ef28c132e
29 changed files with 528 additions and 332 deletions
+29 -3
View File
@@ -3,7 +3,7 @@ module Dodge.Projectile.Update (
updateProjectile,
) where
import Control.Lens
import LensHelp
import Control.Monad
import Data.Foldable
import Data.Maybe
@@ -42,18 +42,44 @@ upProjectile pu pj = case pu of
-- the following requires that this is at the top of the update list, which is
-- not ideal
DestroyPU _ _ -> cWorld . lWorld . projectiles . ix (_prjID pj) . prjUpdates . ix 0 . pjuTimer -~ 1
ApplyGravityPU -> applyGravityPU pj
where
time = _prjTimer pj
act st et = time <= st && time >= et
applyGravityPU :: Projectile -> World -> World
applyGravityPU pj w
| newz <= 0 && abs (pj ^. prjZVel) < 1 = w
& topj . prjVel %~ decvel
& topj . prjSpin %~ decspin
| newz < 0 = w & topj . prjZ .~ 0
& topj . prjZVel %~ bouncez
& topj . prjVel %~ decvel
& topj . prjSpin %~ decspin
& soundStart (ShellSound (pj ^. prjID)) (pj ^. prjPos) click1S Nothing
| otherwise = w & topj . prjZ .~ newz
& topj . prjZVel -~ 0.5
where
topj = cWorld . lWorld . projectiles . ix (pj ^. prjID)
bouncez z | z < -1 = -0.5 * z
| otherwise = 0
decvel v
| magV v > 1 = rotateV (5 * pj ^. prjSpin) $ 0.8 * v
| otherwise = 0
decspin x
| abs x < 0.01 = 0
| otherwise = x * 0.9
newz = pj ^. prjZ + pj ^. prjZVel
--shellCollisionCheck :: (Projectile -> World -> World) -> Projectile -> World -> World
shellCollisionCheck :: Maybe (NewInt ItmInt)
-> Maybe (NewInt ItmInt)
-> Maybe (NewInt ItmInt)
-> Projectile -> World -> World
shellCollisionCheck controlid detid screenid pj w
| time > 330 && circOnSomeWall oldPos 4 w = g
| time <= 330 && anythingHitCirc 2 oldPos newPos w = g
-- | time > 330 && circOnSomeWall oldPos 4 w = g
-- | time <= 330 && anythingHitCirc 2 oldPos newPos w = g
| anythingHitCirc 2 oldPos newPos w = g
| time <= 0 = g
| otherwise = w
where