Pygame sprite не двигается сразу после перемещения вниз - PullRequest
0 голосов
/ 13 апреля 2020

Я работаю над игрой Tower Defense, и у меня есть проблема, когда вражеские спрайты после перемещения влево и вниз не двигаются сразу после этого (вы можете увидеть это на пи c ниже)

enter image description here

Он представляет собой код ниже, где я думаю, что проблема:

x1, y1 = self.path[self.path_pos]
        if self.path_pos + 1 >= len(self.path):
            x2, y2 = (1010, 493)
        else:
            x2, y2 = self.path[self.path_pos + 1]

        dirn = ((x2 - x1), (y2 - y1))
        length = math.sqrt((dirn[0])**2 + (dirn[1])**2)
        dirn = (dirn[0]/length, dirn[1]/length)

        move_x, move_y = (self.x + dirn[0], self.y + dirn[1])


        self.x = move_x
        self.y = move_y

        # go to next point
        if dirn[0] >= 0: # moving right
            if dirn[1] >= 0: # moving down
                if self.x >= x2 and self.y >= y2:
                    self.path_pos += 1
            else:
                if self.x >= x2 and self.y <= y2:
                    self.path_pos += 1
        else: # moving left
            if dirn[1] >= 0: # moving down
                if self.x <= x2 and self.y >= y2:
                    self.path_pos += 1
            else:
                if self.x <= x2 and self.y <= y2:
                    self.path_pos += 1
self.width = 44
        self.height = 66
        self.animation_count = 0
        self.health = 1
        self.vel = 3
        self.path = [(-10, 211), (14, 211), (118, 211), (128, 60), (280, 59), (285, 263), (490, 266), (492, 165), (753, 164),
                     (754, 373), (209, 373), (210, 615), (359, 615), (365, 504), (508, 506), (514, 640), (773, 639),
                     (776, 536), (881, 534), (880, 493), (1010, 439)]
        self.x = self.path[0][0]
        self.y = self.path[0][1]
        self.path_pos = 0
        self.img = None
        self.move_count = 0
        self.dis = 0
        self.imgs = []
        self.flipped = False
...