Пример #1
0
/**
 * \brief Checks the collisions between all entities and a detector.
 *
 * This function is called when a detector wants to check entities,
 * typically when the detector has just moved.
 * If the map is suspended, this function does nothing.
 *
 * \param detector A detector.
 */
void Map::check_collision_from_detector(Detector& detector) {

  if (suspended) {
    return;
  }

  if (detector.is_being_removed()) {
    return;
  }

  // First check the hero.
  detector.check_collision(get_entities().get_hero());

  // Check each entity with this detector.
  Rectangle box = detector.get_extended_bounding_box(8);
  std::vector<EntityPtr> entities_nearby;
  entities->get_entities_in_rectangle(box, entities_nearby);
  for (const EntityPtr& entity_nearby: entities_nearby) {

    if (entity_nearby->is_enabled()
        && !entity_nearby->is_suspended()
        && !entity_nearby->is_being_removed()
        && entity_nearby.get() != &detector
    ) {
      detector.check_collision(*entity_nearby);
    }
  }
}