Пример #1
0
/**
 * \brief Tests whether the hero is cutting with his sword the specified detector
 * for which a collision was detected.
 * \param detector the detector to check
 * \return true if the sword is cutting this detector
 */
bool Hero::SwordSwingingState::is_cutting_with_sword(
    Detector& detector) {

  Hero& hero = get_hero();
  if (hero.get_movement() != nullptr) {
    return false;
  }

  // check the distance to the detector
  int distance = detector.is_obstacle_for(hero) ? 14 : 4;
  Point tested_point = hero.get_facing_point();

  switch (get_sprites().get_animation_direction()) {

    case 0: // right
      tested_point.x += distance;
      break;

    case 1: // up
      tested_point.y -= distance;
      break;

    case 2: // left
      tested_point.x -= distance;
      break;

    case 3: // down
      tested_point.y += distance;
      break;
  }

  return detector.overlaps(tested_point);
}
Пример #2
0
/**
 * @brief Tests whether the hero is cutting with his sword the specified detector
 * for which a collision was detected.
 * @param detector the detector to check
 * @return true if the sword is cutting this detector
 */
bool Hero::SwordSwingingState::is_cutting_with_sword(Detector &detector) {

  if (hero.get_movement() != NULL) {
    return false;
  }

  // check the distance to the detector
  int distance = detector.is_obstacle_for(hero) ? 14 : 4;
  Rectangle tested_point = hero.get_facing_point();

  switch (get_sprites().get_animation_direction()) {

    case 0: // right
      tested_point.add_x(distance);
      break;

    case 1: // up
      tested_point.add_y(-distance);
      break;

    case 2: // left
      tested_point.add_x(-distance);
      break;

    case 3: // down
      tested_point.add_y(distance);
      break;
  }

  return detector.overlaps(tested_point.get_x(), tested_point.get_y());
}
Пример #3
0
/**
 * \brief Tests whether the hero is cutting with his sword the specified detector
 * for which a collision was detected.
 * \param detector the detector to check
 * \return true if the sword is cutting this detector
 */
bool Hero::SwordTappingState::is_cutting_with_sword(Detector& detector) const {

  const Hero& hero = get_hero();
  return detector.is_obstacle_for(hero)         // only obstacle entities can be cut
    && hero.get_facing_entity() == &detector    // only one entity at a time
    && get_sprites().get_current_frame() >= 3;  // wait until the animation shows an appropriate frame
}