我正在开发塔防游戏,但我遇到一个问题,即敌人向左移动然后向下移动的精灵之后没有向右移动(您可以在下面的图片中看到它)
下面是我认为问题所在的一些代码:
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