Esempio n. 1
0
        def wrapper():
            # Setup
            if separate_session:
                shcall(KILL_MINECRAFT_CMD)

            time.sleep(0.5)
            if shcall(IS_RUNNING_MINECRAFT_CMD):
                shcall(MINECRAFT_CMD)
                time.sleep(0.5)
                show(False)

            if not window_visible(get_wid()):
                show(True)
                time.sleep(0.5)
                shcall(XDOTOOL_CMD + "key Return")
                shcall(XDOTOOL_CMD + "key Return")
                time.sleep(3)

            if in_box:
                mc = mc_create()

                mc.setBlocks(0, 0, 0, BOX_WIDTH+1, BOX_HEIGHT-1, BOX_WIDTH+1, block.BRICK_BLOCK)
                mc.setBlocks(0, BOX_HEIGHT, 0, BOX_WIDTH+1, 128, BOX_WIDTH+1, block.AIR)
                mc.setBlocks(1, 1, 1, BOX_WIDTH, BOX_HEIGHT, BOX_WIDTH, block.AIR)
                mc.player.setPos(BOX_MIDDLE, 1, BOX_MIDDLE)
            
                a = mc.player.getPos()
                angle_to_x = 999
                while abs(angle_to_x) > 0.3:
                    mc.player.setTilePos(a)
                    control.forward(0.1)
                    b = mc.player.getPos()
                    angle_to_x = degrees(atan2((b.x - a.x),(b.z - a.z)))
                    #
                    # look adjustment tweaked for speed - look() approx 5x
                    # angle, except when close, then adjust more agressively.
                    #
                    adjust = angle_to_x*10 if angle_to_x < 3 else angle_to_x*5
                    slow_look(right=int(adjust), delay=0.05)
                LOOK_TO_CENTER_DIST = 423
                LOOK_UP_MAX = 2000
                slow_look(up=LOOK_UP_MAX, delay=0.2)
                slow_look(up=-LOOK_TO_CENTER_DIST, delay=0.2)
                control.stop()

                # Must reset position to center, as look()ing may have shifted
                # us off-center.
                mc.player.setPos(BOX_MIDDLE, 1, BOX_MIDDLE)

            passed = func()

            # Teardown
            if separate_session:
                show(False)
                shcall(KILL_MINECRAFT_CMD)

            return passed
Esempio n. 2
0
def move_forward_nowait():
    '''
    Test the wait=False parameter of the move functions, by running forward()
    with no wait, and testing that the expected position over time is correct.
    expected positions were determined experimentally, but start in the middle
    of tile 1, and increase until the player stops moving.
    '''
    expected_pos = {
        0.00 : 1.50000,
        0.50 : 3.39960,
        0.90 : 5.12587,
        1.50 : 5.81656,
        2.00 : 5.81715,
    }
    actual_pos = {}

    mc = mc_create()
    time.sleep(1)
    mc.player.setTilePos(1, 1, 1)
    start = time.time()
    control.forward(duration=1, wait=False)
    func_time = time.time() - start
    print("func_time: ", func_time)
    for t in sorted(expected_pos.keys()):
        if t > 0:
            time_since_start = time.time() - start
            time.sleep(t - time_since_start)
        actual_pos[t] = mc.player.getPos().z
    failed = False
    for t in sorted(expected_pos.keys()):
        print("Time: {:1.2f}    Actual Pos: {:2.5f}    Expected Pos: {:2.5f}".format(
            t, actual_pos[t], expected_pos[t]))
        if abs(expected_pos[t]-actual_pos[t])/expected_pos[t] > 0.01:
            failed = True
            print("FAILED: position not within 1%")
    return func_time < 0.02 and not failed
left = Button(23)
right = Button(14)
up = Button(18)
down = Button(15)

accel = Accel()

while True:
    if left.is_pressed():
        control.left()
    else:
        control.left(release=True)
    if right.is_pressed():
        control.right()
    else:
        control.right(release=True)
    if up.is_pressed():
        control.forward()
    else:
        control.forward(release=True)
    if down.is_pressed():
        control.backward()
    else:
        control.backward(release=True)

    x, y, z = accel.forces()
    control.look(up=20*y, left=20*x)
    
    time.sleep(0.01)

Esempio n. 4
0
left = Button(23)
right = Button(14)
up = Button(18)
down = Button(15)

accel = Accel()

while True:
    if left.is_pressed():
        control.left()
    else:
        control.left(release=True)
    if right.is_pressed():
        control.right()
    else:
        control.right(release=True)
    if up.is_pressed():
        control.forward()
    else:
        control.forward(release=True)
    if down.is_pressed():
        control.backward()
    else:
        control.backward(release=True)

    x, y, z = accel.forces()
    control.look(up=20 * y, left=20 * x)

    time.sleep(0.01)
Esempio n. 5
0
 def custom_move(duration):
     control.forward(duration=0.25)
Esempio n. 6
0
 def custom_move(duration):
     control.forward()
     time.sleep(0.25)
     control.forward(release=True)
Esempio n. 7
0
 def custom_move(duration):
     control.forward()
     time.sleep(0.25)
     control.stop()