Changeset 6607 for code/branches/ppspickups1/src/modules/pickup/items
- Timestamp:
- Mar 22, 2010, 10:45:09 PM (15 years ago)
- 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 38 38 #include "util/StringUtils.h" 39 39 40 #include "worldentities/pawns/Pawn.h" 40 #include "worldentities/pawns/SpaceShip.h" 41 #include "items/Engine.h" 41 42 #include "pickup/PickupIdentifier.h" 42 43 … … 123 124 /** 124 125 @brief 125 Is called every tick.126 Does count down the duration of the SpeedPickup.127 @param dt128 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 Pickup139 float duration=this->getDuration()-dt;140 this->setDuration(duration);141 142 //! If duration is over143 if(this->getDuration() < 0)144 {145 this->setUsed(false);146 }147 }148 }149 150 /**151 @brief152 126 Is called when the pickup has transited from used to unused or the other way around. 153 127 */ … … 163 137 if(this->isUsed()) 164 138 { 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. 180 143 this->destroy(); 181 } 182 } 183 } 144 engine->setSpeedAdd(this->getSpeedAdd()); 145 engine->setSpeedMultiply(this->getSpeedMultiply()); 146 } 147 } 148 149 184 150 185 151 /** … … 189 155 A pointer to the Pawn, or NULL if the conversion failed. 190 156 */ 191 Pawn* SpeedPickup::carrierToPawnHelper(void)157 Engine* SpeedPickup::carrierToEngineHelper(void) 192 158 { 193 159 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) 197 163 { 198 164 COUT(1) << "Invalid PickupCarrier in SpeedPickup." << std::endl; 199 165 } 200 201 return pawn; 166 else 167 { 168 return ship->getEngine(); 169 } 170 171 return 0; 202 172 } 203 173 … … 238 208 { 239 209 COUT(1) << "Invalid duration in SpeedPickup." << std::endl; 240 this->duration_ = 0 .0;210 this->duration_ = 0; 241 211 } 242 212 } … … 250 220 void SpeedPickup::setSpeedAdd(float speedAdd) 251 221 { 252 if(speedAdd > 0.0f)222 if(speedAdd >= 0.0f) 253 223 { 254 224 this->speedAdd_ = speedAdd; … … 269 239 void SpeedPickup::setSpeedMultiply(float speedMultiply) 270 240 { 271 if(speedMultiply != 0 .0f)241 if(speedMultiply != 0) 272 242 { 273 243 this->speedMultiply_ = speedMultiply; … … 279 249 } 280 250 } 251 252 void SpeedPickup::PickupTimerCallBack(void) { 253 COUT(2) << "Timer ended!" << std::endl; 254 } 281 255 } -
code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.h
r6574 r6607 57 57 Eric Beier 58 58 */ 59 class _PickupExport SpeedPickup : public Pickup , public Tickable59 class _PickupExport SpeedPickup : public Pickup 60 60 { 61 61 public: … … 65 65 66 66 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.68 67 69 68 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. … … 80 79 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 81 80 82 void setDuration(float duration); //!< Sets the duration81 void setDuration(float duration); 83 82 void setSpeedAdd(float speedAdd); 84 83 void setSpeedMultiply(float speedMultiply); 85 84 86 87 85 private: 88 86 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. 90 89 91 90 float duration_; //!< The health that is transferred to the Pawn.
Note: See TracChangeset
for help on using the changeset viewer.