Skip to content

Commit d3ff4bf

Browse files
author
Raven
committed
update(#8): make enemies prioritize the face.
1 parent 75172ab commit d3ff4bf

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

main.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,24 @@ def render(self, image):
146146
previous_spawn_time = current_time
147147
spawn_delay = random.normalvariate(4, 1)
148148

149+
face_bounding_box = None
149150

150151
if face_results.detections:
151152
detection = next(iter(face_results.detections))
152153

153154
mp_drawing.draw_detection(image, detection)
154155

156+
bbox = detection.location_data.relative_bounding_box
157+
fbbx = int(bbox.xmin * w)
158+
fbby = int(bbox.ymin * h)
159+
fbbw = int(bbox.width * w)
160+
fbbh = int(bbox.height * h)
161+
face_center = np.array((fbbx + fbbw / 2, fbby + fbbh / 2))
162+
face_bounding_box = (fbbx, fbby, fbbw, fbbh)
163+
164+
for rect in rect_list:
165+
rect.chase(face_center, delta_time)
166+
155167
if hand_results.multi_hand_landmarks:
156168
for hand_landmarks in hand_results.multi_hand_landmarks:
157169
mp_drawing.draw_landmarks(image, hand_landmarks, mp_hands.HAND_CONNECTIONS)
@@ -172,7 +184,8 @@ def render(self, image):
172184
if len(hits) > 0:
173185
hit_indices.append(i)
174186

175-
rect.chase(index_mcp, delta_time)
187+
if not face_results.detections:
188+
rect.chase(index_mcp, delta_time)
176189

177190
if is_hit:
178191
continue

0 commit comments

Comments
 (0)