Fix error in circle wall collision detection
The wall zoning did not take into account the radius of the circle
This commit is contained in:
@@ -35,6 +35,7 @@ module Dodge.Base.Collide (
|
||||
anythingHitCirc,
|
||||
) where
|
||||
|
||||
--import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
import qualified Data.IntSet as IS
|
||||
import Data.List (sortOn)
|
||||
@@ -152,13 +153,12 @@ collideCircWalls sp ep rad = foldl' findPoint (ep, Nothing)
|
||||
where
|
||||
findPoint (p, mwl) wl =
|
||||
maybe (p, mwl) (,Just wl) . uncurry (intersectSegSeg sp p)
|
||||
. shiftbyrad
|
||||
. _wlLine
|
||||
$ wl
|
||||
shiftbyrad (a, b) =
|
||||
bimap
|
||||
f
|
||||
f
|
||||
. shiftbyrad . _wlLine $ wl
|
||||
-- shiftbyrad (a, b) =
|
||||
-- ( a +.+ rad *.* normalizeV (a -.- b)
|
||||
-- , b +.+ rad *.* normalizeV (b -.- a)
|
||||
-- )
|
||||
shiftbyrad (a, b) = bimap f f
|
||||
( a +.+ rad *.* normalizeV (a -.- b)
|
||||
, b +.+ rad *.* normalizeV (b -.- a)
|
||||
)
|
||||
@@ -243,13 +243,16 @@ canSeeIndirect i j w = hasLOSIndirect ipos jpos w
|
||||
anythingHitCirc :: Float -> Point2 -> Point2 -> World -> Bool
|
||||
anythingHitCirc rad sp ep w = hitCr || isJust (sequence hitWl)
|
||||
where
|
||||
hitCr = IS.foldr f False $ crixsNearSeg sp ep w
|
||||
x = rad *.* normalizeV (ep - sp)
|
||||
xsp = sp - x
|
||||
xep = ep + x
|
||||
hitCr = IS.foldr f False $ crixsNearSeg xsp xep w
|
||||
f cid bl =
|
||||
maybe
|
||||
False
|
||||
(\cr -> null $ intersectCircSeg (_crPos cr) (rad + _crRad cr) sp ep)
|
||||
(w ^? cWorld . lWorld . creatures . ix cid)
|
||||
|| bl
|
||||
hitWl = collideCircWalls sp ep rad $ wlsNearSeg sp ep w
|
||||
hitWl = collideCircWalls sp ep rad $ wlsNearSeg xsp xep w
|
||||
|
||||
-- this should probably be wallsOnLine or something
|
||||
|
||||
Reference in New Issue
Block a user