I have an object that needs to follow 4 points given by the coordinates in self.list
. When I execute the code, I can see that the checks are passed and it augments the search coordinates to the next point but the object on screen only goes to the last one.
Working in Python 3 and in pygame.
How can I fix this?
class Enemy:
def __init__(self, image):
super().__init__()
self.image = pygame.image.load(image)
self.rect = self.image.get_rect()
self.rect.x = 1280
self.rect.y = randrange(abs(720 - self.rect.height))
self.pattern = 2
self.list = [(1100,360),(900,180),(700,360),(900,540)]
self.tuple_dest = self.list[0]
self.i = 0
self.p=False
def move(self, player):
if self.tuple_dest[0] <= self.rect.x:
self.rect.x -= 1
elif self.tuple_dest[0] >= self.rect.x:
self.rect.x += 1
if self.tuple_dest[1] <= self.rect.y:
self.rect.y -= 1
elif self.tuple_dest[1] >= self.rect.y:
self.rect.y += 1
#check if arrived
print(self.p)
if self.tuple_dest[0] == self.list[self.i][0] and self.tuple_dest[1] == self.list[self.i][1] and self.p == False:
self.p = True
if self.i < (len(self.list)-1) and self.p==True:
print(self.p)
self.i += 1
print(self.i)
self.tuple_dest = self.list[self.i]
self.p = False