I recommend to use a pygame.Rect object and either .collidepoint() or colliderect() to find a collision between enemy
and player
.
e.g. check if enemy
collides with the center of the player
:
player_rect = pygame.Rect(player.X, player.Y, player.W, player.H)
enemy_rect = pygame.Rect(enemy.X, enemy.Y, enemy.W, enemy.H)
if enemy_rect.collidepoint(player_rect.center):
Play=False
Note, instead of the .X
, .Y
, .W
and .H
properties of player
and enemy
you should use a pygame.Rect
object.
If you want to verify, if the enemy is exactly on the player, the it is sufficient to compare the center points of the rectangles:
if enemy_rect.center == player_rect.center:
Play=False