Changeset 6708 for code/branches/ppspickups2/src/modules/pickup/items
- Timestamp:
- Apr 13, 2010, 9:07:08 AM (15 years ago)
- Location:
- code/branches/ppspickups2/src/modules/pickup/items
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ppspickups2/src/modules/pickup/items/CMakeLists.txt
r6641 r6708 1 1 ADD_SOURCE_FILES(PICKUP_SRC_FILES 2 2 HealthPickup.cc 3 InvisiblePickup.cc 3 4 MetaPickup.cc 4 InvisiblePickup.cc5 5 ) -
code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.cc
r6684 r6708 55 55 { 56 56 RegisterObject(InvisiblePickup); 57 58 57 //! Defines who is allowed to pick up the pickup. 58 this->initialize(); 59 59 } 60 60 … … 70 70 void InvisiblePickup::initializeIdentifier(void) 71 71 { 72 73 74 75 76 72 std::stringstream stream; 73 stream << this->getDuration(); 74 std::string type1 = "duration"; 75 std::string val1 = stream.str(); 76 this->pickupIdentifier_->addParameter(type1, val1); 77 77 } 78 78 … … 83 83 void InvisiblePickup::initialize(void) 84 84 { 85 this->duration_ = 0.0;86 85 this->duration_ = 0.0f; 86 this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); 87 87 } 88 88 … … 94 94 { 95 95 SUPER(InvisiblePickup, XMLPort, xmlelement, mode); 96 97 98 96 XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode); 97 98 this->initializeIdentifier(); 99 99 } 100 100 … … 106 106 { 107 107 SUPER(InvisiblePickup, changedUsed); 108 109 108 110 109 //! If the pickup is not picked up nothing must be done. 111 110 if(!this->isPickedUp()) 112 111 return; 113 if (this->isUsed()) 114 { 115 this->startPickupTimer(this->getDuration()); 116 this->setInvisible(true); 117 } 118 else 119 this->setInvisible(false); 120 112 113 if (this->isUsed()) 114 { 115 this->startPickupTimer(this->getDuration()); 116 this->setInvisible(true); 117 } 118 else 119 { 120 this->setInvisible(false); 121 this->destroy(); 122 } 123 121 124 } 122 125 … … 151 154 152 155 SUPER(InvisiblePickup, clone, item); 153 154 155 156 156 157 InvisiblePickup* pickup = dynamic_cast<InvisiblePickup*>(item); 158 pickup->setDuration(this->getDuration()); 159 pickup->initializeIdentifier(); 157 160 } 158 161 … … 160 163 @brief 161 164 Sets the invisibility. 162 @param health165 @param invisibility 163 166 The invisibility. 164 167 */ 165 168 bool InvisiblePickup::setInvisible(bool invisibility) 166 169 { 167 168 Pawn* pawn = this->carrierToPawnHelper(); 169 pawn->setVisible(!invisibility); 170 return 0; 171 } 172 173 /** 174 @brief 175 Sets the duration. 170 Pawn* pawn = this->carrierToPawnHelper(); 171 if(pawn == NULL) 172 return false; 173 174 pawn->setVisible(!invisibility); 175 return true; 176 } 177 178 /** 179 @brief 180 Sets the duration. 176 181 @param duration 177 The duration182 The duration 178 183 */ 179 184 void InvisiblePickup::setDuration(float duration) 180 185 { 181 182 183 184 185 186 187 188 this->duration_ = 0;189 190 } 191 192 void InvisiblePickup:: PickupTimerCallBack(void)193 { 194 this->setInvisible(false);186 if(duration >= 0.0f) 187 { 188 this->duration_ = duration; 189 } 190 else 191 { 192 COUT(1) << "Invalid duration in InvisiblePickup." << std::endl; 193 this->duration_ = 0.0f; 194 } 195 } 196 197 void InvisiblePickup::pickupTimerCallback(void) 198 { 199 this->setUsed(false); 195 200 } 196 201 -
code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.h
r6641 r6708 64 64 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 65 65 66 67 @brief Checks w ether the Pawn is invisible.66 /** 67 @brief Checks whether the Pawn is invisible. 68 68 @return Returns if the Pawn is invisible. 69 69 */ 70 70 inline bool getInvisibility(bool) 71 71 { return this->invisible_; } 72 73 {return this->duration_;}72 inline float getDuration() 73 { return this->duration_; } 74 74 75 75 protected: 76 bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again. 77 void setDuration(float duration); 78 void initializeIdentifier(void); 76 bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again. 77 void setDuration(float duration); 78 void initializeIdentifier(void); 79 virtual void pickupTimerCallback(void); //!< Function that gets called when the timer ends. 79 80 80 81 private: 81 82 void initialize(void); //!< Initializes the member variables. 82 83 Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 83 void PickupTimerCallBack(void); //!< Function that gets called when the timer ends. 84 bool invisible_; //!< Helper to remember wether the Pawn is invisible. 85 float duration_; //! Duration of invisibility. 84 bool invisible_; //!< Helper to remember wether the Pawn is invisible. 85 float duration_; //! Duration of invisibility. 86 86 }; 87 87 }
Note: See TracChangeset
for help on using the changeset viewer.