I made part of a game. It runs well but I would like to add enemies in my game. So far I add the image of the enemies in pygame sprites.
But how do I make the enemies follow the player? I tried do this but it just made the image of the enemy direct to the player:
def moveEnemy(self):
enemies.rect.x = player.rect.x
enemies.rect.y = player.rect.y
all_sprites_list.add(enemies)
enemies_list.add(enemies)
I thought this would make the image of the enemy follow the player. Instead it just overlaped the player's image.
I read though many pygame sprites examples but the examples saids to replace the enemies.rect.x = player.rect.x with enemies.rect.x = -5 or something around that. I also tried this but it just move the image up instead of following the player.
Do I have to formulate an equation? If so I do not know how to.
How do I make the enemy move but as well make it follow the player? Can someone help me solve this problem?
Any help would be appreciated.