Simplify projectile wall bounce

This commit is contained in:
2025-08-05 09:15:10 +01:00
parent 298238d594
commit b433c1de43
4 changed files with 45 additions and 42 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
-1
View File
@@ -22,7 +22,6 @@ data Bullet = Bullet
, _buDrag :: Float , _buDrag :: Float
, _buPos :: Point2 , _buPos :: Point2
, _buOldPos :: Point2 , _buOldPos :: Point2
-- , _buWidth :: Float
} }
deriving (Show, Eq, Ord, Read) --Generic, Flat) deriving (Show, Eq, Ord, Read) --Generic, Flat)
+37 -35
View File
@@ -3,11 +3,11 @@
--{-# OPTIONS_GHC -Wno-unused-imports #-} --{-# OPTIONS_GHC -Wno-unused-imports #-}
module Dodge.Projectile.Update (updateProjectile) where module Dodge.Projectile.Update (updateProjectile) where
import Dodge.Data.Object
import Control.Monad import Control.Monad
import Data.List (delete) import Data.List (delete)
import Data.Maybe import Data.Maybe
import Dodge.Base import Dodge.Base
import Dodge.Data.Object
import Dodge.Data.World import Dodge.Data.World
import Dodge.EnergyBall import Dodge.EnergyBall
import Dodge.Item.Location import Dodge.Item.Location
@@ -20,10 +20,10 @@ import Dodge.WorldEvent.Sound
import Geometry import Geometry
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
import LensHelp import LensHelp
import NewInt
import RandomHelp
import Linear.Metric import Linear.Metric
import Linear.V3 import Linear.V3
import NewInt
import RandomHelp
updateProjectile :: Projectile -> World -> World updateProjectile :: Projectile -> World -> World
updateProjectile pj w = updateProjectile pj w =
@@ -42,13 +42,15 @@ doGravityPU pj
applyGravityPU :: Projectile -> World -> World applyGravityPU :: Projectile -> World -> World
applyGravityPU pj w applyGravityPU pj w
| (pj ^. pjPos . _z) < 1 && norm (_pjVel pj) < 1 = w | (pj ^. pjPos . _z) < 1 && norm (_pjVel pj) < 1 =
& topj . pjVel .~ 0 w
& topj . pjVel .~ 0
| otherwise = | otherwise =
w -- & topj . pjZ .~ newz w -- & topj . pjZ .~ newz
& topj . pjVel . _z -~ 0.5 & topj . pjVel . _z -~ 0.5
where where
topj = cWorld . lWorld . projectiles . ix (pj ^. pjID) topj = cWorld . lWorld . projectiles . ix (pj ^. pjID)
-- newz = pj ^. pjZ + pj ^. pjZVel -- newz = pj ^. pjZ + pj ^. pjZVel
-- consider pushing any hit creature back -- consider pushing any hit creature back
@@ -64,25 +66,21 @@ shellExplosionCheck pj w
time = _pjTimer pj time = _pjTimer pj
shellHitWall :: Point3 -> Point3 -> Wall -> Projectile -> World -> World shellHitWall :: Point3 -> Point3 -> Wall -> Projectile -> World -> World
shellHitWall p' _ wl pj w shellHitWall p n wl pj w
| Just GStick <- pj ^? pjType . gnHitEffect = | Just GStick <- pj ^? pjType . gnHitEffect =
w w & topj . pjType .~ Grenade (GStuckWall (wl ^. wlStructure))
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjType
.~ Grenade (GStuckWall (wl ^. wlStructure))
& soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos . _xy) & soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos . _xy)
| Just x <- pj ^? pjType . gnHitEffect . bounceTolerance | Just x <- pj ^? pjType . gnHitEffect . bounceTolerance
, abs (dotV (pj ^. pjVel . _xy) (vNormal hitline)) < x = , abs (dot (pj ^. pjVel) (normalize n)) < x =
w w
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjVel . _xy & topj . pjVel %~ reflectInNormal n
%~ reflectIn hitline & topj . pjPos .~ p + (normalize n)
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjPos . _xy
.~ p - normalizeV (pj ^. pjVel . _xy)
& soundStart (ShellSound (pj ^. pjID)) (pj ^. pjPos . _xy) click1S Nothing & soundStart (ShellSound (pj ^. pjID)) (pj ^. pjPos . _xy) click1S Nothing
| otherwise = w & cWorld . lWorld . projectiles . ix (_pjID pj) . pjPos .~ p' | otherwise =
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjTimer .~ 0 w & topj . pjPos .~ p
& topj . pjTimer .~ 0
where where
p = xyV3 p' topj = cWorld . lWorld . projectiles . ix (_pjID pj)
hitline = normalizeV $ uncurry (-) $ _wlLine wl
shellHitCreature :: Point3 -> Creature -> Projectile -> World -> World shellHitCreature :: Point3 -> Creature -> Projectile -> World -> World
shellHitCreature p cr pj w shellHitCreature p cr pj w
@@ -92,19 +90,20 @@ shellHitCreature p cr pj w
.~ Grenade .~ Grenade
( GStuckCreature ( GStuckCreature
(cr ^. crID) (cr ^. crID)
(rotate3z (- cr ^. crDir) (p - ((cr ^. crPos)`v2z`0))) (rotate3z (- cr ^. crDir) (p - ((cr ^. crPos) `v2z` 0)))
(pj ^. pjDir - cr ^. crDir) (pj ^. pjDir - cr ^. crDir)
) )
& soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos . _xy) & soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos . _xy)
| otherwise = w | otherwise =
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjTimer .~ 0 w
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjTimer .~ 0
shellHitFloor :: Point3 -> Projectile -> World -> World shellHitFloor :: Point3 -> Projectile -> World -> World
shellHitFloor p' pj w shellHitFloor p pj w
| z < 1 && norm (_pjVel pj) < 1 = w | z < 1 && norm (_pjVel pj) < 1 = w
| otherwise = | otherwise =
w w
& topj . pjPos .~ (p' & _z .~ 0.1) & topj . pjPos .~ (p & _z .~ 0.1)
& topj . pjVel . _z %~ bouncez & topj . pjVel . _z %~ bouncez
& topj . pjVel . _xy %~ decvel & topj . pjVel . _xy %~ decvel
& topj . pjSpin %~ decspin & topj . pjSpin %~ decspin
@@ -187,8 +186,11 @@ doThrust pj smoke w =
& randGen .~ g & randGen .~ g
& cWorld . lWorld . projectiles . ix i . pjVel . _xy %~ (\v -> accel +.+ frict *.* v) & cWorld . lWorld . projectiles . ix i . pjVel . _xy %~ (\v -> accel +.+ frict *.* v)
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1) & soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& makeFlamelet ((oldPos -.- vel) `v2z` 20) & makeFlamelet
((vel +.+ rotateV (pi + sparkD) accel) `v2z` 0) 3 10 ((oldPos -.- vel) `v2z` 20)
((vel +.+ rotateV (pi + sparkD) accel) `v2z` 0)
3
10
& makeCloudAt & makeCloudAt
RocketSmoke RocketSmoke
lifetime lifetime
@@ -261,17 +263,17 @@ moveStuckGrenade cid poff d pj w
moveProjectile :: Projectile -> World -> World moveProjectile :: Projectile -> World -> World
moveProjectile pj w moveProjectile pj w
| Just GStuckWall{} <- pj ^? pjType . gnHitEffect = w | Just GStuckWall{} <- pj ^? pjType . gnHitEffect = w
| Just (GStuckCreature crid poff d) <- pj ^? pjType . gnHitEffect | Just (GStuckCreature crid poff d) <- pj ^? pjType . gnHitEffect =
= moveStuckGrenade crid poff d pj w moveStuckGrenade crid poff d pj w
| (p,Just (n,OWall wl)) <- collide3 sp (sp + _pjVel pj) w | (p, Just (n, OWall wl)) <- collide3 sp (sp + _pjVel pj) w =
= shellHitWall p n wl pj w shellHitWall p n wl pj w
| (p,Just (_,OFloor)) <- collide3 sp (sp + _pjVel pj) w | (p, Just (_, OFloor)) <- collide3 sp (sp + _pjVel pj) w =
= shellHitFloor p pj w shellHitFloor p pj w
| (p,Just (_,OCreature cr)) <- collide3 sp (sp + _pjVel pj) w | (p, Just (_, OCreature cr)) <- collide3 sp (sp + _pjVel pj) w =
= shellHitCreature p cr pj w shellHitCreature p cr pj w
| (_,Just (_,OChasmWall)) <- collide3 sp (sp + _pjVel pj) w | (_, Just (_, OChasmWall)) <- collide3 sp (sp + _pjVel pj) w =
-- no stick or bounce for now -- no stick or bounce for now
= w & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjTimer .~ 0 w & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjTimer .~ 0
| otherwise = | otherwise =
w w
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjSpin *~ 0.99 & cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjSpin *~ 0.99
+3 -1
View File
@@ -29,7 +29,9 @@ import qualified Data.Map.Strict as M
testStringInit :: Universe -> [String] testStringInit :: Universe -> [String]
testStringInit u = testStringInit u =
map show (u ^.. uvWorld . cWorld . lWorld . projectiles . each . pjVel . _z) map show (take 20 $ u ^.. uvWorld . cWorld . lWorld . energyBalls . each . ebPos . _z)
<>
map show (take 20 $ u ^.. uvWorld . cWorld . lWorld . shockwaves . each . swPos . _z)
-- map shortShow (u ^.. uvWorld . cWorld . lWorld . debris . each . to g) -- map shortShow (u ^.. uvWorld . cWorld . lWorld . debris . each . to g)
-- where -- where
-- g db = (pz,z,norm v) -- g db = (pz,z,norm v)