/** * @brief Returns whether an entity's collides with this entity. * @param entity an entity * @return true if the entity's collides with this entity */ bool Teletransporter::test_collision_custom(MapEntity& entity) { bool collision = false; bool normal_case = true; // specific collision tests for some situations if (entity.is_hero()) { Hero& hero = (Hero&) entity; if (is_on_map_side()) { // scrolling towards an adjacent map Rectangle facing_point = hero.get_facing_point(transition_direction); collision = hero.is_moving_towards(transition_direction) && overlaps(facing_point.get_x(), facing_point.get_y()); normal_case = false; } else if (!get_map().test_collision_with_border(get_center_point()) && hero.get_ground() == GROUND_HOLE) { // falling into a hole collision = overlaps(hero.get_ground_point()); normal_case = false; } } // normal case if (normal_case) { const Rectangle& entity_rectangle = entity.get_bounding_box(); int x1 = entity_rectangle.get_x() + 4; int x2 = x1 + entity_rectangle.get_width() - 9; int y1 = entity_rectangle.get_y() + 4; int y2 = y1 + entity_rectangle.get_height() - 9; collision = overlaps(x1, y1) && overlaps(x2, y1) && overlaps(x1, y2) && overlaps(x2, y2); } if (!collision && !is_on_map_side()) { transporting_hero = false; } return collision; }
bool MapEntity::overlaps(MapEntity& entity) { return overlaps(entity.get_bounding_box()); }
/** * \brief Returns whether an entity's rectangle is entirely inside the detector's rectangle. * * This method is called by check_collision(MapEntity*) when the detector's collision * mode is COLLISION_INSIDE. * * \param entity the entity * \return true if the entity's rectangle is entirely inside the detector's rectangle */ bool Detector::test_collision_inside(MapEntity& entity) { return get_bounding_box().contains(entity.get_bounding_box()); }