+function doLinesIntersect(x1,y1, x2,y2, x3,y3, x4,y4)
+ if x1 == x2 and x3 == x4
+ or y1 == y2 and y3 == y4
+ then
+ -- if lines are parallel, no intersection!
+ return false
+ else
+ -- if lines are not parallel, they must intersect
+ -- do segments overlap?
+ if
+ (
+ (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
+ scene.intersection = {
+ a = {x1,y1, x2,y2},
+ b = {x3,y3, x4,y4},
+ }
+ return true
+ end
+ end
+end
+
+function doesLineIntersectPlayerPaths(path, x1,y1, x2,y2)
+ local cache = {}
+ cache.a = {}
+ cache.b = {}
+ -- for every line in path,
+ -- check intersection with player line
+ for k,v in pairs(path) do
+ if #cache.a == 2 then
+ if #cache.b == 2 then
+ if doLinesIntersect(x1,y1, x2,y2, cache.a[1],cache.a[2], cache.b[1],cache.b[2]) then
+ return true
+ end
+ end
+ cache.b = cache.a
+ cache.a = {}
+ end
+ table.insert(cache.a,v)
+ end