This code implements the manual click Start and end point, the program automatically determine the distance, touch screen time to complete the jump
ImportNumPy as NPImportMatplotlib.pyplot as PltImportMatplotlib.animation as animation fromPILImportImageImportMathImport TimeImportOS
defpull_screenshot (): Defines the interception of the phone screen and sends it to the computer function Os.system ('adb shell screencap-p/sdcard/autojump.png') Send a screenshot command to the phone Os.system ('adb pull/sdcard/autojump.png.'send pull pictures to computer commandsdefJump (distance): Defines the jumping function parameter as a distance press_time= distance * 1.35 Calculation by screen timePress_time=int (press_time) cmd='adb shell input swipe 410-410'+Str (press_time) Press the On-screen commandPrint(cmd) os.system (cmd) send screen command fig=plt.figure () object with custom canvas size index=0cor=[0, 0]pull_screenshot () Execute screenshot function img= Np.array (Image.open ('Autojump.png') ) Update=True Click_count=0cor= []defupdate_data ():returnNp.array (Image.open ('Autojump.png')) Im= Plt.imshow (IMG, animated=True)defUpdatefig (*args):GlobalUpdateifUpdate:time.sleep (1.5) Pull_screenshot () Im.set_array (Update_data ()) Update=FalsereturnIM,defOnClick (event):GlobalUpdateGlobalIX, iyGlobalClick_countGlobalCor#Next screenshotIX, iy=Event.xdata, event.ydata coords=[] Coords.append ((ix, iy))Print('Now =', coords) cor.append (coords) Click_count+ = 1ifClick_count > 1: Click_count=0 Cor1=Cor.pop () Cor2=cor.pop () distance= (Cor1[0][0]-cor2[0][0]) **2 + (Cor1[0][1]-cor2[0][1]) **2Distance= Distance * * 0.5Print('distance =', distance) jump (distance) update=True Fig.canvas.mpl_connect ('button_press_event', OnClick) ANI= Animation. Funcanimation (Fig, Updatefig, interval=50, blit=True) plt.show ()
Python for jumping game code parsing