def slide(self, begin_state: Vector2, end_state: Vector2, progress: float): # mapped_progress = 0.5 + (progress - 0.25) * (progress - 0.5) * (progress - 0.75) / (0.75 * 0.25) mapped_progress = progress target = begin_state.lerp(end_state, mapped_progress) base_x, base_y = self.base_rect.topleft dx, dy = int(target.x) - base_x, int(target.y) - base_y self.rect = self.base_rect.move(dx, dy)
def check_along_path(start: Vector2, end: Vector2, distance, coins, round_start=False, round_end=False): """ This function checks if any of the coins lies within the given distance, of the line joining the given two vectors, representing the end points """ for coin in coins: section = (coin.position - start).dot(end - start) / start.distance_squared_to(end) """ Whether to round or not """ section = section if not round_start else max(0, section) section = section if not round_end else min(1, section) if 0 <= section <= 1: projection = start.lerp(end, section) if projection.distance_to(coin.position) <= distance: """ Coin lies within the distance of the vector """ return True return False