Movement example from the old forum.
from phBot import *
import QtBind
import threading
from math import sqrt
from time import sleep
log('[%s] Loaded' % __name__)
gui = QtBind.init(__name__, 'Movement Example')
QtBind.createLabel(gui, 'X', 10, 5)
QtBind.createLabel(gui, 'Y', 10, 25)
line_x = QtBind.createLineEdit(gui, '', 25, 5, 64, 16)
line_y = QtBind.createLineEdit(gui, '', 25, 25, 64, 16)
button1 = QtBind.createButton(gui, 'move_clicked', 'Move', 10, 50)
def move(x, y, z):
move_to(x, y, z)
count = 0
while sqrt((x - get_character_data()['x']) ** 2 + (y - get_character_data()['y']) ** 2) > 4:
sleep(1.0)
count += 1
if count > 30:
log('30 seconds have elapsed, giving up')
return
log('Arrived at %f, %f' % (get_character_data()['x'], get_character_data()['y']))
def move_clicked():
x = float(QtBind.text(gui, line_x))
y = float(QtBind.text(gui, line_y))
log('Using a thread to move to %f, %f' % (x, y))
threading.Thread(target=move, args=(x, y, 0.0)).start()