示例#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);
    }
  }
}
示例#2
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;
  }

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

  // Check each entity with this detector.
  const std::list<MapEntityPtr>& all_entities = entities->get_entities();
  for (const MapEntityPtr& entity: all_entities) {

    if (entity->is_enabled()
        && !entity->is_being_removed()) {
      detector.check_collision(*entity);
    }
  }
}
示例#3
0
文件: Map.cpp 项目: j4b0l/solarus
/**
 * \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;
  }

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

  // Check each entity with this detector.
  const std::list<MapEntity*>& all_entities = entities->get_entities();
  std::list<MapEntity*>::const_iterator it;
  const std::list<MapEntity*>::const_iterator end = all_entities.end();
  for (it = all_entities.begin(); it != end; ++it) {

    MapEntity& entity = *(*it);
    if (entity.is_enabled()
        && !entity.is_being_removed()) {
      detector.check_collision(entity);
    }
  }
}
示例#4
0
/**
 * \brief Checks the collisions between an entity and the detectors of the map.
 *
 * This function is called by an entity sensitive to the entity detectors
 * when this entity has just moved on the map, or when a detector
 * wants to check this entity.
 * We check whether or not the entity overlaps an entity detector.
 * If the map is suspended, this function does nothing.
 *
 * \param entity the entity that has just moved (this entity should have
 * a movement sensible to the collisions)
 */
void Map::check_collision_with_detectors(MapEntity& entity) {

  if (suspended) {
    return;
  }

  const std::list<Detector*>& detectors = entities->get_detectors();

  // Check each detector.
  std::list<Detector*>::const_iterator it;
  const std::list<Detector*>::const_iterator end = detectors.end();
  for (it = detectors.begin(); it != end; ++it) {

    Detector* detector = *it;
    if (detector->is_enabled()
        && !detector->is_being_removed()) {
      detector->check_collision(entity);
    }
  }
}