Skip to content
Snippets Groups Projects
Commit 9945dbfc authored by Jantz's avatar Jantz
Browse files

Fix crach when at end of path, when position is more than 1, remain at end of path.

parent c8c14102
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ class Enemy:
self.texture = pg.image.load(self.texture_path).convert_alpha()
self.path_position = 0
self.screen_position = (0, 0)
self.full_path_time = 10
self.full_path_time = 20
def calculate_current_path_segment(self, path: tuple[tuple[int, int]]) -> int:
"""
......@@ -34,11 +34,12 @@ class Enemy:
for i in range(len(path_lengths)):
if self.path_position < (current_path_length + path_lengths[i]) / full_path_length:
segment_position = (self.path_position * full_path_length - current_path_length) / path_lengths[i]
print(i, segment_position)
return i, segment_position
current_path_length += path_lengths[i]
if current_path_length >= full_path_length:
self.path_position = 0 # DEBUG VALUE !!!
# Return the end of the last path segment if the path_position more than 1
return len(path) - 2, 1
def move_along_path(self, dt: float, path: tuple[tuple[int, int]]):
"""
Moves the enemy along the path.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment