Hello everyone! I'm making a Super Mario Bros clone game with Python and Pygame and I wrote a function that returns True if two rectangles are colliding and False otherwise. So I know how to detect when Mario collides with a monster. Now, I want to know if Mario jumped over the monster, or in other words, it's rect collided on the top side of the monster rect. How do I do that? Here is my code:
The two rectangles collision detection function:
def is_colliding(x, y, w, h, x2, y2, w2, h2):
if x < x2 + w2 and x + w > x2 and y < y2 + h2 and h + y > y2:
return True
return False
The actual checking of it in the main game loop:
while True:
# other stuff
if is_colliding(mario.x, mario.y, mario.w, mario.h, goomba1.x, goomba1.y, goomba1.w, goomba1.h):
goomba1.wounded()
Any help is appreciated. Thank you.