예제 #1
0
/**
 * \brief Changes the direction of the hero's sprites.
 *
 * It is different from the movement direction.
 *
 * \param direction the direction to set (0 to 3)
 */
void HeroSprites::set_animation_direction(int direction) {

  Debug::check_assertion(direction >= 0 && direction < 4,
    "Invalid direction for set_animation_direction");

  tunic_sprite->set_current_direction(direction);

  if (is_sword_visible()) {
    sword_sprite->set_current_direction(direction);
  }

  if (is_sword_stars_visible()) {
    sword_stars_sprite->set_current_direction(direction);
  }

  if (is_shield_visible()) {
    shield_sprite->set_current_direction(direction);
  }

  if (is_trail_visible()) {
    trail_sprite->set_current_direction(direction);
  }

  if (lifted_item != nullptr) {
    const SpritePtr& sprite = lifted_item->get_sprite();
    sprite->restart_animation();
  }
}
예제 #2
0
/**
 * \brief Updates the animation of the hero's sprites if necessary.
 */
void HeroSprites::update() {

  // Keep the current sprites here in case they change from a script during the operation.
  SpritePtr tunic_sprite = this->tunic_sprite;
  SpritePtr sword_sprite = this->sword_sprite;

  // update the frames
  tunic_sprite->update();

  if (is_sword_visible()) {
    sword_sprite->update();
    sword_sprite->set_current_frame(tunic_sprite->get_current_frame());
    hero.check_collision_with_detectors(*sword_sprite);
  }
  hero.check_collision_with_detectors(*tunic_sprite);

  if (is_sword_stars_visible()) {
    // the stars are not synchronized with the other sprites
    sword_stars_sprite->update();
  }

  if (is_shield_visible()) {
    shield_sprite->update();
    if (walking) {
      shield_sprite->set_current_frame(tunic_sprite->get_current_frame());
    }
  }

  if (is_trail_visible()) {
    trail_sprite->update();
  }

  if (is_ground_visible()) {
    ground_sprite->update();
  }

  if (lifted_item != nullptr && walking) {
    lifted_item->get_sprite().set_current_frame(tunic_sprite->get_current_frame() % 3);
  }

  // blinking
  if (is_blinking()
      && end_blink_date != 0
      && System::now() >= end_blink_date) {
    stop_blinking();
  }

  // Lua callback.
  if (tunic_sprite->is_animation_finished() &&
      !animation_callback_ref.is_empty()) {
    animation_callback_ref.clear_and_call("hero animation callback");
  }
}
예제 #3
0
/**
 * \brief Draws the hero's sprites on the map.
 */
void HeroSprites::draw_on_map() {

  int x = hero.get_x();
  int y = hero.get_y();

  Map& map = hero.get_map();

  if (clipping_rectangle.get_width() > 0) {
    // restrict the map drawing to the clipping rectangle specified (just for the hero's sprites)
    map.set_clipping_rectangle(clipping_rectangle);
  }

  if (hero.is_shadow_visible()) {
    map.draw_sprite(*shadow_sprite, x, y);
  }

  const Rectangle& displayed_xy = hero.get_displayed_xy();
  x = displayed_xy.get_x();
  y = displayed_xy.get_y();

  map.draw_sprite(*tunic_sprite, x, y);

  if (is_trail_visible()) {
    map.draw_sprite(*trail_sprite, x, y);
  }

  if (is_ground_visible()) {
    map.draw_sprite(*ground_sprite, x, y);
  }

  if (is_sword_visible()) {
    map.draw_sprite(*sword_sprite, x, y);
  }

  if (is_sword_stars_visible()) {
    map.draw_sprite(*sword_stars_sprite, x, y);
  }

  if (is_shield_visible()) {
    map.draw_sprite(*shield_sprite, x, y);
  }

  if (lifted_item != NULL) {
    lifted_item->draw_on_map();
  }

  if (clipping_rectangle.get_width() > 0) {
    // restore the normal map drawing
    map.set_clipping_rectangle();
  }
}
예제 #4
0
/**
 * \brief Updates the animation of the hero's sprites if necessary.
 */
