def get_pos(self, dist = None): if not dist: if self.dist < len(self.path) - 3: if self.dist > 0: return gfunc.get_pos_on_path(self.path, self.dist) else: return None else: return gfunc.get_pos_on_path(self.path, dist)
def show_path(self, window, window_scale, dt): # Has the path changed? if self.path != self.old_path: # Update old path self.old_path = self.path # reset the lines # Partial reset if self.old_path and self.lines: for index in range(len(self.old_path)): if self.old_path[index] != self.path[index]: break lines = self.lines[:index - 1] for next_i in range(len(self.path) - len(lines)): last = lines[len(lines) - 1] lines.append(last + 1) self.lines = lines # Complete reset else: self.lines = [] for dist in range(len(self.path) - 1): self.lines.append(dist + 0.5) reset = False # Show the lines for dist_index in range(len(self.lines)): dist = self.lines[dist_index] self.lines[dist_index] += dt * 2 # Work out positions front_dist = dist back_dist = dist - 0.5 if front_dist > 0: pos = gfunc.get_pos_on_path(self.path, front_dist) back_pos = gfunc.get_pos_on_path(self.path, back_dist) # If everything is on the path if pos and back_pos: pos = list(pos) back_pos = list(back_pos) # Center points pos[0] += 0.5 pos[1] += 0.5 back_pos[0] += 0.5 back_pos[1] += 0.5 # Scale pos pos[0] *= window_scale pos[1] *= window_scale back_pos[0] *= window_scale back_pos[1] *= window_scale # Show draw.line(window, (255, 100, 30), pos, back_pos, max(1, int(window_scale * 0.15))) else: reset = True if reset: for dist_index in range(len(self.lines)): self.lines[dist_index] -= 1