Example #1
0
/**
 * @brief Returns the value of a property of this movement.
 *
 * Accepted keys:
 * - path
 * - speed
 * - loop
 * - ignore_obstacles
 * - snap_to_grid
 *
 * @param key key of the property to get
 * @return the corresponding value as a string
 */
const std::string PathMovement::get_property(const std::string &key) {

  std::ostringstream oss;

  if (key == "path") {
    oss << initial_path;
  }
  else if (key == "speed") {
    oss << speed;
  }
  else if (key == "loop") {
    oss << loop;
  }
  else if (key == "ignore_obstacles") {
    oss << are_obstacles_ignored();
  }
  else if (key == "snap_to_grid") {
    oss << snap_to_grid;
  }
  else {
    Debug::die(StringConcat() << "Unknown property of PathMovement: '" << key << "'");
  }

  return oss.str();
}
Example #2
0
/**
 * \brief Updates the position.
 */
void RelativeMovement::update() {

  if (entity_followed == nullptr) {
    finished = true;
    return;
  }

  if (entity_followed->is_being_removed()) {
    finished = true;
    entity_followed = nullptr;
  }
  else {

    Point next = entity_followed->get_xy() + entity_offset;
    Point dnext = next - get_xy();

    if (!are_obstacles_ignored()) {

      if (!finished && (dnext.x != 0 || dnext.y != 0)) {

        if (!test_collision_with_obstacles(dnext)) {
          set_xy(next);
        }
        else {
          finished = true;
          notify_obstacle_reached();
        }
      }
    }
    else {
      set_xy(next);
    }
  }
}
Example #3
0
/**
 * @brief Returns the value of a property of this movement.
 *
 * Accepted keys:
 * - speed
 * - angle
 * - max_distance
 * - ignore_obstacles
 * - smooth
 * - displayed_direction
 *
 * @param key key of the property to get
 * @return the corresponding value as a string
 */
const std::string StraightMovement::get_property(const std::string &key) {

  std::ostringstream oss;

  if (key == "speed") {
    oss << get_speed();
  }
  else if (key == "angle") {
    oss << get_angle();
  }
  else if (key == "max_distance") {
    oss << get_max_distance();
  }
  else if (key == "ignore_obstacles") {
    oss << are_obstacles_ignored();
  }
  else if (key == "smooth") {
    oss << is_smooth();
  }
  else if (key == "displayed_direction") {
    oss << get_displayed_direction4();
  }
  else {
    Debug::die(StringConcat() << "Unknown property of StraightMovement: '" << key << "'");
  }

  return oss.str();
}
Example #4
0
/**
 * \brief Updates the position.
 */
void FollowMovement::update() {

  if (entity_followed == NULL) {
    finished = true;
    return;
  }

  if (entity_followed->is_being_removed()) {
    finished = true;
    RefCountable::unref(entity_followed);
    entity_followed = NULL;
  }
  else {

    int next_x = entity_followed->get_x() + x;
    int next_y = entity_followed->get_y() + y;

    int dx = next_x - get_x();
    int dy = next_y - get_y();

    if (!are_obstacles_ignored()) {

      if (!finished && (dx != 0 || dy != 0)) {

        if (!test_collision_with_obstacles(dx, dy)) {
          set_x(next_x);
          set_y(next_y);
        }
        else {
          finished = true;
          notify_obstacle_reached();
        }
      }
    }
    else {
      set_x(next_x);
      set_y(next_y);
    }
  }
}
Example #5
0
/**
 * @brief Returns the value of a property of this movement.
 *
 * Accepted keys:
 * - direction8
 * - length
 * - speed
 * - ignore_obstacles
 *
 * @param key key of the property to get
 * @return the corresponding value as a string
 */
const std::string JumpMovement::get_property(const std::string &key) {

  std::ostringstream oss;

  if (key == "direction8") {
    oss << direction8;
  }
  else if (key == "length") {
    oss << length;
  }
  else if (key == "speed") {
    oss << speed;
  }
  else if (key == "ignore_obstacles") {
    oss << are_obstacles_ignored();
  }
  else {
    Debug::die(StringConcat() << "Unknown property of JumpMovement: '" << key << "'");
  }

  return oss.str();
}