void HeroSprites::update() {

  // update the frames
  tunic_sprite->update();

  if (is_sword_visible()) {
    sword_sprite->update();
    sword_sprite->set_current_frame(tunic_sprite->get_current_frame());
    hero.check_collision_with_detectors(*sword_sprite);
  }
  hero.check_collision_with_detectors(*tunic_sprite);

  if (is_sword_stars_visible()) {
    // the stars are not synchronized with the other sprites
    sword_stars_sprite->update();
  }

  if (is_shield_visible()) {
    shield_sprite->update();
    if (walking) {
      shield_sprite->set_current_frame(tunic_sprite->get_current_frame());
    }
  }

  if (is_trail_visible()) {
    trail_sprite->update();
  }

  if (is_ground_visible()) {
    ground_sprite->update();
  }

  if (lifted_item != NULL && walking) {
    lifted_item->get_sprite().set_current_frame(tunic_sprite->get_current_frame() % 3);
  }

  // blinking
  if (tunic_sprite->is_blinking() && System::now() >= end_blink_date) {
    stop_blinking();
  }
}
예제 #5
0
/**
 * \brief Draws the hero's sprites on the map.
 */
void HeroSprites::draw_on_map() {

  int x = hero.get_x();
  int y = hero.get_y();

  Map& map = hero.get_map();

  if (hero.is_shadow_visible()) {
    map.draw_sprite(*shadow_sprite, x, y, clipping_rectangle);
  }

  const Point& displayed_xy = hero.get_displayed_xy();
  x = displayed_xy.x;
  y = displayed_xy.y;

  map.draw_sprite(*tunic_sprite, x, y, clipping_rectangle);

  if (is_trail_visible()) {
    map.draw_sprite(*trail_sprite, x, y, clipping_rectangle);
  }

  if (is_ground_visible()) {
    map.draw_sprite(*ground_sprite, x, y, clipping_rectangle);
  }

  if (is_sword_visible()) {
    map.draw_sprite(*sword_sprite, x, y, clipping_rectangle);
  }

  if (is_sword_stars_visible()) {
    map.draw_sprite(*sword_stars_sprite, x, y, clipping_rectangle);
  }

  if (is_shield_visible()) {
    map.draw_sprite(*shield_sprite, x, y, clipping_rectangle);
  }

  if (lifted_item != nullptr) {
    lifted_item->draw_on_map();
  }
}
예제 #6
0
/**
 * \brief Changes the direction of the hero's sprites.
 *
 * It is different from the movement direction.
 *
 * \param direction the direction to set (0 to 3)
 */
void HeroSprites::set_animation_direction(int direction) {

  Debug::check_assertion(direction >= 0 && direction < 4,
    StringConcat() << "Invalid direction for set_animation_direction: " << direction);

  tunic_sprite->set_current_direction(direction);

  if (is_sword_visible()) {
    sword_sprite->set_current_direction(direction);
  }

  if (is_sword_stars_visible()) {
    sword_stars_sprite->set_current_direction(direction);
  }

  if (is_shield_visible()) {
    shield_sprite->set_current_direction(direction);
  }

  if (is_trail_visible()) {
    trail_sprite->set_current_direction(direction);
  }
}
예제 #7
0
/**
 * \brief Sets whether the hero's sprite should keep playing their animation
 * when the game is suspended.
 * \param ignore_suspend true to make the sprites continue their animation even
 * when the game is suspended
 */
void HeroSprites::set_ignore_suspend(bool ignore_suspend) {

  tunic_sprite->set_ignore_suspend(ignore_suspend);

  if (is_sword_visible()) {
    sword_sprite->set_ignore_suspend(ignore_suspend);
  }

  if (is_sword_stars_visible()) {
    sword_stars_sprite->set_ignore_suspend(ignore_suspend);
  }

  if (is_shield_visible()) {
    shield_sprite->set_ignore_suspend(ignore_suspend);
  }

  if (is_trail_visible()) {
    trail_sprite->set_ignore_suspend(ignore_suspend);
  }

  if (is_ground_visible()) {
    ground_sprite->set_ignore_suspend(ignore_suspend);
  }
}
예제 #8
0
/**
 * \brief Restarts the animation of the hero's sprites.
 *
 * This function is called when the sprites have to
 * get back to their first frame.
 */
void HeroSprites::restart_animation() {

  tunic_sprite->restart_animation();

  if (is_sword_visible()) {
    sword_sprite->restart_animation();
  }

  if (is_sword_stars_visible()) {
    sword_stars_sprite->restart_animation();
  }

  if (is_shield_visible()) {
    shield_sprite->restart_animation();
  }

  if (is_trail_visible()) {
    trail_sprite->restart_animation();
  }

  if (is_ground_visible()) {
    ground_sprite->restart_animation();
  }
}
예제 #9
0
/**
 * \brief Stops displaying the sword stars (if any).
 */
void HeroSprites::stop_displaying_sword_stars() {

  if (is_sword_stars_visible()) {
    sword_stars_sprite->stop_animation();
  }
}