Improve creature wall collisions

This commit is contained in:
2022-05-19 09:06:22 +01:00
parent 914cae8212
commit 565a71a5a2
+5 -3
View File
@@ -36,13 +36,14 @@ colCrWall w c
where
-- c'' = c' & crPos %~ pushOutFromWalls rad ls
--c' = c & crPos %~ pushOutFromWalls' rad (reverse ls)
c' = c & crPos %~ pushOutFromCorners rad ls
. pushOutFromWalls rad ls
c' = c & crPos %~ pushOutFromCorners rad ls'
. pushOutFromWalls rad ls'
. flip (collidePointWalls p1) wls -- check push throughs
rad = _crRad c + wallBuffer
p1 = _crOldPos c
p2 = _crPos c
ls = IM.elems $ _wlLine <$> wls
ls' = filter (uncurry $ isLHS p1) ls
wls = IM.filter (not . _wlWalkable) $ wallsNearPoint p2 w
--wallPoints = map fst ls
@@ -59,7 +60,8 @@ pushCreatureOutFromWalls ls cr = cr & crPos %~ pushOutFromWalls (_crRad cr) ls
pushOutFromWalls :: Float -> [(Point2,Point2)] -> Point2 -> Point2
pushOutFromWalls rad wls p1 = case (getFirst . foldMap (First . pushOutFromWall rad p1)) wls of
Nothing -> p1
Just p2 -> fromMaybe p2 $ (getLast . foldMap (Last . pushOutFromWall rad p2)) wls
--Just p2 -> fromMaybe p2 $ (getLast . foldMap (Last . pushOutFromWall rad p2)) wls
Just p2 -> pushOutFromWalls rad (tail wls) p2
-- possible improvement: choose between the closer of p2 and "p3" to p1
--pushOutFromWalls' :: Float -> [(Point2,Point2)] -> Point2 -> Point2