-
Notifications
You must be signed in to change notification settings - Fork 45
/
app.go
50 lines (44 loc) · 951 Bytes
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package wechat_autojump_game
import (
"bytes"
"io/ioutil"
"log"
"os"
"time"
"image/png"
)
var (
filename = "wechat_jump.png"
SleepMills time.Duration = 1000
)
func Run() {
// filename = "tmp_jump3.png"
// currentX, currentY, nextX, nextY := getLocation(filename)
// println(currentX, currentY, nextX, nextY)
// return
for true {
time.Sleep(SleepMills * time.Millisecond)
saveScreenShot(filename)
currentX, currentY, nextX, nextY := getLocation(filename)
if currentX == 0 || currentY == 0 {
continue
}
distance := getDistance(currentX, currentY, nextX, nextY)
jump(distance)
}
}
func getLocation(name string) (x, y, nextX, nextY int) {
f1, err := os.Open(name)
if err != nil {
panic(err)
}
defer f1.Close()
data, _ := ioutil.ReadAll(f1)
img, _ := png.Decode(bytes.NewReader(data))
if err != nil {
log.Fatal(err)
}
location := NewLocation(img)
x, y, nextX, nextY = location.judgeByRGBRange()
return
}