Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8534


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

finished code for ShrinkPickup, adapted XML file\

Location:
code/branches/pickup
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup/data/levels/pickups.oxw

    r8502 r8534  
    192192    <PickupSpawner position="-30,-30,-30" respawnTime="60" triggerDistance="20" maxSpawnedItems="5">
    193193      <pickup>
    194         <ShrinkPickup />
     194        <ShrinkPickup shrinkFactor = "5.0" duration = "5.0" shrinkSpeed = "5.0"/>
    195195      </pickup>
    196196    </PickupSpawner>
  • 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}
  • code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h

    r8502 r8534  
    5959            virtual ~ShrinkPickup(); //!< Destructor.
    6060            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    61                         virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    62                         void tick(float dt);
     61            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
     62            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode);
     63            inline float getShrinkFactor(void) const
     64                { return this->shrinkFactor_; }
     65            inline float getDuration(void) const
     66                { return this->duration_; }
     67            inline float getShrinkSpeed(void) const
     68                { return this->shrinkSpeed_; }
     69            void setShrinkFactor(float factor);
     70            void setDuration(float duration);
     71            void setShrinkSpeed(float speed);
     72            void tick(float dt);
     73
     74        protected:
     75            void initializeIdentifier(void);
    6376
    6477        private:
    6578            void initialize(void);
    66                        
    67                         float duration_;                        //!< determines how long the pickup will be active
    68                 float shrinkFactor_;            //shrink factor of the space ship
    69                         float shrinkSpeed_;
    70                         bool isActive_;
    71                         bool isTerminating_;
    72                         int size_;
    73                         std::list<SmartPtr<CameraPosition> > cameraPositions_;
    74                         float defaultCameraPos_;
    75                         Ogre::Vector3 defaultScale_;
    76                         Ogre::Vector3 actualScale_;
    77                         Ogre::Vector3 smallScale_;
    78                         float defaultMass_;
    79                         float actualMass_;
    80                         float smallMass_;                       
    81                         Pawn* carrierToPawnHelper(void);
    82                         Pawn* pawn;
    83                         Timer durationTimer;
    84                         void terminate(void);
    85 
     79            float duration_;                    //!< determines how long the pickup will be active
     80            float shrinkFactor_;        //shrink factor of the space ship
     81            float shrinkSpeed_;         //speed of shrinking
     82            bool isActive_;             //true if ship is shrinking or small
     83            bool isTerminating_;        //true if ship is growing
     84            int size_;                  //number of camera positions
     85            std::list<SmartPtr<CameraPosition> > cameraPositions_;
     86            float defaultCameraPos_;    //all default, actual and small values...
     87            Ogre::Vector3 defaultScale_;
     88            Ogre::Vector3 actualScale_;
     89            Ogre::Vector3 smallScale_;
     90            float defaultMass_;
     91            float actualMass_;
     92            float smallMass_;                   
     93            Pawn* carrierToPawnHelper(void);
     94            Pawn* pawn;
     95            Timer durationTimer;
     96            void terminate(void);
    8697    };
    8798}
Note: See TracChangeset for help on using the changeset viewer.