/** * \brief Suspends or resumes the animation of the hero's sprites. * * This function is called by the map when the game is suspended or resumed. * * \param suspended true to suspend the hero's sprites, false to resume them */ void HeroSprites::set_suspended(bool suspended) { tunic_sprite->set_suspended(suspended); if (equipment.has_ability("sword") && sword_sprite != NULL) { sword_sprite->set_suspended(suspended); sword_stars_sprite->set_suspended(suspended); } if (equipment.has_ability("shield") && shield_sprite != NULL) { shield_sprite->set_suspended(suspended); } trail_sprite->set_suspended(suspended); if (is_ground_visible()) { ground_sprite->set_suspended(suspended); } // timer uint32_t now = System::now(); if (suspended) { when_suspended = now; } else if (end_blink_date != 0) { end_blink_date += now - when_suspended; } }
/** * \brief Suspends or resumes the animation of the hero's sprites. * * This function is called by the map when the game is suspended or resumed. * * \param suspended true to suspend the hero's sprites, false to resume them */ void HeroSprites::set_suspended(bool suspended) { tunic_sprite->set_suspended(suspended); if (equipment.has_ability(ABILITY_SWORD) && sword_sprite != nullptr) { sword_sprite->set_suspended(suspended); sword_stars_sprite->set_suspended(suspended); } if (equipment.has_ability(ABILITY_SHIELD) && shield_sprite != nullptr) { shield_sprite->set_suspended(suspended); } trail_sprite->set_suspended(suspended); if (is_ground_visible()) { ground_sprite->set_suspended(suspended); } // Timer. uint32_t now = System::now(); if (suspended) { when_suspended = now; } else if (end_blink_date != 0) { end_blink_date += now - when_suspended; } }
/** * \brief This function is called when the sprites take a "walking" animation. * * It makes instructions common to all states having a "walking" animation. * (e.g. free or carrying). */ void HeroSprites::set_animation_walking_common() { if (is_ground_visible() && hero.get_ground_below() != GROUND_SHALLOW_WATER) { ground_sprite->set_current_animation("walking"); } walking = true; }
/** * \brief This function is called when the sprites take a "stopped" animation. * * It makes instructions common to all states having a "stopped" animation. * (e.g. free or carrying). */ void HeroSprites::set_animation_stopped_common() { if (is_ground_visible() && hero.get_ground_below() != Ground::SHALLOW_WATER) { ground_sprite->set_current_animation("stopped"); } walking = false; }
/** * \brief Notifies the hero's sprites that a map has just become active. */ void HeroSprites::notify_map_started() { // some sprites may be tileset dependent if (lifted_item != NULL) { lifted_item->notify_map_started(); } if (is_ground_visible()) { ground_sprite->set_tileset(hero.get_map().get_tileset()); } }
/** * \brief Notifies the hero's sprites that the tileset has just changed. */ void HeroSprites::notify_tileset_changed() { // Some sprites may be tileset dependent. if (lifted_item != nullptr) { lifted_item->notify_tileset_changed(); } if (is_ground_visible()) { ground_sprite->set_tileset(hero.get_map().get_tileset()); } }
/** * \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"); } }
/** * \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(); } }
/** * \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(); } }
/** * \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(); } }
/** * \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); } }
/** * \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(); } }