跳一跳小游戏辅助(手动版本)py代码实现

注意:单纯研究游戏原理。和练习py才写的,切勿滥用。否则后果自负。


核心思路就是一个勾股定理的作用。通过2次计算完成跳跃,这些包我都打了注释。。。怎么安装,包安装方法  pip install 包名字,包安装完成就是adb。。百度安装。。配置环境变量。。。


#!/usr/bin/python
#-*-coding:utf-8 -*-
#FileName:wechat_main.py
#Author:gjt
#Date:2018/1/6 20:45

#os模块包含普通操作系统的功能
import os
#是python image library的缩写,,图像处理模块 numpy是python的一个科学计算库
import PIL,numpy
#matplotlib绘制直线,第二个矩形区域,Pyplot绘图
import matplotlib.pyplot as plt
#自定义动画函数
from matplotlib.animation import FuncAnimation
#py的时间模块
import time

need_updata = True

#获取手机截屏
def get_screen_image():
os.system('adb shell screencap -p /sdcard/screen.png') #获取当前手机目录截屏
os.system('adb pull /sdcard/screen.png') #下载当前截图到电脑上
return numpy.array(PIL.Image.open('screen.png')) #image需要大写。
#计算弦长
def jump_to_next(point1,point2):
x1,y1 = point1
x2,y2 = point2
distance = ((x2-x1)**2 + (y2-y1)**2)**0.5
os.system('adb shell input swipe 320 410 320 410 {}'.format(int(distance*1.35)))

#绑定鼠标的单击事件
def on_click(event,coor=[]):
global need_updata
coor.append((event.xdata,event.ydata))
if len(coor)==2:
jump_to_next(coor.pop(),coor.pop())
need_updata = True

#重新绘制图片
def updata_screen(frame):
global need_updata
if need_updata:
time.sleep(1)
axes_image.set_array(get_screen_image())
need_updata = False
return axes_image,

figure = plt.figure()#创建一个空白区域(设置图片对象)生成一张图片
axes_image = plt.imshow(get_screen_image(),animated = True); #把图片拿到
figure.canvas.mpl_connect('button_press_event',on_click)
ani = FuncAnimation(figure,updata_screen,interval=5,blit=True)
plt.show() #展示出来 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值