-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathaction_long.py
More file actions
294 lines (248 loc) · 11.4 KB
/
Copy pathaction_long.py
File metadata and controls
294 lines (248 loc) · 11.4 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
import math
import skill_long
# 动作 points是人体的关节点,可以看README里面图和解释
def operation(points):
# 鼻子
nose = points[0]
# 胸骨
core = points[1]
# 右边肩膀
shoulder_right = points[2]
# 左边肩膀
shoulder_left = points[5]
# 右边肘
elbow_right = points[3]
# 左边肘
elbow_left = points[6]
# 右手掌
palm_right = points[4]
# 左手掌
palm_left = points[7]
# 裆部
jj = points[8]
# 右髋骨
hip_right = points[9]
# 左髋骨
hip_left = points[12]
# 右膝盖
knee_right = points[10]
# 左膝盖
knee_left = points[13]
# 右脚踝
ankle_right = points[11]
# 左脚踝
ankle_left = points[14]
# 动作设计的时候注意这里的顺序(这个很重要)
# 翻滚 弯背
if roll_left(palm_right, palm_left, knee_right, knee_left):
return
# 曝气 双手交叉在胸前
if unparalleled(palm_left, elbow_left, palm_right, elbow_right, shoulder_left, shoulder_right, jj, core):
return
# 旋风腿 踢腿加直拳 (左右方向)同手同脚挥出踢出
if whirlwind_leg_left(palm_left, elbow_left, shoulder_left, hip_left, knee_left,elbow_right,hip_right,knee_right, ankle_left,ankle_right):
return
# 右边旋风腿 同手同脚挥出踢出
if whirlwind_leg_right(palm_right, elbow_right, shoulder_right, hip_right, knee_right, hip_left, knee_left, elbow_left, ankle_right,ankle_left):
return
# 冲击波 推波 龟派气功波的招式
if qi_gong_right(core, elbow_left, elbow_right):
return
# 龟派气功波的招式
if qi_gong_left(core, elbow_left, elbow_right):
return
# 技能旋风腿 高举双手(消耗气的旋风腿)
if real_sheng_long_boxing(nose, palm_left, palm_right):
return
# 升龙拳 高举左右手
if sheng_long_boxing_left(nose, palm_left):
return
if sheng_long_boxing_right(nose, palm_right):
return
# 右边移动 左手格挡
if move_right(palm_left, elbow_left, shoulder_left,core):
return
# 左边移动 右手格挡
if move_left(palm_right, elbow_right, shoulder_right,core):
return
# 腿 踢腿
if leg(knee_right, hip_left, hip_left, knee_left):
return
# 拳头 直拳
if boxing(palm_left, elbow_left, shoulder_left, palm_right, elbow_right, shoulder_right):
return
return
# 气功波 右边
def qi_gong_right(core, elbow_left, elbow_right):
if core[2] > 0.1 and elbow_left[2] > 0.1 and elbow_right[2] > 0.1:
if elbow_left[0] < core[0] and elbow_right[0] < core[0]:
# 调用按键使用技能
skill_long.shock_wave_right()
return True
return False
# 气功波 左边
def qi_gong_left(core, elbow_left, elbow_right):
if core[2] > 0.1 and elbow_left[2] > 0.1 and elbow_right[2] > 0.1:
if elbow_left[0] > core[0] and elbow_right[0] > core[0]:
skill_long.shock_wave_left()
return True
return False
# 升龙拳 左边 判断方式(左手手腕高于眼睛) 后面的动作设计也基本是这样靠着数学计算,用角度和位置来判断的。
def sheng_long_boxing_left(nose, palm_left):
if nose[2] > 0.1 and palm_left[2] > 0.1:
if palm_left[1] < nose[1]:
skill_long.sheng_long_boxing_left();
return True
return False
# 升龙拳 右边 判断方式(右手手腕高于眼睛) 后面的动作设计也基本是这样靠着数学计算,用角度和位置来判断的。
def sheng_long_boxing_right(nose, palm_right):
if nose[2] > 0.1 and palm_right[2] > 0.1:
if palm_right[1] < nose[1]:
skill_long.sheng_long_boxing_right()
return True
return False
# 大招旋风腿 (双手高于眼睛)
def real_sheng_long_boxing(nose,palm_left,palm_right):
if nose[2] > 0.1 and palm_right[2] > 0.1 and palm_left[2] > 0.1:
if palm_right[1] < nose[1] and palm_left[1] < nose[1]:
skill_long.i()
return True
return False
# 旋风腿 右边
def whirlwind_leg_right(palm_right, elbow_right, shoulder_right, hip_right, knee_right,hip_left,knee_left, elbow_left, ankle_right, ankle_left):
if palm_right[2] > 0.1 and elbow_right[2] > 0.1 and shoulder_right[2] > 0.1 and hip_right[2] > 0.1 and knee_right[2] > 0.1 and hip_left[2] > 0.1 and knee_left[2] > 0.1 and elbow_left[2] > 0.1 and ankle_right[2] > 0.1 and ankle_left[2] > 0.1 and palm_right[1] < elbow_left[1] :
temp_palm_elbow = [palm_right[0], palm_right[1], elbow_right[0], elbow_right[1]]
temp_elbow_shoulder = [elbow_right[0], elbow_right[1], shoulder_right[0], shoulder_right[1]]
result_angle = angle(temp_palm_elbow, temp_elbow_shoulder)
if result_angle > 40:
temp_hip_knee_right = [hip_right[0], hip_right[1], knee_right[0], knee_right[1]]
temp_hip_knee_left = [hip_left[0], hip_left[1], knee_left[0], knee_left[1]]
angle2 = angle(temp_hip_knee_right, temp_hip_knee_left)
if angle2 < 40:
skill_long.xuan_feng_leg_right()
return True
return False
# 旋风腿 左边
def whirlwind_leg_left(palm_left, elbow_left, shoulder_left, hip_left, knee_left, elbow_right,hip_right,knee_right, ankle_left ,ankle_right):
if palm_left[2] > 0.1 and elbow_left[2] > 0.1 and shoulder_left[2] > 0.1 and hip_left[2] > 0.1 and knee_left[2] > 0.1 and elbow_right[2] > 0.1 and hip_right[2] > 0.1 and ankle_left[2] > 0.1 and ankle_right[2] > 0.1 and knee_right[2] > 0.1 and palm_left[1] < elbow_right[1]:
temp_palm_elbow = [palm_left[0], palm_left[1], elbow_left[0], elbow_left[1]]
temp_elbow_shoulder = [elbow_left[0], elbow_left[1], shoulder_left[0], shoulder_left[1]]
result_angle = angle(temp_palm_elbow, temp_elbow_shoulder)
if result_angle > 40:
temp_hip_knee_left = [hip_left[0], hip_left[1], knee_left[0], knee_left[1]]
temp_hip_knee_right = [hip_right[0], hip_right[1], knee_right[0], knee_right[1]]
angle2 = angle(temp_hip_knee_left, temp_hip_knee_right)
if angle2 < 40:
skill_long.xuan_feng_leg_left()
return True
return False
# 往左走
def move_left(palm_right, elbow_right, shoulder_right,core):
if palm_right[2] > 0.1 and elbow_right[2] > 0.1 and shoulder_right[2] > 0.1:
temp_palm_elbow = [palm_right[0], palm_right[1], elbow_right[0], elbow_right[1]]
temp_shoulder_elbow = [elbow_right[0], elbow_right[1], shoulder_right[0], shoulder_right[1]]
result = angle(temp_palm_elbow, temp_shoulder_elbow)
if palm_right[1] < core[1]:
skill_long.left()
return True
return False
# 往右走
def move_right(palm_left, elbow_left, shoulder_left,core):
if palm_left[2] > 0.1 and elbow_left[2] > 0.1 and shoulder_left[2] > 0.1:
temp_palm_elbow = [palm_left[0], palm_left[1], elbow_left[0], elbow_left[1]]
temp_shoulder_elbow = [elbow_left[0], elbow_left[1], shoulder_left[0], shoulder_left[1]]
result = angle(temp_palm_elbow, temp_shoulder_elbow)
if palm_left[1] < core[1]:
skill_long.right()
return True
return False
# 拳
def boxing(palm_left, elbow_left, shoulder_left,palm_right, elbow_right, shoulder_right):
if palm_left[2] > 0.1 and elbow_left[2] > 0.1 and shoulder_left[2] > 0.1 and palm_left[1] < elbow_right[1] and elbow_left[1] < elbow_right[1]:
temp_palm_elbow = [palm_left[0], palm_left[1], elbow_left[0], elbow_left[1]]
temp_elbow_shoulder = [elbow_left[0], elbow_left[1], shoulder_left[0], shoulder_left[1]]
result_angle = angle(temp_palm_elbow, temp_elbow_shoulder)
if result_angle < 70:
skill_long.j()
return True
if palm_right[2] > 0.1 and elbow_right[2] > 0.1 and shoulder_right[2] > 0.1 and palm_right[1] < elbow_left[1] and elbow_right[1] < elbow_left[1]:
temp_palm_elbow = [palm_left[0], palm_left[1], elbow_right[0], elbow_right[1]]
temp_elbow_shoulder = [elbow_right[0], elbow_right[1], shoulder_right[0], shoulder_right[1]]
result_angle = angle(temp_palm_elbow, temp_elbow_shoulder)
if result_angle < 60:
skill_long.j()
return True
return
# 腿
def leg(hip_right, knee_right, hip_left, knee_left):
if hip_right[2] > 0.1 and knee_right[2] > 0.1:
temp_hip_knee_right = [hip_right[0], hip_right[1], knee_right[0], knee_right[1]]
temp_hip_knee_left = [hip_left[0], hip_left[1], knee_left[0], knee_left[1]]
angle2 = angle(temp_hip_knee_right, temp_hip_knee_left)
if angle2 < 30:
skill_long.k()
return True
# if hip_right[2] > 0.1 and knee_right[2] > 0.1:
# temp_hip_knee_right = [hip_right[0], hip_right[1], knee_right[0], knee_right[1]]
# temp_hip_knee_left = [hip_left[0], hip_left[1], knee_left[0], knee_left[1]]
# angle2 = angle(temp_hip_knee_right, temp_hip_knee_left)
# if angle2 > 30:
# move.k()
# return True
return
# 曝气
def unparalleled(palm_left, elbow_left, palm_right, elbow_right, shoulder_left, shoulder_right, jj, core):
if palm_left[2] > 0.1 and elbow_left[0] > 0.1 and palm_right[2] > 0.1 and elbow_right[2] > 0.1 and shoulder_left[2] > 0.1 and shoulder_right[2] > 0.1 and jj[2] > 0.1 and core[2] > 0.1:
temp_palm_elbow_left = [[palm_left[0], palm_left[1]], [elbow_left[0], elbow_left[1]]]
temp_palm_elbow_right = [[palm_right[0], palm_right[1]], [elbow_right[0], elbow_right[1]]]
(result1, result2) = line_intersection(temp_palm_elbow_left, temp_palm_elbow_right)
y_top = core[1]
y_bottom = jj[1]
x_left = shoulder_left[0]
x_right = shoulder_right[0]
if result1 < x_left and result1 > x_right and result2 > y_top and result2 < y_bottom and palm_left[0] < palm_right[0]:
skill_long.o()
return True
return False
# 翻滚
def roll_left(palm_right, palm_left, knee_right, knee_left):
if (palm_right[2] > 0.1 and knee_right[2] > 0.1) or (palm_left[2] > 0.1 and knee_left[2] > 0.1):
if palm_right[1] > knee_right[1] or palm_right[1] > knee_right[1]:
skill_long.roll_right()
return True
if palm_left[1] > knee_left[1] or palm_left[1] > knee_right[1]:
skill_long.roll_left()
return True
return False
# 计算两个直线的夹角 只要夹角
def angle(v1, v2):
dx1 = v1[2] - v1[0]
dy1 = v1[3] - v1[1]
dx2 = v2[2] - v2[0]
dy2 = v2[3] - v2[1]
angle1 = math.atan2(dy1, dx1)
angle1 = int(angle1 * 180 / math.pi)
# print(angle1)
angle2 = math.atan2(dy2, dx2)
angle2 = int(angle2 * 180 / math.pi)
# print(angle2)
if angle1 * angle2 >= 0:
included_angle = abs(angle1 - angle2)
else:
included_angle = abs(angle1) + abs(angle2)
if included_angle > 180:
included_angle = 360 - included_angle
return abs(90 - included_angle)
# 两个线的交点
def line_intersection(line1, line2):
xdiff = (line1[0][0] - line1[1][0], line2[0][0] - line2[1][0])
ydiff = (line1[0][1] - line1[1][1], line2[0][1] - line2[1][1])
def det(a, b):
return a[0] * b[1] - a[1] * b[0]
div = det(xdiff, ydiff)
if div == 0:
raise Exception('lines do not intersect')
d = (det(*line1), det(*line2))
x = det(d, xdiff) / div
y = det(d, ydiff) / div
return x, y