Пример #1
0
def forward(distance):
    """Move the turtle forward a given distance (in its current direction).

    Distance must be a whole number between {} and {}.

    >>> begin()
    >>> forward(2)
    >>> get_tiles()
    G
    G
    v
    """.format(min_distance, max_distance)

    _check_distance(distance, "Oops, forward({}) won't work.".format(distance), "Try this:\n\nforward(3)")

    turtle = _get_turtle_session()

    # all moves forward except the last one
    for i in xrange(distance-1):
        position_diff = calculate_point_on_sphere(direction=turtle.direction, radius=1)
        _move_relative(position_diff.x, position_diff.y, position_diff.z, False)

    # last forward move
    position_diff = calculate_point_on_sphere(direction=turtle.direction, radius=1)
    return _move_relative(position_diff.x, position_diff.y, position_diff.z, True)
Пример #2
0
def forward(distance):
    """Move the turtle forward a given distance (in its current direction).

    Distance must be a whole number between {} and {}.

    >>> begin()
    >>> forward(2)
    >>> get_tiles()
    G
    G
    v
    """.format(min_distance, max_distance)

    _check_distance(distance, "Oops, forward({}) won't work.".format(distance),
                    "Try this:\n\nforward(3)")

    turtle = _get_turtle_session()

    # all moves forward except the last one
    for i in xrange(distance - 1):
        position_diff = calculate_point_on_sphere(direction=turtle.direction,
                                                  radius=1)
        _move_relative(position_diff.x, position_diff.y, position_diff.z,
                       False)

    # last forward move
    position_diff = calculate_point_on_sphere(direction=turtle.direction,
                                              radius=1)
    return _move_relative(position_diff.x, position_diff.y, position_diff.z,
                          True)
Пример #3
0
def peek():
    turtle = _get_turtle_session()
    position_diff = calculate_point_on_sphere(direction=turtle.direction, radius=1)
    peek_x = turtle.position.x + position_diff.x
    peek_y = turtle.position.y + position_diff.y
    peek_z = turtle.position.z + position_diff.z

    if Position(peek_x, peek_y, peek_z).is_possible_in_a_minecraft_world():
        return _MC.get_block(
            turtle.position.x + position_diff.x,
            turtle.position.y + position_diff.y,
            turtle.position.z + position_diff.z)
    else:
        return None
Пример #4
0
def peek():
    turtle = _get_turtle_session()
    position_diff = calculate_point_on_sphere(direction=turtle.direction,
                                              radius=1)
    peek_x = turtle.position.x + position_diff.x
    peek_y = turtle.position.y + position_diff.y
    peek_z = turtle.position.z + position_diff.z

    if Position(peek_x, peek_y, peek_z).is_possible_in_a_minecraft_world():
        return _MC.get_block(turtle.position.x + position_diff.x,
                             turtle.position.y + position_diff.y,
                             turtle.position.z + position_diff.z)
    else:
        return None
Пример #5
0
def begin(start_distance_from_player=5,
          default_trail=[block.GOLD_BLOCK],
          sleep_function=sleep):
    """Create a new turtle, about 5 blocks out from where the player is facing.

    >>> begin()
    >>> get_tiles()
    v
    """
    pos = _MC.get_player_tile_pos()
    rotation_degrees = _MC.get_player_rotation_degrees()

    if rotation_degrees < 0:
        rotation_degrees = 360 + rotation_degrees

    horizon_pitch = 0

    facing = _facing_based_on_yaw(rotation_degrees)
    yaw = 0
    if facing == block.PISTON.FACING_SOUTH:
        yaw = 180
    if facing == block.PISTON.FACING_WEST:
        yaw = 270
    elif facing == block.PISTON.FACING_NORTH:
        yaw = 0
    elif facing == block.PISTON.FACING_EAST:
        yaw = 90
    position_diff = calculate_point_on_sphere(
        direction=Direction(yaw, horizon_pitch, 0),
        radius=start_distance_from_player)

    start_x = pos.x + position_diff.x
    start_y = pos.y + position_diff.y
    start_z = pos.z + position_diff.z
    _MC.turtle_session = TurtleSession(Position(start_x, start_y, start_z),
                                       Direction(yaw, horizon_pitch, 0),
                                       default_trail, sleep_function)
    return _draw_turtle()
Пример #6
0
def begin(start_distance_from_player=5, default_trail=[block.GOLD_BLOCK], sleep_function=sleep):
    """Create a new turtle, about 5 blocks out from where the player is facing.

    >>> begin()
    >>> get_tiles()
    v
    """
    pos = _MC.get_player_tile_pos()
    rotation_degrees = _MC.get_player_rotation_degrees()

    if rotation_degrees < 0:
        rotation_degrees = 360 + rotation_degrees

    horizon_pitch = 0

    facing = _facing_based_on_yaw(rotation_degrees)
    yaw = 0
    if facing == block.PISTON.FACING_SOUTH:
        yaw = 180
    if facing == block.PISTON.FACING_WEST:
        yaw = 270
    elif facing == block.PISTON.FACING_NORTH:
        yaw = 0
    elif facing == block.PISTON.FACING_EAST:
        yaw = 90
    position_diff = calculate_point_on_sphere(direction=Direction(yaw, horizon_pitch, 0), radius=start_distance_from_player)

    start_x = pos.x + position_diff.x
    start_y = pos.y + position_diff.y
    start_z = pos.z + position_diff.z
    _MC.turtle_session = TurtleSession(
        Position(start_x, start_y, start_z),
        Direction(yaw, horizon_pitch, 0),
        default_trail,
        sleep_function)
    return _draw_turtle()