You need to implement some kind of collision detection. The simplest way to do this is to use bounding boxes to check if two boxes intersects. The following function takes two box objects, and returns true/false based on if they collide or not:
def collides(box1, box2):
return !((box1.bottom < box2.top) or
(box1.top > box2.bottom) or
(box1.left > box2.right) or
(box1.right < box2.left))
class Box(top, bottom, left, right):
def __init__(self, top, bottom, left, right):
self.top = top
self.bottom = bottom
self.left = left
self.right = right
You can read more about this algorithm at: Basic 2D Collision Detection.
For more info see: StackOverflow - Basic 2D Collision Detection.