-function doesLineIntersectPlayerPaths(path, x1, y1, x2, y2)
+function doLinesIntersect(x1,y1, x2,y2, x3,y3, x4,y4)
+ local intersect = false
+
+ if x1 == x2 and x3 == x4
+ or y1 == y2 and y3 == y4
+ then
+ -- if lines are parallel, no intersection!
+ elseif x1 == x2 and y3 == y4 then
+ intersect = (
+ x3 < x1 and x1 < x4
+ or
+ x4 < x1 and x1 < x3
+ ) and (
+ y1 < y3 and y3 < y2
+ or
+ y2 < y3 and y3 < y1
+ )
+ elseif x3 == x4 and y1 == y2 then
+ intersect = (
+ x1 < x3 and x3 < x2
+ or
+ x2 < x3 and x3 < x1
+ ) and (
+ y3 < y1 and y1 < y4
+ or
+ y4 < y1 and y1 < y3
+ )
+ else
+ print('You should never see this message')
+ end
+
+ if intersect then
+ scene.intersection = {
+ a = {x1,y1, x2,y2},
+ b = {x3,y3, x4,y4},
+ }
+ end
+
+ return intersect
+end
+
+function doesLineIntersectPlayerPaths(node, v1, v2)
+ -- for every line in path,
+ -- check intersection with player line
+ while node and node.prev do
+ local v3 = node.vector
+ local v4 = node.prev.vector
+ if doLinesIntersect(v1.x,v1.y, v2.x,v2.y, v3.x,v3.y, v4.x,v4.y) then
+ return true
+ end
+ node = node.prev
+ end