Collision Detection

xLinesUp = object1Left <= object2Right && object1Right >= object2Left

yLinesUp = object1Top <= object2Bottom && object1Bottom >= object2Top

objectsTouching = xLinesUp && yLinesUp

object 1
object 2

Use the arrow keys to move object 1. The objects will turn green when they touch.