Changeset 8534 for code/branches/pickup
- Timestamp:
- May 23, 2011, 2:37:08 PM (14 years ago)
- Location:
- code/branches/pickup
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup/data/levels/pickups.oxw
r8502 r8534 192 192 <PickupSpawner position="-30,-30,-30" respawnTime="60" triggerDistance="20" maxSpawnedItems="5"> 193 193 <pickup> 194 <ShrinkPickup />194 <ShrinkPickup shrinkFactor = "5.0" duration = "5.0" shrinkSpeed = "5.0"/> 195 195 </pickup> 196 196 </PickupSpawner> -
code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc
r8502 r8534 51 51 CreateFactory(ShrinkPickup); 52 52 53 /** 54 @brief 55 Constructor: Initializes the Pickup. 56 */ 53 57 ShrinkPickup::ShrinkPickup(BaseObject* creator) : Pickup(creator) 54 58 { … … 56 60 57 61 this->initialize(); 58 shrinkFactor_ = 5.0;59 duration_ = 5.0;60 shrinkSpeed_ = 5.0;61 62 isActive_ = false; 62 63 isTerminating_ = false; … … 68 69 } 69 70 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 70 140 void ShrinkPickup::initialize(void) 71 141 { … … 73 143 } 74 144 145 /** 146 @brief 147 Prepares for shrinking (collecting several informations). 148 */ 75 149 void ShrinkPickup::changedUsed(void) 76 150 { … … 83 157 this->Pickupable::destroy(); 84 158 159 //Collect scaling information. 85 160 defaultScale_ = this->pawn->getScale3D(); 86 161 defaultMass_ = this->pawn->getMass(); … … 94 169 cameraPositions_ = this->pawn->getCameraPositions(); 95 170 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. 98 173 } 99 174 } 100 175 176 /** 177 @brief 178 Updates the scales of the ship. 179 @param dt 180 Time since last call. 181 */ 101 182 void ShrinkPickup::tick(float dt) 102 183 { 103 if(isActive_ == true && actualScale_ > smallScale_) 184 if(isActive_ == true && actualScale_ > smallScale_) //if the ship has not reached the target scale, continue shrinking 104 185 { 105 186 float factor_ = 1 + dt*shrinkSpeed_; … … 121 202 else isActive_ = false; 122 203 123 if(isTerminating_ == true && actualScale_ < defaultScale_) 204 if(isTerminating_ == true && actualScale_ < defaultScale_) //grow until the ship reaches its default scale. 124 205 { 125 206 float factor_ = 1 + dt*shrinkSpeed_; … … 144 225 } 145 226 227 /** 228 @brief 229 Initializes the termination. 230 */ 146 231 void ShrinkPickup::terminate(void) 147 232 { … … 171 256 172 257 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(); 173 264 } 174 265 } -
code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h
r8502 r8534 59 59 virtual ~ShrinkPickup(); //!< Destructor. 60 60 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); 63 76 64 77 private: 65 78 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); 86 97 }; 87 98 }
Note: See TracChangeset
for help on using the changeset viewer.