Ejemplo n.º 1
0
/**
 * \brief Notifies this custom entity that another entity has detected a
 * collision with it.
 * \param other_entity The other entity.
 */
void CustomEntity::notify_collision_from(MapEntity& other_entity) {

    // See if we also detect the other entity, and if yes, do the callbacks.
    if (test_collision_custom(other_entity)) {
        notify_collision(other_entity, COLLISION_CUSTOM);
    }
}
Ejemplo n.º 2
0
/**
 * @brief Notifies this entity that it was just enabled or disabled.
 * @param enabled true if the entity is now enabled
 */
void DynamicTile::notify_enabled(bool enabled) {

  if (is_on_map()
      && !enabled
      && test_collision_custom(get_hero())) {
    // the tile under the hero is disabled: the hero's ground may have changed
    get_hero().check_position();
  }
}
Ejemplo n.º 3
0
/**
 * \brief Checks whether an entity collides with this detector.
 *
 * This function is called by the map when an entity has just moved.
 * It checks whether the entity collides with this detector.
 * Depending on the detector collision mode(s), the appropriate
 * test_collision_* functions are called.
 * If there is a collision, the notify_collision() method is called.
 *
 * \param entity the entity to check
 */
void Detector::check_collision(Entity& entity) {

  if (&entity != this
      && (has_layer_independent_collisions() || get_layer() == entity.get_layer())) { // the entity is in the same layer as the detector

    // detect the collision depending on the collision mode

    if (has_collision_mode(COLLISION_OVERLAPPING) && test_collision_rectangle(entity)) {
      notify_collision(entity, COLLISION_OVERLAPPING);
    }

    if (has_collision_mode(COLLISION_CONTAINING) && test_collision_inside(entity)) {
      notify_collision(entity, COLLISION_CONTAINING);
    }

    if (has_collision_mode(COLLISION_ORIGIN) && test_collision_origin_point(entity)) {
      notify_collision(entity, COLLISION_ORIGIN);
    }

    if (has_collision_mode(COLLISION_FACING) && test_collision_facing_point(entity)) {

      if (entity.get_facing_entity() == nullptr) { // make sure only one entity can think "I am the facing entity"
        entity.set_facing_entity(this);
      }
      notify_collision(entity, COLLISION_FACING);
    }

    if (has_collision_mode(COLLISION_TOUCHING) && test_collision_touching(entity)) {
      notify_collision(entity, COLLISION_TOUCHING);
    }

    if (has_collision_mode(COLLISION_CENTER) && test_collision_center(entity)) {
      notify_collision(entity, COLLISION_CENTER);
    }

    if (has_collision_mode(COLLISION_CUSTOM) && test_collision_custom(entity)) {
      notify_collision(entity, COLLISION_CUSTOM);
    }
  }
}