Changeset 11071 for code/trunk/src/modules/pong/Pong.cc
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (8 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/pong/Pong.cc
r9939 r11071 64 64 RegisterObject(Pong); 65 65 66 this->center_ = 0;67 this->ball_ = 0;68 this->bat_[0] = 0;69 this->bat_[1] = 0;66 this->center_ = nullptr; 67 this->ball_ = nullptr; 68 this->bat_[0] = nullptr; 69 this->bat_[1] = nullptr; 70 70 71 71 this->setHUDTemplate("PongHUD"); … … 103 103 void Pong::cleanup() 104 104 { 105 if (this->ball_ != NULL) // Destroy the ball, if present.105 if (this->ball_ != nullptr) // Destroy the ball, if present. 106 106 { 107 107 this->ball_->destroy(); 108 this->ball_ = 0;108 this->ball_ = nullptr; 109 109 } 110 110 … … 112 112 for (size_t i = 0; i < 2; ++i) 113 113 { 114 if (this->bat_[0] != NULL)114 if (this->bat_[0] != nullptr) 115 115 { 116 116 this->bat_[0]->destroy(); 117 this->bat_[0] = 0;117 this->bat_[0] = nullptr; 118 118 } 119 119 } … … 127 127 void Pong::start() 128 128 { 129 if (this->center_ != NULL) // There needs to be a PongCenterpoint, i.e. the area the game takes place.130 { 131 if (this->ball_ == NULL) // If there is no ball, create a new ball.129 if (this->center_ != nullptr) // There needs to be a PongCenterpoint, i.e. the area the game takes place. 130 { 131 if (this->ball_ == nullptr) // If there is no ball, create a new ball. 132 132 { 133 133 this->ball_ = new PongBall(this->center_->getContext()); … … 145 145 146 146 // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint. 147 for ( size_t i = 0; i < 2; ++i)147 for (WeakPtr<orxonox::PongBat>& bat : this->bat_) 148 148 { 149 if ( this->bat_[i] == NULL)149 if (bat == nullptr) 150 150 { 151 this->bat_[i]= new PongBat(this->center_->getContext());152 this->bat_[i]->addTemplate(this->center_->getBattemplate());151 bat = new PongBat(this->center_->getContext()); 152 bat->addTemplate(this->center_->getBattemplate()); 153 153 } 154 154 } … … 211 211 { 212 212 // first spawn human players to assign always the left bat to the player in singleplayer 213 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)214 if ( it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))215 this->spawnPlayer( it->first);213 for (const auto& mapEntry : this->players_) 214 if (mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_)) 215 this->spawnPlayer(mapEntry.first); 216 216 // now spawn bots 217 for ( std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)218 if (! it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))219 this->spawnPlayer( it->first);217 for (const auto& mapEntry : this->players_) 218 if (!mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_)) 219 this->spawnPlayer(mapEntry.first); 220 220 } 221 221 … … 231 231 232 232 // If the first (left) bat has no player. 233 if (this->bat_[0]->getPlayer() == NULL)233 if (this->bat_[0]->getPlayer() == nullptr) 234 234 { 235 235 player->startControl(this->bat_[0]); … … 237 237 } 238 238 // If the second (right) bat has no player. 239 else if (this->bat_[1]->getPlayer() == NULL)239 else if (this->bat_[1]->getPlayer() == nullptr) 240 240 { 241 241 player->startControl(this->bat_[1]); … … 247 247 248 248 // If the player is an AI, it receives a pointer to the ball. 249 if (player->getController() != NULL&& player->getController()->isA(Class(PongAI)))249 if (player->getController() != nullptr && player->getController()->isA(Class(PongAI))) 250 250 { 251 251 PongAI* ai = orxonox_cast<PongAI*>(player->getController()); … … 262 262 Deathmatch::playerScored(player, score); 263 263 264 if (this->center_ != NULL) // If there is a centerpoint.264 if (this->center_ != nullptr) // If there is a centerpoint. 265 265 { 266 266 // Fire an event for the player that has scored, to be able to react to it in the level, e.g. by displaying fireworks. … … 271 271 272 272 // Also announce, that the player has scored. 273 if (player != NULL)273 if (player != nullptr) 274 274 this->gtinfo_->sendAnnounceMessage(player->getName() + " scored"); 275 275 } 276 276 277 277 // If there is a ball present, reset its position, velocity and acceleration. 278 if (this->ball_ != NULL)278 if (this->ball_ != nullptr) 279 279 { 280 280 this->ball_->setPosition(Vector3::ZERO); … … 285 285 286 286 // If there are bats reset them to the middle position. 287 if (this->bat_[0] != NULL && this->bat_[1] != NULL)287 if (this->bat_[0] != nullptr && this->bat_[1] != nullptr) 288 288 { 289 289 this->bat_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0); … … 292 292 293 293 // If a player gets enough points, he won the game -> end of game 294 PlayerInfo* winningPlayer = NULL;294 PlayerInfo* winningPlayer = nullptr; 295 295 if (this->getLeftPlayer() && this->getScore(this->getLeftPlayer()) >= scoreLimit_) 296 296 winningPlayer = this->getLeftPlayer(); … … 314 314 void Pong::startBall() 315 315 { 316 if (this->ball_ != NULL && this->center_ != NULL)316 if (this->ball_ != nullptr && this->center_ != nullptr) 317 317 this->ball_->setSpeed(this->center_->getBallSpeed()); 318 318 } … … 322 322 Get the left player. 323 323 @return 324 Returns a pointer to the player playing on the left. If there is no left player, NULLis returned.324 Returns a pointer to the player playing on the left. If there is no left player, nullptr is returned. 325 325 */ 326 326 PlayerInfo* Pong::getLeftPlayer() const 327 327 { 328 if (this->bat_ != NULL && this->bat_[0] != NULL)328 if (this->bat_ != nullptr && this->bat_[0] != nullptr) 329 329 return this->bat_[0]->getPlayer(); 330 330 else 331 return 0;331 return nullptr; 332 332 } 333 333 … … 336 336 Get the right player. 337 337 @return 338 Returns a pointer to the player playing on the right. If there is no right player, NULLis returned.338 Returns a pointer to the player playing on the right. If there is no right player, nullptr is returned. 339 339 */ 340 340 PlayerInfo* Pong::getRightPlayer() const 341 341 { 342 if (this->bat_ != NULL && this->bat_[1] != NULL)342 if (this->bat_ != nullptr && this->bat_[1] != nullptr) 343 343 return this->bat_[1]->getPlayer(); 344 344 else 345 return 0;345 return nullptr; 346 346 } 347 347 }
Note: See TracChangeset
for help on using the changeset viewer.