def check_win(self, container : pymunk.Body) -> bool: points = [container.local_to_world((-3,-12)), container.local_to_world((3,-12)), container.local_to_world((3,12)), container.local_to_world((-3,12))] won = True (dx, dy) = (10, 26) if self.vertical else (26,-10) limits = {'x': (min(self.position.x, self.position.x + dx), max(self.position.x, self.position.x + dx)), 'y': (min(self.position.y, self.position.y + dy), max(self.position.y, self.position.y + dy))} for point in points: if (point.x < limits['x'][0] or point.x > limits['x'][1]) or (point.y < limits['y'][0] or point.y > limits['y'][1]): won = False return won;
def update_distance(self, object: pymunk.Body, active=True): to_x, to_y = self.compute_connection_point(object) assert (isinstance(to_x, float) or isinstance( to_x, int)) and (isinstance(to_y, float) or isinstance(to_y, int)) at_x, at_y = object.position if self.screen is not None: tether_pos = object.local_to_world(self.tether_offset) color = (153, 43, 43) if active else (50, 43, 43) pygame.draw.lines(self.screen, color, False, [(to_x, to_y), tether_pos]) direction_vec = np.array([to_x - at_x, to_y - at_y]) self.last_used_length = self.curr_used_length self.curr_used_length = np.linalg.norm(direction_vec) return direction_vec
def draw_segment_on_body_dashed(self, body: pymunk.Body, color, filled: bool, a: Vec2d, b: Vec2d, radius: float, dash_length: float, dash_proportion: float = .5, dash_offset: float = 0.0) -> None: a = body.local_to_world(a) b = body.local_to_world(b) self.draw_segment_dashed(color, filled, a, b, radius, dash_length, dash_proportion, dash_offset)
def draw_segment_on_body(self, body: pymunk.Body, color, filled: bool, a: Vec2d, b: Vec2d, radius: float): a = body.local_to_world(a) b = body.local_to_world(b) self.draw_segment(color, filled, a, b, radius)
def convert_shape_vector(self, body: pymunk.Body, vector: Vec2d) -> Vec2d: """Converts a shape vector belonging to the given body into a surface vector.""" # return self.convert(entity.body.position + vector.rotated(entity.body.angle)) return self.convert(body.local_to_world(vector))