本文整理汇总了C++中MapEntity::get_bounding_box方法的典型用法代码示例。如果您正苦于以下问题:C++ MapEntity::get_bounding_box方法的具体用法?C++ MapEntity::get_bounding_box怎么用?C++ MapEntity::get_bounding_box使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MapEntity
的用法示例。
在下文中一共展示了MapEntity::get_bounding_box方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_collision_custom
/**
* @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;
}
示例2: overlaps
bool MapEntity::overlaps(MapEntity& entity) {
return overlaps(entity.get_bounding_box());
}
示例3: test_collision_inside
/**
* \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());
}