用了三天时间才写完,实现了通过图片识别读取坐标数值,自动寻路等简单功能。
主要的难点在于游戏中的坐标系,和电脑屏幕的坐标系存在三维旋转关系,难以换算。
//全局变量:第一个数左上右下坐标
Global first1x
Global first1y
Global first2x
Global first2y //全局变量:xp技点位置
Global xpx
Global xpy //全局变量:读取到的数字
Global x1
Global x2
Global x3
Global x4
Global y1
Global y2
Global y3
Global y4 //全局变量:读到的坐标
Global nowx
Global nowy //全局变量:屏幕中间点实际坐标
Global actualx
Global actualy //主体 //初始化变量
Call init() //自动按键
Call startKey() //自动点击XP技
If Form1.CheckBox1.Value = Then
BeginThread findclick()
End If //自动寻路
Select Case Form1.ComboBox1.ListIndex
Case
Call go1()
Case Else
End Select // 子程序:按1寻路
Sub go1()
While
Call headTo(, )
Call headTo(, )
Call headTo(, )
Call headTo(, )
Call headTo(, )
Call headTo(, )
Wend
End Sub //子程序:初始化
Sub init() first1x =
first1y =
first2x =
first2y = xpx =
xpy = //获取屏幕中间点实际坐标
actualx = Plugin.GetSysInfo.GetScreenResolutionX /
actualy = Plugin.GetSysInfo.GetScreenResolutionY / End Sub //子程序:得到当前坐标,保存到nowx,nowy
Sub get() //得出X坐标
x1 = find(first1x, first1y, first2x, first2y) x2 = find(first1x + , first1y, first2x + , first2y) If x2 >= Then
x3 = find(first1x + , first1y, first2x + , first2y)
If x3 >= Then
x4 = find(first1x + , first1y, first2x + , first2y)
If x4 >= Then
nowx = x1 * + x2 * + x3 * + x4
Else
nowx = x1* + x2* + x3
End If
Else
nowx = x1* + x2
End If
Else
nowx = x1
End If //得出Y坐标
y1 = find(first1x + , first1y, first2x + , first2y) y2 = find(first1x + , first1y, first2x + , first2y) If y2 >= Then
y3 = find(first1x + , first1y, first2x + , first2y)
If y3 >= Then
y4 = find(first1x + , first1y, first2x + , first2y)
If y4 >= Then
nowy = y1 * + y2 * + y3 * + y4
Else
nowy = y1* + y2* + y3
End If
Else
nowy = y1* + y2
End If
Else
nowy = y1
End If End Sub //函数:通过参数first1x,first1y,first2x,first2y返回检测到的数字
Function find(first1x, first1y, first2x, first2y) FindPic first1x,first1y,first2x,first2y,"Attachment:\0.bmp",,intX,intY
If intX > And intY > Then
find =
Exit Function
End If
FindPic first1x,first1y,first2x,first2y,"Attachment:\1.bmp",,intX,intY
If intX > And intY > Then
find =
Exit Function
End If
FindPic first1x,first1y,first2x,first2y,"Attachment:\2.bmp",,intX,intY
If intX > And intY > Then
find =
Exit Function
End If
FindPic first1x,first1y,first2x,first2y,"Attachment:\3.bmp",,intX,intY
If intX > And intY > Then
find =
Exit Function
End If
FindPic first1x,first1y,first2x,first2y,"Attachment:\4.bmp",,intX,intY
If intX > And intY > Then
find =
Exit Function
End If
FindPic first1x,first1y,first2x,first2y,"Attachment:\5.bmp",,intX,intY
If intX > And intY > Then
find =
Exit Function
End If
FindPic first1x,first1y,first2x,first2y,"Attachment:\6.bmp",,intX,intY
If intX > And intY > Then
find =
Exit Function
End If
FindPic first1x,first1y,first2x,first2y,"Attachment:\7.bmp",,intX,intY
If intX > And intY > Then
find =
Exit Function
End If
FindPic first1x,first1y,first2x,first2y,"Attachment:\8.bmp",,intX,intY
If intX > And intY > Then
find =
Exit Function
End If
FindPic first1x,first1y,first2x,first2y,"Attachment:\9.bmp",,intX,intY
If intX > And intY > Then
find =
Exit Function
End If find = - End Function //子程序:前往目标地点
Sub headTo(x, y)
BeginThread click
While
Call get()
a = nowx - x
b = nowy - y // 判断是否已经到达
If (a * a + b * b) < Then
Exit Sub
End If // 屏幕向量
screenx = (b - a) * 1.1
screeny = (a + b) * 0.6 d = / (Sqr( + (screenx * screenx) / (screeny * screeny)))
c = (screenx / screeny) * d If c * screenx < Then
c = -c
End If If d * screeny > Then
d = -d
End If c = c + actualx
d = d + actualy // 鼠标指向
MoveTo c, d
Delay
Wend End Sub // 线程:不停点击鼠标
Sub click()
clickID = GetThreadID()
While
LeftClick
Delay
Wend
End Sub // 子程序:开始所有键盘点击
Sub startkey()
Select Case Form1.KeyBox1.ListIndex
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox1.Caption
BeginThread presskey(, ms)
Case Else
End Select Select Case Form1.KeyBox2.ListIndex
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox2.Caption
BeginThread presskey(, ms)
Case Else
End Select Select Case Form1.KeyBox3.ListIndex
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox3.Caption
BeginThread presskey(, ms)
Case Else
End Select Select Case Form1.KeyBox4.ListIndex
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case
ms = Form1.MsBox4.Caption
BeginThread presskey(, ms)
Case Else
End Select
End Sub //线程:每隔ms按num键
Sub presskey(num,mss)
While
KeyPress num,
Delay ms
Wend
End Sub // 查找和点击XP技能
Sub findclick()
While
IfColor xpx, xpy, "CF71A9", Then
SaveMousePos
MoveTo ,
LeftClick
RestoreMousePos
Else
End If
Delay
Wend
End Sub