/** * \brief Updates the pickable item. * * This function is called repeatedly by the map. * This is a redefinition of Entity::update() to make * the item blink and then disappear after an amount of time. */ void Pickable::update() { // update the animations and the movement Detector::update(); // update the shadow if (shadow_sprite != nullptr) { shadow_sprite->update(); } shadow_xy.x = get_x(); if (!is_falling()) { shadow_xy.y = get_y(); } if (entity_followed != nullptr && entity_followed->is_being_removed()) { if (entity_followed->get_type() == EntityType::BOOMERANG || entity_followed->get_type() == EntityType::HOOKSHOT) { // The pickable may have been dropped by the boomerang/hookshot // not exactly on the hero so let's fix this. if (get_distance(get_hero()) < 16) { try_give_item_to_player(); } } entity_followed = nullptr; } check_bad_ground(); if (!is_suspended()) { // check the timer uint32_t now = System::now(); // wait 0.7 second before allowing the hero to take the item if (!can_be_picked && now >= allow_pick_date) { can_be_picked = true; falling_height = FALLING_NONE; get_hero().check_collision_with_detectors(); } else { // make the item blink and then disappear if (will_disappear) { if (now >= blink_date && !get_sprite().is_blinking() && entity_followed == nullptr) { set_blinking(true); } if (now >= disappear_date) { remove_from_map(); } } } } }
/** * \brief Initializes the movement of the item (if it is falling), * depending on its subtype. */ void Pickable::initialize_movement() { if (is_falling()) { set_movement(std::make_shared<FallingOnFloorMovement>(falling_height)); } }
/** * \brief Initializes the movement of the item (if it is falling), * depending on its subtype. */ void Pickable::initialize_movement() { if (is_falling()) { set_movement(new FallingOnFloorMovement(falling_height)); } }