From 040a878b41ef735e205330fc4055cac319e5fb2a Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 16 Nov 2018 07:09:34 +0100 Subject: [PATCH] fix collision detection --- src/MainGame/WorldMap.hs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/MainGame/WorldMap.hs b/src/MainGame/WorldMap.hs index fbfda89..ab8f29b 100644 --- a/src/MainGame/WorldMap.hs +++ b/src/MainGame/WorldMap.hs @@ -844,25 +844,21 @@ checkBoundsCollision2 -> V2 Double checkBoundsCollision2 pre@(V2 pr pc) nex dt acc (Boundaries (minr, minc) (maxr, maxc)) - | colltr < dt && colltc < dt = V2 0 0 - | colltr < dt && incol = V2 0 1 * acc - | colltc < dt && inrow = V2 1 0 * acc + | colltr < dt || colltc < dt = V2 0 0 | otherwise = acc where V2 vr vc = fmap (/ dt) (nex - pre) colltr - | vr > 0 && prr <= maxr = + | vr > 0 && prr < maxr && (prc > minc && prc < maxc) = ((fromIntegral (floor pr :: Int) + minr - 0.15) - pr) / vr - | vr < 0 && prr >= minr = + | vr < 0 && prr > minr && (prc > minc && prc < maxc) = ((fromIntegral (floor pr :: Int) + maxr + 0.15) - pr) / vr | otherwise = dt colltc - | vc > 0 && prc <= maxc = + | vc > 0 && prc < maxc && (prr > minr && prr < maxr) = ((fromIntegral (floor pc :: Int) + minc - 0.15) - pc) / vc - | vc < 0 && prc >= minc = + | vc < 0 && prc > minc && (prr > minr && prr < maxr) = ((fromIntegral (floor pc :: Int) + maxc + 0.15) - pc) / vc | otherwise = dt - inrow = pr > minr && pr < maxr - incol = pc > minc && pc < maxc prr = pr - fromIntegral (floor pr :: Int) prc = pc - fromIntegral (floor pc :: Int)