Changeset 9939 for code/trunk/src/modules/pong/PongBall.cc
- Timestamp:
- Dec 21, 2013, 11:16:54 PM (10 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/pong/PongBall.cc
r9667 r9939 40 40 41 41 #include "PongBat.h" 42 43 #include "sound/WorldSound.h" 44 #include "core/XMLPort.h" 42 45 43 46 namespace orxonox … … 66 69 67 70 this->registerVariables(); 71 72 //initialize sound 73 if (GameMode::isMaster()) 74 { 75 this->defScoreSound_ = new WorldSound(this->getContext()); 76 this->defScoreSound_->setVolume(1.0f); 77 this->defBatSound_ = new WorldSound(this->getContext()); 78 this->defBatSound_->setVolume(0.4f); 79 this->defBoundarySound_ = new WorldSound(this->getContext()); 80 this->defBoundarySound_->setVolume(0.5f); 81 } 82 else 83 { 84 this->defScoreSound_ = 0; 85 this->defBatSound_ = 0; 86 this->defBoundarySound_ = 0; 87 } 68 88 } 69 89 … … 81 101 delete[] this->batID_; 82 102 } 103 } 104 105 //xml port for loading sounds 106 void PongBall::XMLPort(Element& xmlelement, XMLPort::Mode mode) 107 { 108 SUPER(PongBall, XMLPort, xmlelement, mode); 109 XMLPortParam(PongBall, "defScoreSound", setDefScoreSound, getDefScoreSound, xmlelement, mode); 110 XMLPortParam(PongBall, "defBatSound", setDefBatSound, getDefBatSound, xmlelement, mode); 111 XMLPortParam(PongBall, "defBoundarySound", setDefBoundarySound, getDefBoundarySound, xmlelement, mode); 83 112 } 84 113 … … 117 146 if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2) 118 147 { 119 // Its velocity in z-direction is inverted (i.e. it bounces off). 148 defBoundarySound_->play(); //play boundary sound 149 // Its velocity in z-direction is inverted (i.e. it bounces off). 120 150 velocity.z = -velocity.z; 121 151 // And its position is set as to not overstep the boundary it has just crossed. … … 142 172 if (fabs(distance) <= 1) // If the bat is there to parry. 143 173 { 144 // Set the ball to be exactly at the boundary. 174 defBatSound_->play(); //play bat sound 175 // Set the ball to be exactly at the boundary. 145 176 position.x = this->fieldWidth_ / 2; 146 177 // Invert its velocity in x-direction (i.e. it bounces off). … … 155 186 else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_)) 156 187 { 188 defScoreSound_->play();//play score sound 157 189 if (this->getGametype() && this->bat_[0]) 158 190 { … … 169 201 if (fabs(distance) <= 1) // If the bat is there to parry. 170 202 { 171 // Set the ball to be exactly at the boundary. 203 defBatSound_->play(); //play bat sound 204 // Set the ball to be exactly at the boundary. 172 205 position.x = -this->fieldWidth_ / 2; 173 206 // Invert its velocity in x-direction (i.e. it bounces off). … … 182 215 else if (GameMode::isMaster() && position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_)) 183 216 { 217 defScoreSound_->play();//play score sound 184 218 if (this->getGametype() && this->bat_[1]) 185 219 { … … 262 296 this->bat_[1] = orxonox_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[1])); 263 297 } 298 299 void PongBall::setDefScoreSound(const std::string &pongSound) 300 { 301 if( defScoreSound_ ) 302 defScoreSound_->setSource(pongSound); 303 else 304 assert(0); // This should never happen, because soundpointer is only available on master 305 } 306 307 const std::string& PongBall::getDefScoreSound() 308 { 309 if( defScoreSound_ ) 310 return defScoreSound_->getSource(); 311 else 312 assert(0); 313 return BLANKSTRING; 314 } 315 316 void PongBall::setDefBatSound(const std::string &pongSound) 317 { 318 if( defBatSound_ ) 319 defBatSound_->setSource(pongSound); 320 else 321 assert(0); // This should never happen, because soundpointer is only available on master 322 } 323 324 const std::string& PongBall::getDefBatSound() 325 { 326 if( defBatSound_ ) 327 return defBatSound_->getSource(); 328 else 329 assert(0); 330 return BLANKSTRING; 331 } 332 333 void PongBall::setDefBoundarySound(const std::string &pongSound) 334 { 335 if( defBoundarySound_ ) 336 defBoundarySound_->setSource(pongSound); 337 else 338 assert(0); // This should never happen, because soundpointer is only available on master 339 } 340 341 const std::string& PongBall::getDefBoundarySound() 342 { 343 if( defBoundarySound_ ) 344 return defBoundarySound_->getSource(); 345 else 346 assert(0); 347 return BLANKSTRING; 348 } 264 349 }
Note: See TracChangeset
for help on using the changeset viewer.