Skip to content

Commit 56492b0

Browse files
authored
Revert crusher's edge detection for its horizontal axis (#3286)
* Fix crusher's edge detection
1 parent db256c3 commit 56492b0

File tree

1 file changed

+55
-17
lines changed

1 file changed

+55
-17
lines changed

src/badguy/crusher.cpp

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,31 +161,69 @@ Crusher::should_crush()
161161

162162
for (Player* player : Sector::get().get_players())
163163
{
164-
const Rectf& playerbbox = player->get_bbox();
164+
const Rectf& player_bbox = player->get_bbox();
165+
bool player_in_main_detect_zone = false;
165166

166167
if (m_dir == CrusherDirection::ALL)
167168
{
168-
if (!(playerbbox.overlaps(get_detect_box(CrusherDirection::HORIZONTAL)) ||
169-
playerbbox.overlaps(get_detect_box(CrusherDirection::VERTICAL))))
170-
171-
continue;
169+
if (player_bbox.overlaps(get_detect_box(CrusherDirection::HORIZONTAL)) ||
170+
player_bbox.overlaps(get_detect_box(CrusherDirection::VERTICAL)))
171+
{
172+
player_in_main_detect_zone = true;
173+
}
172174
}
173-
else if (!playerbbox.overlaps(get_detect_box()))
175+
else if (player_bbox.overlaps(get_detect_box()))
174176
{
175-
continue;
177+
player_in_main_detect_zone = true;
176178
}
177179

178-
RaycastResult result = Sector::get().get_first_line_intersection(get_bbox().get_middle(),
179-
playerbbox.get_middle(),
180-
false,
181-
get_collision_object());
180+
bool player_in_top_edge_zone = false;
181+
if (!player_in_main_detect_zone &&
182+
(m_dir == CrusherDirection::LEFT ||
183+
m_dir == CrusherDirection::RIGHT ||
184+
m_dir == CrusherDirection::HORIZONTAL))
185+
{
186+
const Rectf crusher_bbox = get_bbox();
187+
const float zone_width = crusher_bbox.get_width() / 6.0f;
188+
const float zone_height = 1.0f;
189+
const float zone_top_y = crusher_bbox.get_top() - zone_height;
182190

183-
auto obj_p = std::get_if<CollisionObject*>(&result.hit);
184-
if (!obj_p || *obj_p != player->get_collision_object())
185-
continue;
191+
Rectf left_top_zone;
192+
Rectf right_top_zone;
186193

187-
m_target = *obj_p;
188-
return true;
194+
if (m_dir == CrusherDirection::LEFT || m_dir == CrusherDirection::HORIZONTAL)
195+
{
196+
left_top_zone.set_p1(Vector(crusher_bbox.get_left(), zone_top_y));
197+
left_top_zone.set_size(zone_width, zone_height);
198+
if (player_bbox.overlaps(left_top_zone))
199+
player_in_top_edge_zone = true;
200+
}
201+
202+
if (!player_in_top_edge_zone &&
203+
(m_dir == CrusherDirection::RIGHT || m_dir == CrusherDirection::HORIZONTAL))
204+
{
205+
right_top_zone.set_p1(Vector(crusher_bbox.get_right() - zone_width, zone_top_y));
206+
right_top_zone.set_size(zone_width, zone_height);
207+
if (player_bbox.overlaps(right_top_zone))
208+
player_in_top_edge_zone = true;
209+
}
210+
}
211+
212+
if (player_in_main_detect_zone || player_in_top_edge_zone)
213+
{
214+
const RaycastResult result = Sector::get().get_first_line_intersection(get_bbox().get_middle(),
215+
player_bbox.get_middle(),
216+
false,
217+
get_collision_object());
218+
219+
const auto obj_p = std::get_if<CollisionObject*>(&result.hit);
220+
221+
if (!obj_p || *obj_p != player->get_collision_object())
222+
continue;
223+
224+
m_target = player->get_collision_object();
225+
return true;
226+
}
189227
}
190228

191229
return false;
@@ -358,7 +396,7 @@ Crusher::get_detect_box(CrusherDirection dir)
358396
detectbox.set_p1(pos);
359397
detectbox.set_size(size.width, size.height);
360398

361-
return detectbox.grown(-1.f);
399+
return detectbox;
362400
}
363401

364402
Vector

0 commit comments

Comments
 (0)