Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 22, 2010, 10:45:09 PM (14 years ago)
Author:
ebeier
Message:

first working version of the SpeedPickup, needs some more work for "onUse" type. Spaceship trails need to be looked at, because they don't show when a SpeedPickup with SpeedAdd is used.

Location:
code/branches/ppspickups1/src/modules/pickup/items
Files:
2 edited

Legend:

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

    r6575 r6607  
    3838#include "util/StringUtils.h"
    3939
    40 #include "worldentities/pawns/Pawn.h"
     40#include "worldentities/pawns/SpaceShip.h"
     41#include "items/Engine.h"
    4142#include "pickup/PickupIdentifier.h"
    4243
     
    123124    /**
    124125    @brief
    125         Is called every tick.
    126         Does count down the duration of the SpeedPickup.
    127     @param dt
    128         The duration of the last tick.
    129     */
    130     void SpeedPickup::tick(float dt)
    131     {
    132         if(this->isUsed())
    133         {
    134             Pawn* pawn = this->carrierToPawnHelper();
    135             if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    136                 this->destroy();
    137 
    138              //! Calculate the remaining duration of the Pickup
    139             float duration=this->getDuration()-dt;
    140             this->setDuration(duration);
    141 
    142             //! If duration is over
    143             if(this->getDuration() < 0)
    144             {
    145                 this->setUsed(false);
    146             }
    147         }
    148     }
    149 
    150     /**
    151     @brief
    152126        Is called when the pickup has transited from used to unused or the other way around.
    153127    */
     
    163137        if(this->isUsed())
    164138        {
    165             if(this->isOnce())
    166             {
    167                 Pawn* pawn = this->carrierToPawnHelper();
    168                 if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    169                     this->destroy();
    170 
    171                 //! The pickup has been used up.
    172                 this->setUsed(false);
    173             }
    174         }
    175         else
    176         {
    177             //! If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused.
    178             if(this->isOnce() || (this->isContinuous() && this->getDuration() < 0))
    179             {
     139            this->startPickupTimer(this->getDuration());
     140
     141            Engine* engine = this->carrierToEngineHelper();
     142            if(engine == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    180143                this->destroy();
    181             }
    182         }
    183     }
     144            engine->setSpeedAdd(this->getSpeedAdd());
     145            engine->setSpeedMultiply(this->getSpeedMultiply());
     146        }
     147    }
     148
     149
    184150
    185151    /**
     
    189155        A pointer to the Pawn, or NULL if the conversion failed.
    190156    */
    191     Pawn* SpeedPickup::carrierToPawnHelper(void)
     157    Engine* SpeedPickup::carrierToEngineHelper(void)
    192158    {
    193159        PickupCarrier* carrier = this->getCarrier();
    194         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
    195 
    196         if(pawn == NULL)
     160        SpaceShip* ship = dynamic_cast<SpaceShip*>(carrier);
     161
     162        if(ship == NULL)
    197163        {
    198164            COUT(1) << "Invalid PickupCarrier in SpeedPickup." << std::endl;
    199165        }
    200 
    201         return pawn;
     166        else
     167        {
     168            return ship->getEngine();
     169        }
     170
     171        return 0;
    202172    }
    203173
     
    238208        {
    239209            COUT(1) << "Invalid duration in SpeedPickup." << std::endl;
    240             this->duration_ = 0.0;
     210            this->duration_ = 0;
    241211        }
    242212    }
     
    250220    void SpeedPickup::setSpeedAdd(float speedAdd)
    251221    {
    252         if(speedAdd > 0.0f)
     222        if(speedAdd >= 0.0f)
    253223        {
    254224            this->speedAdd_ = speedAdd;
     
    269239    void SpeedPickup::setSpeedMultiply(float speedMultiply)
    270240    {
    271         if(speedMultiply != 0.0f)
     241        if(speedMultiply != 0)
    272242        {
    273243            this->speedMultiply_ = speedMultiply;
     
    279249        }
    280250    }
     251
     252    void SpeedPickup::PickupTimerCallBack(void) {
     253        COUT(2) << "Timer ended!" << std::endl;
     254    }
    281255}
  • code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.h

    r6574 r6607  
    5757        Eric Beier
    5858    */
    59     class _PickupExport SpeedPickup : public Pickup, public Tickable
     59    class _PickupExport SpeedPickup : public Pickup
    6060    {
    6161        public:
     
    6565
    6666            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
    67             virtual void tick(float dt); //!< Is called every tick.
    6867
    6968            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
     
    8079            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    8180
    82             void setDuration(float duration); //!< Sets the duration
     81            void setDuration(float duration);
    8382            void setSpeedAdd(float speedAdd);
    8483            void setSpeedMultiply(float speedMultiply);
    8584
    86 
    8785        private:
    8886            void initialize(void); //!< Initializes the member variables.
    89             Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     87            void PickupTimerCallBack(void); //!< Function that gets called when timer ends.
     88            Engine* carrierToEngineHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
    9089
    9190            float duration_; //!< The health that is transferred to the Pawn.
Note: See TracChangeset for help on using the changeset viewer.