Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 23, 2011, 2:37:08 PM (13 years ago)
Author:
ssgier
Message:

finished code for ShrinkPickup, adapted XML file\

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc

    r8502 r8534  
    5151    CreateFactory(ShrinkPickup);
    5252
     53                /**
     54    @brief
     55        Constructor: Initializes the Pickup.
     56    */
    5357    ShrinkPickup::ShrinkPickup(BaseObject* creator) : Pickup(creator)
    5458    {
     
    5660
    5761        this->initialize();
    58         shrinkFactor_ = 5.0;
    59         duration_ = 5.0;
    60         shrinkSpeed_ = 5.0;
    6162        isActive_ = false;
    6263        isTerminating_ = false;
     
    6869    }
    6970
     71    void ShrinkPickup::initializeIdentifier(void)
     72    {
     73        std::stringstream stream;
     74        stream << this->getShrinkFactor();
     75        std::string type1 = "shrinkFactor";
     76        std::string val1 = stream.str();
     77        this->pickupIdentifier_->addParameter(type1, val1);
     78
     79        stream.clear();
     80        stream << this->getDuration();
     81        std::string val2 = stream.str();
     82        std::string type2 = "duration";
     83        this->pickupIdentifier_->addParameter(type2, val2);
     84
     85        stream.clear();
     86        stream << this->getShrinkSpeed();
     87        std::string val3 = stream.str();
     88        std::string type3 = "shrinkSpeed";
     89        this->pickupIdentifier_->addParameter(type3, val3);
     90    }
     91
     92   /**
     93    @brief
     94        Method for creating a HealthPickup object through XML.
     95    */
     96    void ShrinkPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
     97    {
     98        SUPER(ShrinkPickup, XMLPort, xmlelement, mode);
     99
     100        XMLPortParam(ShrinkPickup, "shrinkFactor", setShrinkFactor, getShrinkFactor, xmlelement, mode);
     101        XMLPortParam(ShrinkPickup, "duration", setDuration, getDuration, xmlelement, mode);
     102        XMLPortParam(ShrinkPickup, "shrinkSpeed", setShrinkSpeed, getShrinkSpeed, xmlelement, mode);
     103
     104        this->initializeIdentifier();
     105    }
     106
     107    /**
     108    @brief
     109        Sets the shrinking factor.
     110    @param factor
     111        The factor.
     112    */
     113    void ShrinkPickup::setShrinkFactor(float factor)
     114    {
     115        this->shrinkFactor_ = factor;
     116    }
     117
     118    /**
     119    @brief
     120        Sets the duration.
     121    @param duration
     122        The duration.
     123    */
     124    void ShrinkPickup::setDuration(float duration)
     125    {
     126        this->duration_ = duration;
     127    }
     128
     129    /**
     130    @brief
     131        Sets the shrinking speed.
     132    @param speed
     133        The speed.
     134    */
     135    void ShrinkPickup::setShrinkSpeed(float speed)
     136    {
     137        this->shrinkSpeed_ = speed;
     138    }
     139
    70140    void ShrinkPickup::initialize(void)
    71141    {
     
    73143    }
    74144
     145                /**
     146    @brief
     147        Prepares for shrinking (collecting several informations).
     148    */
    75149    void ShrinkPickup::changedUsed(void)
    76150    {
     
    83157                this->Pickupable::destroy();
    84158
     159            //Collect scaling information.
    85160            defaultScale_ = this->pawn->getScale3D();
    86161            defaultMass_ = this->pawn->getMass();
     
    94169            cameraPositions_ = this->pawn->getCameraPositions();
    95170            size_ = cameraPositions_.size();
    96             isActive_ = true;
    97             durationTimer.setTimer(duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this)));
     171            isActive_ = true;    //start shrinking now.
     172            durationTimer.setTimer(duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this)));    //Set timer for termination.
    98173        }
    99174    }
    100175
     176        /**
     177    @brief
     178        Updates the scales of the ship.
     179    @param dt
     180        Time since last call.
     181    */
    101182    void ShrinkPickup::tick(float dt)
    102183    {
    103         if(isActive_ == true && actualScale_ > smallScale_)
     184        if(isActive_ == true && actualScale_ > smallScale_)    //if the ship has not reached the target scale, continue shrinking
    104185        {
    105186            float factor_ = 1 + dt*shrinkSpeed_;
     
    121202        else isActive_ = false;
    122203
    123         if(isTerminating_ == true && actualScale_ < defaultScale_)
     204        if(isTerminating_ == true && actualScale_ < defaultScale_)    //grow until the ship reaches its default scale.
    124205        {
    125206            float factor_ = 1 + dt*shrinkSpeed_;
     
    144225    }
    145226
     227        /**
     228    @brief
     229        Initializes the termination.
     230    */
    146231    void ShrinkPickup::terminate(void)
    147232    {
     
    171256
    172257        SUPER(ShrinkPickup, clone, item);
     258        ShrinkPickup* pickup = dynamic_cast<ShrinkPickup*>(item);
     259        pickup->setShrinkFactor(this->getShrinkFactor());
     260        pickup->setDuration(this->getDuration());
     261        pickup->setShrinkSpeed(this->getShrinkSpeed());
     262
     263        pickup->initializeIdentifier();
    173264    }
    174265}
Note: See TracChangeset for help on using the changeset viewer.