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
View File
@@ -22,7 +22,6 @@ data Bullet = Bullet
, _buDrag :: Float
, _buPos :: Point2
, _buOldPos :: Point2
-- , _buWidth :: Float
}
deriving (Show, Eq, Ord, Read) --Generic, Flat)
+41 -39
View File
@@ -3,11 +3,11 @@
--{-# OPTIONS_GHC -Wno-unused-imports #-}
module Dodge.Projectile.Update (updateProjectile) where
import Dodge.Data.Object
import Control.Monad
import Data.List (delete)
import Data.Maybe
import Dodge.Base
import Dodge.Data.Object
import Dodge.Data.World
import Dodge.EnergyBall
import Dodge.Item.Location
@@ -20,10 +20,10 @@ import Dodge.WorldEvent.Sound
import Geometry
import qualified IntMapHelp as IM
import LensHelp
import NewInt
import RandomHelp
import Linear.Metric
import Linear.V3
import NewInt
import RandomHelp
updateProjectile :: Projectile -> World -> World
updateProjectile pj w =
@@ -42,13 +42,15 @@ doGravityPU pj
applyGravityPU :: Projectile -> World -> World
applyGravityPU pj w
| (pj ^. pjPos . _z) < 1 && norm (_pjVel pj) < 1 = w
& topj . pjVel .~ 0
| (pj ^. pjPos . _z) < 1 && norm (_pjVel pj) < 1 =
w
& topj . pjVel .~ 0
| otherwise =
w -- & topj . pjZ .~ newz
& topj . pjVel . _z -~ 0.5
where
topj = cWorld . lWorld . projectiles . ix (pj ^. pjID)
-- newz = pj ^. pjZ + pj ^. pjZVel
-- consider pushing any hit creature back
@@ -64,25 +66,21 @@ shellExplosionCheck pj w
time = _pjTimer pj
shellHitWall :: Point3 -> Point3 -> Wall -> Projectile -> World -> World
shellHitWall p' _ wl pj w
shellHitWall p n wl pj w
| Just GStick <- pj ^? pjType . gnHitEffect =
w
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjType
.~ Grenade (GStuckWall (wl ^. wlStructure))
w & topj . pjType .~ Grenade (GStuckWall (wl ^. wlStructure))
& soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos . _xy)
| Just x <- pj ^? pjType . gnHitEffect . bounceTolerance
, abs (dotV (pj ^. pjVel . _xy) (vNormal hitline)) < x =
, abs (dot (pj ^. pjVel) (normalize n)) < x =
w
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjVel . _xy
%~ reflectIn hitline
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjPos . _xy
.~ p - normalizeV (pj ^. pjVel . _xy)
& topj . pjVel %~ reflectInNormal n
& topj . pjPos .~ p + (normalize n)
& soundStart (ShellSound (pj ^. pjID)) (pj ^. pjPos . _xy) click1S Nothing
| otherwise = w & cWorld . lWorld . projectiles . ix (_pjID pj) . pjPos .~ p'
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjTimer .~ 0
| otherwise =
w & topj . pjPos .~ p
& topj . pjTimer .~ 0
where
p = xyV3 p'
hitline = normalizeV $ uncurry (-) $ _wlLine wl
topj = cWorld . lWorld . projectiles . ix (_pjID pj)
shellHitCreature :: Point3 -> Creature -> Projectile -> World -> World
shellHitCreature p cr pj w
@@ -92,19 +90,20 @@ shellHitCreature p cr pj w
.~ Grenade
( GStuckCreature
(cr ^. crID)
(rotate3z (- cr ^. crDir) (p - ((cr ^. crPos)`v2z`0)))
(rotate3z (- cr ^. crDir) (p - ((cr ^. crPos) `v2z` 0)))
(pj ^. pjDir - cr ^. crDir)
)
& soundOriginIDsAt (ShellSound (pj ^. pjID)) [slapS, slap1S] (pj ^. pjPos . _xy)
| otherwise = w
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjTimer .~ 0
| otherwise =
w
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjTimer .~ 0
shellHitFloor :: Point3 -> Projectile -> World -> World
shellHitFloor p' pj w
| z < 1 && norm (_pjVel pj) < 1 = w
| otherwise =
w
& topj . pjPos .~ (p' & _z .~ 0.1)
shellHitFloor p pj w
| z < 1 && norm (_pjVel pj) < 1 = w
| otherwise =
w
& topj . pjPos .~ (p & _z .~ 0.1)
& topj . pjVel . _z %~ bouncez
& topj . pjVel . _xy %~ decvel
& topj . pjSpin %~ decspin
@@ -187,8 +186,11 @@ doThrust pj smoke w =
& randGen .~ g
& cWorld . lWorld . projectiles . ix i . pjVel . _xy %~ (\v -> accel +.+ frict *.* v)
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& makeFlamelet ((oldPos -.- vel) `v2z` 20)
((vel +.+ rotateV (pi + sparkD) accel) `v2z` 0) 3 10
& makeFlamelet
((oldPos -.- vel) `v2z` 20)
((vel +.+ rotateV (pi + sparkD) accel) `v2z` 0)
3
10
& makeCloudAt
RocketSmoke
lifetime
@@ -245,7 +247,7 @@ pjRemoteSetDirection ph pj w = case ph of
lw = w ^. cWorld . lWorld
moveStuckGrenade :: Int -> Point3 -> Float -> Projectile -> World -> World
moveStuckGrenade cid poff d pj w
moveStuckGrenade cid poff d pj w
| Just cr <- w ^? cWorld . lWorld . creatures . ix cid =
let cpos = cr ^. crPos
cdir = cr ^. crDir
@@ -261,17 +263,17 @@ moveStuckGrenade cid poff d pj w
moveProjectile :: Projectile -> World -> World
moveProjectile pj w
| Just GStuckWall{} <- pj ^? pjType . gnHitEffect = w
| Just (GStuckCreature crid poff d) <- pj ^? pjType . gnHitEffect
= moveStuckGrenade crid poff d pj w
| (p,Just (n,OWall wl)) <- collide3 sp (sp + _pjVel pj) w
= shellHitWall p n wl pj w
| (p,Just (_,OFloor)) <- collide3 sp (sp + _pjVel pj) w
= shellHitFloor p pj w
| (p,Just (_,OCreature cr)) <- collide3 sp (sp + _pjVel pj) w
= shellHitCreature p cr pj w
| (_,Just (_,OChasmWall)) <- collide3 sp (sp + _pjVel pj) w
| Just (GStuckCreature crid poff d) <- pj ^? pjType . gnHitEffect =
moveStuckGrenade crid poff d pj w
| (p, Just (n, OWall wl)) <- collide3 sp (sp + _pjVel pj) w =
shellHitWall p n wl pj w
| (p, Just (_, OFloor)) <- collide3 sp (sp + _pjVel pj) w =
shellHitFloor p pj w
| (p, Just (_, OCreature cr)) <- collide3 sp (sp + _pjVel pj) w =
shellHitCreature p cr pj w
| (_, Just (_, OChasmWall)) <- collide3 sp (sp + _pjVel pj) w =
-- 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 =
w
& 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 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)
-- where
-- g db = (pz,z,norm v)