The image should move from the top left corner to the bottom right corner. and vice versa. This works if the width and height of the screen are the same. If the width is larger, the image lands above the lower right corner
def basisfunktion(self,j):
self.rect.x, x1 = self.li[j] ,self.li[j]
self.rect.y, y1 = self.li[j + 2] , self.li[j + 2]
x2 = self.li[j+1]
y2 = self.li[j+3]
self.dx = x2 - x1
self.dy = y2 - y1
self.dist = math.sqrt(self.dx * self.dx + self.dy * self.dy)
def update(self):
if self.rect.x >= 0 and self.rect.x <= screen_x and self.rect.y >= 0 and self.rect.y <= screen_y:
self.rect.x += self.speed *self.dx / self.dist
self.rect.y += self.speed *self.dy / self.dist
screen.blit(self.image,(self.rect.x, self.rect.y))
else:
if self.index< (len(self.li)-4):
self.index += 4
self.rect.x = -1
self.rect.y = -1
runbaby.basisfunktion(self.index)