]> Untitled Git - lightcycles-love.git/commitdiff
Fixed collision conditions
authorClifton James Palmer <clifton.palmer@gmail.com>
Sat, 8 Dec 2018 19:41:19 +0000 (13:41 -0600)
committerClifton James Palmer <clifton.palmer@gmail.com>
Sat, 8 Dec 2018 20:00:14 +0000 (14:00 -0600)
scene.lua

index f11fc3e53cf3e740968c1487e5c6b58f48f9d99f..08b96de3dcdd39f9e7f4f2c04a3c927891e2133c 100644 (file)
--- a/scene.lua
+++ b/scene.lua
@@ -60,10 +60,6 @@ function scene:updatePlayers(dt)
 end
 
 function doLinesIntersect(x1,y1, x2,y2, x3,y3, x4,y4)
 end
 
 function doLinesIntersect(x1,y1, x2,y2, x3,y3, x4,y4)
-    scene.intersection = {
-        a = {x1,y1, x2,y2},
-        b = {x3,y3, x4,y4},
-        }
     if x1 == x2 and x3 == x4
     or y1 == y2 and y3 == y4
     then
     if x1 == x2 and x3 == x4
     or y1 == y2 and y3 == y4
     then
@@ -73,13 +69,21 @@ function doLinesIntersect(x1,y1, x2,y2, x3,y3, x4,y4)
         -- if lines are not parallel, they must intersect
         -- do segments overlap?
         if
         -- if lines are not parallel, they must intersect
         -- do segments overlap?
         if
-            x1 <= x3 and x3 <= x2
-        and y1 <= y3 and y3 <= y2
-        or
-            x3 <= x1 and x1 <= x4
-        and y3 <= y1 and y1 <= y4
+            (
+                (x1 <= x3 and x3 <= x2 or x1 <= x4 and x4 <= x2)
+                or
+                (x3 <= x1 and x1 <= x4 or x3 <= x2 and x2 <= x4)
+            ) and (
+                (y1 <= y3 and y3 <= y2 or y1 <= y4 and y4 <= y2)
+                or
+                (y3 <= y1 and y1 <= y4 or y3 <= y2 and y2 <= y4)
+            )
         then
             scene.paused = true
         then
             scene.paused = true
+            scene.intersection = {
+                a = {x1,y1, x2,y2},
+                b = {x3,y3, x4,y4},
+                }
             return true
         end
     end
             return true
         end
     end