Ejemplo n.º 1
0
/**
 * @brief Sets the speed of the angle variation.
 * @param angle_speed number of degrees to make per second
 */
void CircleMovement::set_angle_speed(int angle_speed) {

  Debug::check_assertion(angle_speed > 0, StringConcat() << "Invalid angle speed: " << angle_speed);

  this->angle_change_delay = 1000 / angle_speed;
  this->next_angle_change_date = System::now();
  recompute_position();
}
Ejemplo n.º 2
0
/**
 * \brief Sets the center of the circles.
 *
 * The movement will make circles around the specified (possibly moving) entity.
 *
 * \param center_entity the entity around which you want to make circles
 * \param x x coordinate of where the center should be placed relative to the entity's origin
 * \param y y coordinate of where the center should be placed relative to the entity's origin
 */
void CircleMovement::set_center(
    const EntityPtr& center_entity,
    int x,
    int y
) {
  this->center_entity = center_entity;
  this->center_point = { x, y };
  recompute_position();
}
Ejemplo n.º 3
0
/**
 * @brief Stops the movement.
 */
void CircleMovement::stop() {

  previous_radius = current_radius;
  set_radius(0);

  if (loop_delay != 0) {
    restart_date = System::now() + loop_delay;
  }
  recompute_position();
}
Ejemplo n.º 4
0
/**
 * \brief Sets the speed of the angle variation.
 * \param angle_speed number of degrees to make per second
 */
void CircleMovement::set_angle_speed(int angle_speed) {

  if (angle_speed <= 0) {
    std::ostringstream oss;
    oss << "Invalid angle speed: " << angle_speed;
    Debug::die(oss.str());
  }

  this->angle_change_delay = 1000 / angle_speed;
  this->next_angle_change_date = System::now();
  recompute_position();
}
Ejemplo n.º 5
0
/**
 * @brief Sets the center of the circles.
 *
 * The movement will make circles around the specified fixed point.
 *
 * @param center_point center of the circles to make
 */
void CircleMovement::set_center(const Rectangle& center_point) {

  if (this->center_entity != NULL) {
    this->center_entity->decrement_refcount();
    if (this->center_entity->get_refcount() == 0) {
      delete this->center_entity;
    }
  }

  this->center_entity = NULL;
  this->center_point = center_point;
  recompute_position();
}
Ejemplo n.º 6
0
/**
 * @brief Sets the center of the circles.
 *
 * The movement will make circles around the specified (possibly moving) entity.
 *
 * @param center_entity the entity around which you want to make circles
 * @param x x coordinate of where the center should be placed relative to the entity's origin
 * @param y y coordinate of where the center should be placed relative to the entity's origin
 */
void CircleMovement::set_center(MapEntity& center_entity, int x, int y) {

  if (this->center_entity != NULL) {
    this->center_entity->decrement_refcount();
    if (this->center_entity->get_refcount() == 0) {
      delete this->center_entity;
    }
  }

  this->center_entity = &center_entity;
  this->center_entity->increment_refcount();
  this->center_point.set_xy(x, y);
  recompute_position();
}
Ejemplo n.º 7
0
/**
 * @brief Starts the circle movement.
 */
void CircleMovement::start() {

  current_angle = initial_angle;
  next_angle_change_date = System::now();
  nb_rotations = 0;

  if (duration != 0) {
    end_movement_date = System::now() + duration;
  }

  if (radius_change_delay == 0) {
    current_radius = wanted_radius;
  }
  else {
    next_radius_change_date = System::now();
  }
  recompute_position();
}
Ejemplo n.º 8
0
/**
 * @brief Sets the radius of the circles.
 * @param radius the radius in pixels
 */
void CircleMovement::set_radius(int radius) {

  Debug::check_assertion(radius >= 0, StringConcat() << "Invalid radius: " << radius);

  this->wanted_radius = radius;
  if (radius_change_delay == 0) {
    if (is_started()) {
      this->current_radius = wanted_radius;
    }
  }
  else {
    this->radius_increment = (radius > this->current_radius) ? 1 : -1;
    if (is_started()) {
      this->next_radius_change_date = System::now();
    }
  }
  recompute_position();
}
Ejemplo n.º 9
0
/**
 * \brief Sets the radius of the circles.
 * \param radius the radius in pixels
 */
void CircleMovement::set_radius(int radius) {

  if (radius < 0) {
    std::ostringstream oss;
    oss << "Invalid radius: " << radius;
    Debug::die(oss.str());
  }

  this->wanted_radius = radius;
  if (radius_change_delay == 0) {
    if (is_started()) {
      this->current_radius = wanted_radius;
    }
  }
  else {
    this->radius_increment = (radius > this->current_radius) ? 1 : -1;
    if (is_started()) {
      this->next_radius_change_date = System::now();
    }
  }
  recompute_position();
}
Ejemplo n.º 10
0
/**
 * @brief Updates the movement.
 */
void CircleMovement::update() {

  Movement::update();

  if (center_entity != NULL && center_entity->is_being_removed()) {
    set_center(Rectangle(
          center_entity->get_x() + center_point.get_x(),
          center_entity->get_y() + center_point.get_y()));
  }

  if (is_suspended()) {
    return;
  }

  bool update_needed = false;
  uint32_t now = System::now();

  // maybe it is time to stop or to restart
  if (current_radius != 0 && duration != 0 && now >= end_movement_date && wanted_radius != 0) {
    stop();
  }
  else if (current_radius == 0 && loop_delay != 0 && now >= restart_date && wanted_radius == 0) {
    set_radius(previous_radius);
    start();
  }

  // update the angle
  if (is_started()) {
    while (now >= next_angle_change_date) {

      current_angle += angle_increment;
      current_angle = (360 + current_angle) % 360;
      if (current_angle == initial_angle) {
        nb_rotations++;

        if (nb_rotations == max_rotations) {
          stop();
        }
      }

      next_angle_change_date += angle_change_delay;
      update_needed = true;
    }
  }

  // update the radius
  while (current_radius != wanted_radius && now >= next_radius_change_date) {

    current_radius += radius_increment;

    next_radius_change_date += radius_change_delay;
    update_needed = true;
  }

  // the center may have moved
  if (center_entity != NULL) {
    update_needed = true;
  }

  if (update_needed) {
    recompute_position();
  }
}
Ejemplo n.º 11
0
/**
 * \brief Sets the center of the circles.
 *
 * The movement will make circles around the specified fixed point.
 *
 * \param center_point center of the circles to make
 */
void CircleMovement::set_center(const Point& center_point) {

  this->center_entity = nullptr;
  this->center_point = center_point;
  recompute_position();
}