Pardon the mess, Play My Code is in beta!

READY TO PLAY?
CLICK TO LOG IN!

sign up - lost password

isLineOverlap

isLineOverlap( x1, y1, x2, y2, x3, y3, x4, y4 )

This allows you to check if two lines overlap. True is returned if they do, and false if they do not.

The first line is from x1 by y1, to x2 by y2. The second line is from x3 by y3, to x4 by y4.

// tests if there is an overlap between old and new X and Y's,
// between a theoretical 'a' and 'b' objects
if isLineOverlap( a.oldX(), a.oldY(), a.newX(), a.newY(), b.oldX(), b.oldY(), b.newX(), b.newY() )
    // there is a collision!
end

One place where you might want to use this is useful for checking the collisions between a Bullet and a Player. The lines could be from the old to new location of the Bullet and Player, to see if they collide on the current frame.