当前位置: 首页>>代码示例>>C++>>正文


C++ MapEntity::get_bounding_box方法代码示例

本文整理汇总了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;
}
开发者ID:Aerospyke,项目名称:solarus,代码行数:48,代码来源:Teletransporter.cpp

示例2: overlaps

bool MapEntity::overlaps(MapEntity& entity) {
	return overlaps(entity.get_bounding_box());
}
开发者ID:dujos,项目名称:sdlcpp,代码行数:3,代码来源:MapEntity.cpp

示例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());
}
开发者ID:j4b0l,项目名称:solarus,代码行数:13,代码来源:Detector.cpp


注:本文中的MapEntity::get_bounding_box方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。