Check wall collisions when expanding

This commit is contained in:
2021-11-18 21:15:50 +00:00
parent a546d070f0
commit 15f2c419d2
7 changed files with 58 additions and 36 deletions
+8 -5
View File
@@ -1,6 +1,7 @@
{- | Deals with moving creature wall collisions. -}
module Dodge.WallCreatureCollisions
( colCrsWalls
, colCrWall
) where
import Dodge.Data
--import Dodge.Data.DamageType
@@ -16,13 +17,15 @@ import Control.Lens
import qualified Data.IntMap.Strict as IM
colCrsWalls :: World -> World
colCrsWalls w = over creatures (fmap (colCrWall w)) w
colCrsWalls w = w & creatures %~ fmap (colCrWall w)
colCrWall :: World -> Creature -> Creature
colCrWall w c
| noclipIsOn && _crID c == 0 = c -- for noclip
| p1 == p2 = pushOrCrush ls c
| otherwise = c & crPos %~ pushOutFromWalls rad ls
| otherwise = c & crPos %~
pushOutFromWalls rad (reverse ls)
. pushOutFromWalls rad ls
. flip (collidePointWalls p1) wls -- check push throughs
where
rad = _crRad c + wallBuffer
@@ -60,12 +63,12 @@ pushOrCrush wls cr = case mapMaybe (pushOutFromWall (_crRad cr) cpos) wls of
-- assumes wall points are different
pushOutFromWall :: Float -> Point2 -> (Point2,Point2) -> Maybe Point2
pushOutFromWall rad cp2 (wp1,wp2)
| isOnWall = Just newP -- +.+ (1 *.* norm))
| isOnWall = Just newP
| otherwise = Nothing
where
norm = errorNormalizeV 61 $ vNormal (wp1 -.- wp2)
wp1' = (rad *.* norm) +.+ wp1
wp2' = (rad *.* norm) +.+ wp2
wp1' = wp1 +.+ rad *.* norm
wp2' = wp2 +.+ rad *.* norm
newP = errorClosestPointOnLine 5 wp1' wp2' cp2
isOnWall = circOnSegNoEndpoints wp1 wp2 cp2 rad