Ejemplo n.º 1
0
    def move_box(self, pos: Point2d, vel: Vector2d,
                 size: Vector2d) -> Tuple[Point2d, Vector2d]:
        distance = vel.norm
        maximum = int(distance)

        if distance < 0:
            return pos, vel

        fraction = 1.0 / float(maximum + 1)

        for i in range(0, maximum + 1):
            new_pos = pos + vel * fraction  # type: Point2d
            if self.test_box(new_pos, size):
                hit = False
                if self.test_box(Point2d(pos.x, new_pos.y), size):
                    new_pos.y = pos.y
                    vel.y = 0
                    hit = True

                if self.test_box(Point2d(new_pos.x, pos.y), size):
                    new_pos.x = pos.x
                    vel.x = 0
                    hit = True

                if not hit:
                    new_pos = pos
                    vel = Vector2d(0, 0)

            pos = new_pos

        return pos, vel
Ejemplo n.º 2
0
def move_camera(camera: Vector2d, focus: Point2d) -> None:
    # Objective 7: Find the correct value for half the window width
    # YOUR CODE HERE...
    half_win_width = 500

    # Objective 7: Uncomment and try out the different camera movements

    #1. always in center:
    camera.x = focus.x - half_win_width