Changeset 9939 for code/trunk/src/modules/pong
- Timestamp:
- Dec 21, 2013, 11:16:54 PM (11 years ago)
- Location:
- code/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/pong/Pong.cc
r9667 r9939 47 47 #include "PongBot.h" 48 48 #include "PongAI.h" 49 49 50 namespace orxonox 50 51 { … … 117 118 } 118 119 } 120 119 121 } 120 122 -
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 } -
code/trunk/src/modules/pong/PongBall.h
r9667 r9939 42 42 #include "worldentities/MovableEntity.h" 43 43 44 44 45 namespace orxonox 45 46 { … … 63 64 64 65 virtual void tick(float dt); 66 67 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 65 68 66 69 /** … … 123 126 static const float MAX_REL_Z_VELOCITY; 124 127 128 void setDefScoreSound(const std::string& engineSound); 129 const std::string& getDefScoreSound(); 130 void setDefBatSound(const std::string& engineSound); 131 const std::string& getDefBatSound(); 132 void setDefBoundarySound(const std::string& engineSound); 133 const std::string& getDefBoundarySound(); 134 125 135 private: 126 136 void registerVariables(); … … 135 145 unsigned int* batID_; //!< The object IDs of the bats, to be able to synchronize them over the network. 136 146 float relMercyOffset_; //!< Offset, that makes the player not loose, when, in all fairness, he would have. 147 WorldSound* defScoreSound_; 148 WorldSound* defBatSound_; 149 WorldSound* defBoundarySound_; 137 150 }; 138 151 } -
code/trunk/src/modules/pong/PongScore.cc
r9667 r9939 41 41 42 42 #include "Pong.h" 43 #include "sound/WorldSound.h" ///////////////////////////// 43 44 44 45 namespace orxonox -
code/trunk/src/modules/pong/PongScore.h
r9667 r9939 124 124 WeakPtr<PlayerInfo> player1_; //!< Store information about left player permanently. 125 125 WeakPtr<PlayerInfo> player2_; //!< Same for the right player. To end the game properly. 126 WorldSound* scoreSound_; 127 126 128 }; 127 129 }
Note: See TracChangeset
for help on using the changeset viewer.