Changeset 8108 for code/trunk/src
- Timestamp:
- Mar 23, 2011, 9:57:54 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/tetris (added) merged: 8104-8107
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/Loader.cc
r8079 r8108 144 144 @param verbose 145 145 Whether the loader is verbose (prints its progress in a low output level) or not. 146 @param bRemoveLuaTags 147 If true lua tags are just ignored and removed. The default is false. 146 148 @return 147 149 Returns true if successful. -
code/trunk/src/libraries/network/Host.cc
r8079 r8108 75 75 * @param packet Packet to be added 76 76 * @param clientID ID of the client the packet should be sent to 77 * @param channelID ID of the channel. 77 78 * @return success? 78 79 */ -
code/trunk/src/libraries/network/MasterServerComm.h
r7804 r8108 89 89 90 90 /** \param callback The callback function to call with data received. 91 * \param delayms Delay in milliseconds. 91 92 * \return 0 for success, other for error 92 93 * -
code/trunk/src/modules/designtools/ScreenshotManager.cc
r8079 r8108 61 61 @brief 62 62 Creates a screenshot with the given camera. 63 @param camera64 Pointer to the camera "looking at" the scene of interest65 @param fileName66 the filename of the screenshot file.67 63 */ 68 64 void ScreenshotManager::makeScreenshot() const -
code/trunk/src/modules/pickup/Pickup.h
r7547 r8108 81 81 The Pickup class offers (useful) base functionality for a wide range of pickups. 82 82 83 Pickups in geriting from this class can choose an activation type and a duration type.83 Pickups inheriting from this class can choose an activation type and a duration type. 84 84 - The <b>activationType</b> deals with what happens to the Pickup as soon as it is picked up. It can either be set to <em>immediate</em>, which means that the Pickup is activated/used immediately upon being picked up. Or to <em>onUse</em>, which means, that the Pickup will be activated/used if some outside entity (most commonly the player through the PickupInventory) decides to use it. Default is <em>immediate</em>. 85 85 - The <b>durationType</b> deals with whether the Pickup has a continuous effect or whether its effect is focused on a singular instant. It can either be set to <em>once</em>, which means, that the Pickup just has an effect (at a singular instant in time) and is done once that effect has been applied. Or to <em>continuous</em>, which means that the effect of the Pickup unfolds over some timespan. Default is <em>once</em>. -
code/trunk/src/modules/pong/Pong.cc
r7911 r8108 27 27 */ 28 28 29 /** 30 @file Pong.cc 31 @brief Implementation of the Pong class. 32 */ 33 29 34 #include "Pong.h" 30 35 … … 32 37 #include "core/EventIncludes.h" 33 38 #include "core/command/Executor.h" 39 40 #include "gamestates/GSLevel.h" 41 34 42 #include "PongCenterpoint.h" 35 43 #include "PongBall.h" … … 40 48 namespace orxonox 41 49 { 50 // Events to allow to react to scoring of a player, in the level-file. 42 51 CreateEventName(PongCenterpoint, right); 43 52 CreateEventName(PongCenterpoint, left); … … 45 54 CreateUnloadableFactory(Pong); 46 55 56 /** 57 @brief 58 Constructor. Registers and initializes the object. 59 */ 47 60 Pong::Pong(BaseObject* creator) : Deathmatch(creator) 48 61 { … … 56 69 this->setHUDTemplate("PongHUD"); 57 70 71 // Pre-set the timer, but don't start it yet. 58 72 this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Pong::startBall, this))); 59 73 this->starttimer_.stopTimer(); 60 74 75 // Set the type of Bots for this particular Gametype. 61 76 this->botclass_ = Class(PongBot); 62 77 } 63 78 79 /** 80 @brief 81 Destructor. Cleans up, if initialized. 82 */ 64 83 Pong::~Pong() 65 84 { … … 68 87 } 69 88 89 /** 90 @brief 91 Cleans up the Gametype by destroying the ball and the bats. 92 */ 70 93 void Pong::cleanup() 71 94 { 72 if (this->ball_ )95 if (this->ball_ != NULL) // Destroy the ball, if present. 73 96 { 74 97 this->ball_->destroy(); … … 76 99 } 77 100 101 // Destroy both bats, if present. 78 102 for (size_t i = 0; i < 2; ++i) 79 103 { 80 if (this->bat_[0] )104 if (this->bat_[0] != NULL) 81 105 { 82 106 this->bat_[0]->destroy(); … … 86 110 } 87 111 112 /** 113 @brief 114 Starts the Pong minigame. 115 */ 88 116 void Pong::start() 89 117 { 90 if (this->center_ )91 { 92 if ( !this->ball_)118 if (this->center_ != NULL) // There needs to be a PongCenterpoint, i.e. the area the game takes place. 119 { 120 if (this->ball_ == NULL) // If there is no ball, create a new ball. 93 121 { 94 122 this->ball_ = new PongBall(this->center_); 123 // Apply the template for the ball specified by the centerpoint. 95 124 this->ball_->addTemplate(this->center_->getBalltemplate()); 96 125 } 97 126 127 // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to. 98 128 this->center_->attach(this->ball_); 99 129 this->ball_->setPosition(0, 0, 0); … … 103 133 this->ball_->setBatLength(this->center_->getBatLength()); 104 134 105 if (!this->bat_[0]) 135 // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint. 136 for (size_t i = 0; i < 2; ++i) 106 137 { 107 this->bat_[0] = new PongBat(this->center_); 108 this->bat_[0]->addTemplate(this->center_->getBattemplate()); 138 if (this->bat_[i] == NULL) 139 { 140 this->bat_[i] = new PongBat(this->center_); 141 this->bat_[i]->addTemplate(this->center_->getBattemplate()); 142 } 109 143 } 110 if (!this->bat_[1]) 111 { 112 this->bat_[1] = new PongBat(this->center_); 113 this->bat_[1]->addTemplate(this->center_->getBattemplate()); 114 } 115 144 145 // Attach the bats to the centerpoint and set the parameters as specified in the centerpoint, the bats are attached to. 116 146 this->center_->attach(this->bat_[0]); 117 147 this->center_->attach(this->bat_[1]); … … 127 157 this->bat_[1]->setLength(this->center_->getBatLength()); 128 158 159 // Set the bats for the ball. 129 160 this->ball_->setBats(this->bat_); 130 161 } 131 else 162 else // If no centerpoint was specified, an error is thrown and the level is exited. 132 163 { 133 164 COUT(1) << "Error: No Centerpoint specified." << std::endl; 134 } 135 165 GSLevel::startMainMenu(); 166 return; 167 } 168 169 // Start the timer. After it has expired the ball is started. 136 170 this->starttimer_.startTimer(); 137 171 138 172 // Set variable to temporarily force the player to spawn. 139 173 bool temp = this->bForceSpawn_; 140 174 this->bForceSpawn_ = true; 141 175 176 // Call start for the parent class. 142 177 Deathmatch::start(); 143 178 179 // Reset the variable. 144 180 this->bForceSpawn_ = temp; 145 181 } 146 182 183 /** 184 @brief 185 Ends the Pong minigame. 186 */ 147 187 void Pong::end() 148 188 { 149 189 this->cleanup(); 150 190 191 // Call end for the parent class. 151 192 Deathmatch::end(); 152 193 } 153 194 195 /** 196 @brief 197 Spawns players, and fills the rest up with bots. 198 */ 154 199 void Pong::spawnPlayersIfRequested() 155 200 { … … 164 209 } 165 210 211 /** 212 @brief 213 Spawns the input player. 214 @param player 215 The player to be spawned. 216 */ 166 217 void Pong::spawnPlayer(PlayerInfo* player) 167 218 { 168 if (!this->bat_[0]->getPlayer()) 219 assert(player); 220 221 // If the first (left) bat has no player. 222 if (this->bat_[0]->getPlayer() == NULL) 169 223 { 170 224 player->startControl(this->bat_[0]); 171 225 this->players_[player].state_ = PlayerState::Alive; 172 226 } 173 else if (!this->bat_[1]->getPlayer()) 227 // If the second (right) bat has no player. 228 else if (this->bat_[1]->getPlayer() == NULL) 174 229 { 175 230 player->startControl(this->bat_[1]); 176 231 this->players_[player].state_ = PlayerState::Alive; 177 232 } 233 // If both bats are taken. 178 234 else 179 235 return; 180 236 181 if (player && player->getController() && player->getController()->isA(Class(PongAI))) 237 // If the player is an AI, it receives a pointer to the ball. 238 if (player->getController() != NULL && player->getController()->isA(Class(PongAI))) 182 239 { 183 240 PongAI* ai = orxonox_cast<PongAI*>(player->getController()); … … 186 243 } 187 244 245 /** 246 @brief 247 Is called when the player scored. 248 */ 188 249 void Pong::playerScored(PlayerInfo* player) 189 250 { 190 251 Deathmatch::playerScored(player); 191 252 192 if (this->center_) 193 { 253 if (this->center_ != NULL) // If there is a centerpoint. 254 { 255 // Fire an event for the player that has scored, to be able to react to it in the level, e.g. by displaying fireworks. 194 256 if (player == this->getRightPlayer()) 195 257 this->center_->fireEvent(FireEventName(PongCenterpoint, right)); … … 197 259 this->center_->fireEvent(FireEventName(PongCenterpoint, left)); 198 260 199 if (player) 261 // Also announce, that the player has scored. 262 if (player != NULL) 200 263 this->gtinfo_->sendAnnounceMessage(player->getName() + " scored"); 201 264 } 202 265 203 if (this->ball_) 266 // If there is a ball present, reset its position, velocity and acceleration. 267 if (this->ball_ != NULL) 204 268 { 205 269 this->ball_->setPosition(Vector3::ZERO); … … 209 273 } 210 274 211 if (this->bat_[0] && this->bat_[1]) 275 // If there are bats reset them to the middle position. 276 if (this->bat_[0] != NULL && this->bat_[1] != NULL) 212 277 { 213 278 this->bat_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0); … … 215 280 } 216 281 282 // Restart the timer to start the ball. 217 283 this->starttimer_.startTimer(); 218 284 } 219 285 286 /** 287 @brief 288 Starts the ball with some default speed. 289 */ 220 290 void Pong::startBall() 221 291 { 222 if (this->ball_ && this->center_)292 if (this->ball_ != NULL && this->center_ != NULL) 223 293 this->ball_->setSpeed(this->center_->getBallSpeed()); 224 294 } 225 295 296 /** 297 @brief 298 Get the left player. 299 @return 300 Returns a pointer to the player playing on the left. If there is no left player, NULL is returned. 301 */ 226 302 PlayerInfo* Pong::getLeftPlayer() const 227 303 { 228 if (this->bat_ && this->bat_[0])304 if (this->bat_ != NULL && this->bat_[0] != NULL) 229 305 return this->bat_[0]->getPlayer(); 230 306 else … … 232 308 } 233 309 310 /** 311 @brief 312 Get the right player. 313 @return 314 Returns a pointer to the player playing on the right. If there is no right player, NULL is returned. 315 */ 234 316 PlayerInfo* Pong::getRightPlayer() const 235 317 { 236 if (this->bat_ && this->bat_[1])318 if (this->bat_ != NULL && this->bat_[1] != NULL) 237 319 return this->bat_[1]->getPlayer(); 238 320 else -
code/trunk/src/modules/pong/Pong.h
r7911 r8108 27 27 */ 28 28 29 /** 30 @file Pong.h 31 @brief Declaration of the Pong class. 32 @ingroup Pong 33 */ 34 29 35 #ifndef _Pong_H__ 30 36 #define _Pong_H__ … … 33 39 34 40 #include "tools/Timer.h" 41 35 42 #include "gametypes/Deathmatch.h" 36 43 37 44 namespace orxonox 38 45 { 46 47 /** 48 @brief 49 Implements a Pong minigame (<a href="http://en.wikipedia.org/wiki/Pong">Wikipedia::Pong</a>). 50 It connects the different entities present in a game of Pong. 51 52 - The @ref orxonox::PongCenterpoint "PongCenterpoint" is the playing field for the Pong minigame, it allows for configuration of the minigame, e.g. by setting the size of the playing field, or the length of the @ref orxonox::PongBat "PongBats". The playing field is always in the x,y-plane, the x-axis being the horizontal and the z-axis being the vertical axis.<br /> 53 The Pong class redistributes the important parameters defined in @ref orxonox::PongCenterpoint "PongCenterpoint" to the other entities, that need to know them, e.g. the @ref orxonox::PongBall "PongBall" and the @ref orxonox::PongBat "PongBats".<br /> 54 The @ref orxonox::PongCenterpoint "PongCenterpoint" needs to exist in a level with the @ref orxonox::Gametype "Gametype" <em>Pong</em>. 55 - The @ref orxonox::PongBall "PongBall" is the ball both players play with. The @ref orxonox::PongBall "PongBall" both implements the movement of the ball, as well as the influence of the boundaries and consequently, also the bouncing (off the upper and lower delimiters, and as off the @ref orxonox::PongBat "PongBats") of the ball and the effects of the failure of a player to catch the ball (i.e. the scoring of the other player). 56 - The two @ref orxonox::PongBat "PongBats" are the entities through which the players can actively participate in the game, by controlling them. The @ref orxonox::PongBat "PongBat" class manages the movement (and restrictions thereof) and the influence of the players on the bats. 57 58 @author 59 Fabian 'x3n' Landau 60 61 @ingroup Pong 62 */ 39 63 class _PongExport Pong : public Deathmatch 40 64 { 41 65 public: 42 Pong(BaseObject* creator); 43 virtual ~Pong(); 66 Pong(BaseObject* creator); //!< Constructor. Registers and initializes the object. 67 virtual ~Pong(); //!< Destructor. Cleans up, if initialized. 44 68 45 virtual void start(); 46 virtual void end(); 69 virtual void start(); //!< Starts the Pong minigame. 70 virtual void end(); ///!< Ends the Pong minigame. 47 71 48 virtual void spawnPlayer(PlayerInfo* player); 72 virtual void spawnPlayer(PlayerInfo* player); //!< Spawns the input player. 49 73 50 virtual void playerScored(PlayerInfo* player); 74 virtual void playerScored(PlayerInfo* player); //!< Is called when the player scored. 51 75 76 /** 77 @brief Set the PongCenterpoint (the playing field). 78 @param center A pointer to the PongCenterpoint to be set. 79 */ 52 80 void setCenterpoint(PongCenterpoint* center) 53 81 { this->center_ = center; } 54 82 55 PlayerInfo* getLeftPlayer() const; 56 PlayerInfo* getRightPlayer() const; 83 PlayerInfo* getLeftPlayer() const; //!< Get the left player. 84 PlayerInfo* getRightPlayer() const; //!< Get the right player. 57 85 58 86 protected: 59 virtual void spawnPlayersIfRequested(); 87 virtual void spawnPlayersIfRequested(); //!< Spawns players, and fills the rest up with bots. 60 88 61 void startBall(); 62 void cleanup(); 89 void startBall(); //!< Starts the ball with some default speed. 90 void cleanup(); //!< Cleans up the Gametype by destroying the ball and the bats. 63 91 64 WeakPtr<PongCenterpoint> center_; 65 WeakPtr<PongBall> ball_; 66 WeakPtr<PongBat> bat_[2]; 67 Timer starttimer_; 92 WeakPtr<PongCenterpoint> center_; //!< The playing field. 93 WeakPtr<PongBall> ball_; //!< The Pong ball. 94 WeakPtr<PongBat> bat_[2]; //!< The two bats. 95 Timer starttimer_; //!< A timer to delay the start of the game. 68 96 }; 69 97 } -
code/trunk/src/modules/pong/PongAI.cc
r6417 r8108 27 27 */ 28 28 29 /** 30 @file PongAI.cc 31 @brief Implementation of the PongAI class. 32 */ 33 29 34 #include "PongAI.h" 30 35 … … 32 37 #include "core/ConfigValueIncludes.h" 33 38 #include "tools/Timer.h" 39 34 40 #include "worldentities/ControllableEntity.h" 41 35 42 #include "PongBall.h" 36 43 … … 41 48 const static float MAX_REACTION_TIME = 0.4f; 42 49 50 /** 51 @brief 52 Constructor. Registers and initializes the object. 53 */ 43 54 PongAI::PongAI(BaseObject* creator) : Controller(creator) 44 55 { … … 59 70 } 60 71 72 /** 73 @brief 74 Destructor. Cleans up the list fo reaction timers. 75 */ 61 76 PongAI::~PongAI() 62 77 { … … 65 80 } 66 81 82 /** 83 @brief 84 Sets config values. 85 */ 67 86 void PongAI::setConfigValues() 68 87 { 88 // Sets the strength of the PongAi as a config value. 69 89 SetConfigValue(strength_, 0.5).description("A value from 0 to 1 where 0 is weak and 1 is strong."); 70 90 } 71 91 92 /** 93 @brief 94 Is called each tick. 95 Implements the behavior of the PongAI (i.e. its intelligence). 96 @param dt 97 The time that has elapsed since the last tick. 98 */ 72 99 void PongAI::tick(float dt) 73 100 { 74 if (!this->ball_ || !this->getControllableEntity()) 101 // If either the ball, or the controllable entity (i.e. the bat) don't exist (or aren't set). 102 if (this->ball_ == NULL || this->getControllableEntity() == NULL) 75 103 return; 76 104 … … 109 137 if (this->ballDirection_.x != 1) 110 138 { 111 // The ball just starte tto approach, initialize all values139 // The ball just started to approach, initialize all values 112 140 this->ballDirection_.x = 1; 113 141 this->ballDirection_.y = sgn(ballvel.z); … … 158 186 { 159 187 // We had to correct our position because we moved too far 160 // (and delay is tfalse, so we're not in the wrong place because of a new end-position prediction)188 // (and delay is false, so we're not in the wrong place because of a new end-position prediction) 161 189 if (fabs(mypos.z - this->ballEndPosition_) < 0.5 * this->ball_->getBatLength() * this->ball_->getFieldDimension().y) 162 190 { … … 173 201 } 174 202 203 /** 204 @brief 205 Calculates the random offset, that accounts for random errors the AI makes in order to be beatable. 206 The higher the strength of the AI, the smaller the (expected value of the) error. 207 The result of this method is stored in this->randomOffset_. 208 */ 175 209 void PongAI::calculateRandomOffset() 176 210 { … … 184 218 // exp < 1 -> position is more likely a large number 185 219 186 // The position shoul n't be larger than 0.5 (50% of the bat-length from the middle is the end)220 // The position shouldn't be larger than 0.5 (50% of the bat-length from the middle is the end) 187 221 position *= 0.48f; 188 222 … … 194 228 } 195 229 230 /** 231 @brief 232 Calculate the end position the ball will be in. 233 The result of this calculation is stored in this->ballEndPosition_. 234 */ 196 235 void PongAI::calculateBallEndPosition() 197 236 { … … 295 334 } 296 335 336 /** 337 @brief 338 Determine the movement the AI will undertake. (Either -1, 0 or 1) 339 The result of this calculation is stored in this->movement_; 340 @param direction 341 The current direction of movement. 342 @param bUseDelay 343 The time by which this move is delayed. (Again, to make the AI less efficient) 344 */ 297 345 void PongAI::move(char direction, bool bUseDelay) 298 346 { … … 321 369 } 322 370 371 /** 372 @brief 373 Is called, when a delayed move takes effect. 374 */ 323 375 void PongAI::delayedMove() 324 376 { -
code/trunk/src/modules/pong/PongAI.h
r5929 r8108 27 27 */ 28 28 29 /** 30 @file PongAI.h 31 @brief Declaration of the PongAI class. 32 @ingroup Pong 33 */ 34 29 35 #ifndef _PongAI_H__ 30 36 #define _PongAI_H__ … … 33 39 34 40 #include <list> 41 35 42 #include "util/Math.h" 36 43 #include "tools/interfaces/Tickable.h" 44 37 45 #include "controllers/Controller.h" 38 46 39 47 namespace orxonox 40 48 { 49 50 /** 51 @brief 52 The PongAI is an artificial intelligence for the @ref orxonox::Pong "Pong" gametype. 53 54 @author 55 Fabian 'x3n' Landau 56 57 @ingroup Pong 58 */ 41 59 class _PongExport PongAI : public Controller, public Tickable 42 60 { 43 61 public: 44 PongAI(BaseObject* creator); 62 PongAI(BaseObject* creator); //!< Constructor. Registers and initializes the object. 45 63 virtual ~PongAI(); 46 64 47 65 void setConfigValues(); 48 66 49 virtual void tick(float dt); 67 virtual void tick(float dt); //!< Implements the behavior of the PongAI (i.e. its intelligence). 50 68 69 /** 70 @brief Set the ball for the AI. 71 @param ball A pointer to the ball. 72 */ 51 73 void setPongBall(PongBall* ball) 52 74 { this->ball_ = ball; } 53 75 54 76 protected: 55 void calculateRandomOffset(); 56 void calculateBallEndPosition(); 57 void move(char direction, bool bUseDelay); 58 void delayedMove(); 77 void calculateRandomOffset(); //!< Calculates the random offset, that accounts for random errors the AI makes in order to be beatable. 78 void calculateBallEndPosition(); //!< Calculate the end position the ball will be in. 79 void move(char direction, bool bUseDelay); //!< Determine the movement the AI will undertake. 80 void delayedMove(); //!< Is called, when a delayed move takes effect. 59 81 60 PongBall* ball_; 61 Vector2 ballDirection_; 62 float ballEndPosition_; 63 float randomOffset_; 64 bool bChangedRandomOffset_; 65 float relHysteresisOffset_; 66 float strength_; 82 PongBall* ball_; //!< A pointer to the ball. 83 Vector2 ballDirection_; //!< Vector to store the (x,z) direction in which the ball is flying. 84 float ballEndPosition_; //!< The calculated end position of the ball. 85 float randomOffset_; //!< A random offset to introduce random errors (weighted by the strength of the AI) into the AI's behavior. 86 bool bChangedRandomOffset_; //!< Helper boolean, to change the random offset more often. 87 float relHysteresisOffset_; //!< A hysteresis offset. 88 float strength_; //!< The strength of the AI. Ranging from 0 to 1. 67 89 68 std::list<std::pair<Timer*, char> > reactionTimers_; 69 char movement_; 70 char oldMove_; 71 bool bOscillationAvoidanceActive_; 90 std::list<std::pair<Timer*, char> > reactionTimers_; //!< A list of reaction timers and the directions that take effect when their timer expires. 91 char movement_; //!< The planned movement. 92 char oldMove_; //!< The previous movement. 93 bool bOscillationAvoidanceActive_; //!< Boolean, to avoid oscillations. 72 94 }; 73 95 } -
code/trunk/src/modules/pong/PongBall.cc
r7886 r8108 27 27 */ 28 28 29 /** 30 @file PongBall.cc 31 @brief Implementation of the PongBall class. 32 */ 33 29 34 #include "PongBall.h" 30 35 31 36 #include "core/CoreIncludes.h" 32 37 #include "core/GameMode.h" 38 33 39 #include "gametypes/Gametype.h" 40 34 41 #include "PongBat.h" 35 42 … … 40 47 const float PongBall::MAX_REL_Z_VELOCITY = 1.5; 41 48 49 /** 50 @brief 51 Constructor. Registers and initializes the object. 52 */ 42 53 PongBall::PongBall(BaseObject* creator) 43 54 : MovableEntity(creator) … … 57 68 } 58 69 70 /** 71 @brief 72 Destructor. 73 */ 59 74 PongBall::~PongBall() 60 75 { … … 68 83 } 69 84 85 /** 86 @brief 87 Register variables to synchronize over the network. 88 */ 70 89 void PongBall::registerVariables() 71 90 { … … 79 98 } 80 99 100 /** 101 @brief 102 Is called every tick. 103 Handles the movement of the ball and its interaction with the boundaries and bats. 104 @param dt 105 The time since the last tick. 106 */ 81 107 void PongBall::tick(float dt) 82 108 { 83 109 SUPER(PongBall, tick, dt); 84 110 111 // Get the current position, velocity and acceleration of the ball. 85 112 Vector3 position = this->getPosition(); 86 113 Vector3 velocity = this->getVelocity(); 87 114 Vector3 acceleration = this->getAcceleration(); 88 115 116 // If the ball has gone over the top or bottom boundary of the playing field (i.e. the ball has hit the top or bottom delimiters). 89 117 if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2) 90 118 { 119 // Its velocity in z-direction is inverted (i.e. it bounces off). 91 120 velocity.z = -velocity.z; 121 // And its position is set as to not overstep the boundary it has just crossed. 92 122 if (position.z > this->fieldHeight_ / 2) 93 123 position.z = this->fieldHeight_ / 2; … … 98 128 } 99 129 130 // If the ball has crossed the left or right boundary of the playing field (i.e. a player has just scored, if the bat isn't there to parry). 100 131 if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2) 101 132 { 102 133 float distance = 0; 103 134 104 if (this->bat_ )135 if (this->bat_ != NULL) // If there are bats. 105 136 { 106 if (position.x > this->fieldWidth_ / 2 && this->bat_[1]) 137 // If the right boundary has been crossed. 138 if (position.x > this->fieldWidth_ / 2 && this->bat_[1] != NULL) 107 139 { 140 // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%) 108 141 distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2); 109 if (fabs(distance) <= 1) 110 { 142 if (fabs(distance) <= 1) // If the bat is there to parry. 143 { 144 // Set the ball to be exactly at the boundary. 111 145 position.x = this->fieldWidth_ / 2; 146 // Invert its velocity in x-direction (i.e. it bounces off). 112 147 velocity.x = -velocity.x; 148 // Adjust the velocity in the z-direction, depending on where the ball hit the bat. 113 149 velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_; 114 150 acceleration = this->bat_[1]->getVelocity() * this->accelerationFactor_ * -1; … … 116 152 this->fireEvent(); 117 153 } 154 // If the left player scores. 118 155 else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_)) 119 156 { … … 125 162 } 126 163 } 127 if (position.x < -this->fieldWidth_ / 2 && this->bat_[0]) 164 // If the left boundary has been crossed. 165 else if (position.x < -this->fieldWidth_ / 2 && this->bat_[0] != NULL) 128 166 { 167 // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%) 129 168 distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2); 130 if (fabs(distance) <= 1) 131 { 169 if (fabs(distance) <= 1) // If the bat is there to parry. 170 { 171 // Set the ball to be exactly at the boundary. 132 172 position.x = -this->fieldWidth_ / 2; 173 // Invert its velocity in x-direction (i.e. it bounces off). 133 174 velocity.x = -velocity.x; 175 // Adjust the velocity in the z-direction, depending on where the ball hit the bat. 134 176 velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_; 135 177 acceleration = this->bat_[0]->getVelocity() * this->accelerationFactor_ * -1; … … 137 179 this->fireEvent(); 138 180 } 181 // If the right player scores. 139 182 else if (GameMode::isMaster() && position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_)) 140 183 { … … 149 192 } 150 193 194 // Set the position, velocity and acceleration of the ball, if they have changed. 151 195 if (acceleration != this->getAcceleration()) 152 196 this->setAcceleration(acceleration); … … 157 201 } 158 202 203 /** 204 @brief 205 Set the speed of the ball (in x-direction). 206 @param speed 207 The speed to be set. 208 */ 159 209 void PongBall::setSpeed(float speed) 160 210 { 161 if (speed != this->speed_) 211 if (speed != this->speed_) // If the speed changes 162 212 { 163 213 this->speed_ = speed; 164 214 215 // Set the speed in the direction of the balls current velocity. 165 216 Vector3 velocity = this->getVelocity(); 166 217 if (velocity.x != 0) 167 218 velocity.x = sgn(velocity.x) * this->speed_; 168 else 219 else // If the balls current velocity is zero, the speed is set in a random direction. 169 220 velocity.x = this->speed_ * sgn(rnd(-1,1)); 170 221 … … 173 224 } 174 225 226 /** 227 @brief 228 Set the bats for the ball. 229 @param bats 230 An array (of size 2) of weak pointers, to be set as the new bats. 231 */ 175 232 void PongBall::setBats(WeakPtr<PongBat>* bats) 176 233 { 177 if (this->bDeleteBats_) 234 if (this->bDeleteBats_) // If there are already some bats, delete them. 178 235 { 179 236 delete[] this->bat_; … … 182 239 183 240 this->bat_ = bats; 241 // Also store their object IDs, for synchronization. 184 242 this->batID_[0] = this->bat_[0]->getObjectID(); 185 243 this->batID_[1] = this->bat_[1]->getObjectID(); 186 244 } 187 245 246 /** 247 @brief 248 Get the bats over the network. 249 */ 188 250 void PongBall::applyBats() 189 251 { 190 if (!this->bat_) 252 // Make space for the bats, if they don't exist, yet. 253 if (this->bat_ == NULL) 191 254 { 192 255 this->bat_ = new WeakPtr<PongBat>[2]; -
code/trunk/src/modules/pong/PongBall.h
r7885 r8108 27 27 */ 28 28 29 /** 30 @file PongBall.h 31 @brief Declaration of the PongBall class. 32 @ingroup Pong 33 */ 34 29 35 #ifndef _PongBall_H__ 30 36 #define _PongBall_H__ … … 33 39 34 40 #include "util/Math.h" 41 35 42 #include "worldentities/MovableEntity.h" 36 43 37 44 namespace orxonox 38 45 { 46 47 /** 48 @brief 49 This class manages the ball for @ref orxonox::Pong "Pong". 50 51 It is responsible for both the movement of the ball in the x,z-plane as well as its interaction with the boundaries of the playing field (defined by the @ref orxonox::PongCenterpoint "PongCenterpoint") and the @ref orxonox::PongBat "PongBats". Or more precisely, it makes the ball bounce off then upper and lower delimiters of the playing field, it makes the ball bounce off the bats and also detects when a player scores and takes appropriate measures. 52 53 @author 54 Fabian 'x3n' Landau 55 56 @ingroup Pong 57 */ 39 58 class _PongExport PongBall : public MovableEntity 40 59 { … … 45 64 virtual void tick(float dt); 46 65 66 /** 67 @brief Set the dimensions of the playing field. 68 @param width The width of the playing field. 69 @param height The height of the playing field. 70 */ 47 71 void setFieldDimension(float width, float height) 48 72 { this->fieldWidth_ = width; this->fieldHeight_ = height; } 73 /** 74 @brief Get the dimensions of the playing field. 75 @param dimension A vector with the width as the first and height as the second component. 76 */ 49 77 void setFieldDimension(const Vector2& dimension) 50 78 { this->setFieldDimension(dimension.x, dimension.y); } 79 /** 80 @brief Get the dimensions of the playing field. 81 @return Returns a vector with the width as the first and height as the second component. 82 */ 51 83 Vector2 getFieldDimension() const 52 84 { return Vector2(this->fieldWidth_, this->fieldHeight_); } 53 85 54 void setSpeed(float speed); 86 void setSpeed(float speed); //!< Set the speed of the ball (in x-direction). 87 /** 88 @brief Get the speed of the ball (in x-direction). 89 @return Returns the speed of the ball (in x-direction). 90 */ 55 91 float getSpeed() const 56 92 { return this->speed_; } 57 93 94 /** 95 @brief Set the acceleration factor of the ball. 96 @param factor The factor the acceleration of the ball is set to. 97 */ 58 98 void setAccelerationFactor(float factor) 59 99 { this->accelerationFactor_ = factor; } 100 /** 101 @brief Get the acceleration factor of the ball. 102 @return Returns the acceleration factor of the ball. 103 */ 60 104 float getAccelerationFactor() const 61 105 { return this->accelerationFactor_; } 62 106 107 /** 108 @brief Set the length of the bats. 109 @param batlength The length of the bats (in z-direction) as percentage of the height of the playing field. 110 */ 63 111 void setBatLength(float batlength) 64 112 { this->batlength_ = batlength; } 113 /** 114 @brief Get the length of the bats. 115 @return Returns the length of the bats (in z-direction) as percentage of the height of the playing field. 116 */ 65 117 float getBatLength() const 66 118 { return this->batlength_; } 67 119 68 void setBats(WeakPtr<PongBat>* bats); 69 void applyBats(); 120 void setBats(WeakPtr<PongBat>* bats); //!< Set the bats for the ball. 121 void applyBats(); //!< Get the bats over the network. 70 122 71 123 static const float MAX_REL_Z_VELOCITY; … … 74 126 void registerVariables(); 75 127 76 float fieldWidth_; 77 float fieldHeight_; 78 float speed_; 79 float accelerationFactor_; 80 float batlength_; 81 WeakPtr<PongBat>* bat_; 82 bool bDeleteBats_; 83 unsigned int* batID_; 84 float relMercyOffset_; 128 float fieldWidth_; //!< The width of the playing field. 129 float fieldHeight_; //!< The height of the playing field. 130 float speed_; //!< The speed (in x-direction) of the ball. 131 float accelerationFactor_; //!< The acceleration factor of the ball. 132 float batlength_; //!< The length of the bats (in z-direction) as percentage of the height of the playing field. 133 WeakPtr<PongBat>* bat_; //!< An array with the two bats. 134 bool bDeleteBats_; //!< Bool, to keep track, of whether this->bat_ exists or not. 135 unsigned int* batID_; //!< The object IDs of the bats, to be able to synchronize them over the network. 136 float relMercyOffset_; //!< Offset, that makes the player not loose, when, in all fairness, he would have. 85 137 }; 86 138 } -
code/trunk/src/modules/pong/PongBat.cc
r5781 r8108 27 27 */ 28 28 29 /** 30 @file PongBat.cc 31 @brief Implementation of the PongBat class. 32 */ 33 29 34 #include "PongBat.h" 30 35 … … 36 41 CreateFactory(PongBat); 37 42 43 /** 44 @brief 45 Constructor. Registers and initializes the object. 46 */ 38 47 PongBat::PongBat(BaseObject* creator) : ControllableEntity(creator) 39 48 { … … 50 59 } 51 60 61 /** 62 @brief 63 Registers variables to be synchronized over the network. 64 */ 52 65 void PongBat::registerVariables() 53 66 { … … 57 70 } 58 71 72 /** 73 @brief 74 Is called each tick. 75 Moves the bat. 76 @param dt 77 The time since last tick. 78 */ 59 79 void PongBat::tick(float dt) 60 80 { 81 // If the bat is controlled (but not over the network). 61 82 if (this->hasLocalController()) 62 83 { 63 84 if (this->movement_ != 0) 64 85 { 86 // The absolute value of the movement is restricted to be lesser or equal than the speed of the bat. 65 87 this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_; 66 88 89 // If moveRightLeft() is used the movement is dependento on wehther it is the right or the left bat, so, it is i.e. dependent on the orientation of the bat. 67 90 if (this->bMoveLocal_) 68 91 this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0)); … … 73 96 this->bSteadiedPosition_ = false; 74 97 } 98 // If there is no movement but the position has not been steadied, the velocity is set to zero and the position is reaffirmed. 75 99 else if (!this->bSteadiedPosition_) 76 100 { … … 84 108 SUPER(PongBat, tick, dt); 85 109 110 // Restrict the position of the bats, for them to always be between the upper and lower delimiters. i.e. the bats stall if they reach the upper or lower boundary. 86 111 Vector3 position = this->getPosition(); 87 112 if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2) … … 96 121 } 97 122 123 /** 124 @brief 125 Overloaded the function to steer the bat up and down. 126 @param value 127 A vector whose first component is the inverse direction in which we want to steer the bat. 128 */ 98 129 void PongBat::moveFrontBack(const Vector2& value) 99 130 { … … 102 133 } 103 134 135 /** 136 @brief 137 Overloaded the function to steer the bat up and down. 138 @param value 139 A vector whose first component is the direction in which we wnat to steer the bat. 140 */ 104 141 void PongBat::moveRightLeft(const Vector2& value) 105 142 { … … 108 145 } 109 146 147 /** 148 @brief 149 Is called when the player changed. 150 */ 110 151 void PongBat::changedPlayer() 111 152 { -
code/trunk/src/modules/pong/PongBat.h
r7163 r8108 27 27 */ 28 28 29 /** 30 @file PongBat.h 31 @brief Declaration of the PongBat class. 32 @ingroup Pong 33 */ 34 29 35 #ifndef _PongBat_H__ 30 36 #define _PongBat_H__ 31 37 32 38 #include "pong/PongPrereqs.h" 39 33 40 #include "worldentities/ControllableEntity.h" 34 41 35 42 namespace orxonox 36 43 { 44 45 /** 46 @brief 47 The PongBat class manages the bats for @ref orxonox::Pong "Pong", which are the elements controlled by the players. 48 49 It is responsible for the movement (controlled by the players) of the bat. 50 51 @author 52 Fabian 'x3n' Landau 53 54 @ingroup Pong 55 */ 37 56 class _PongExport PongBat : public ControllableEntity 38 57 { 39 58 public: 40 PongBat(BaseObject* creator); 59 PongBat(BaseObject* creator); //!< Constructor. Registers and initializes the object. 41 60 virtual ~PongBat() {} 42 61 43 62 virtual void tick(float dt); 44 63 45 virtual void moveFrontBack(const Vector2& value); 46 virtual void moveRightLeft(const Vector2& value); 64 virtual void moveFrontBack(const Vector2& value); //!< Overloaded the function to steer the bat up and down. 65 virtual void moveRightLeft(const Vector2& value); //!< Overloaded the function to steer the bat up and down. 47 66 48 virtual void changedPlayer(); 67 virtual void changedPlayer(); //!< Is called when the player changed. 49 68 69 /** 70 @brief Set the speed of the bat. 71 @param speed The speed to be set. 72 */ 50 73 void setSpeed(float speed) 51 74 { this->speed_ = speed; } 75 /** 76 @brief Get the speed of the bat. 77 @return Returns the speed of the bat. 78 */ 52 79 float getSpeed() const 53 80 { return this->speed_; } 54 81 82 /** 83 @brief Set the height of the playing field. 84 @param height The height of the playing field. 85 */ 55 86 void setFieldHeight(float height) 56 87 { this->fieldHeight_ = height; } 88 /** 89 @brief Get the height of the playing field. 90 @return Returns the height of the playing field. 91 */ 57 92 float getFieldHeight() const 58 93 { return this->fieldHeight_; } 59 94 95 /** 96 @brief Set the length of the bat. 97 @param length The length of the bat (in z-direction) as percentage of the height of the playing field. 98 */ 60 99 void setLength(float length) 61 100 { this->length_ = length; } 101 /** 102 @brief get the length of the bat. 103 @return Returns the length of the bat (in z-direction) as percentage of the height of the playing field. 104 */ 62 105 float getLength() const 63 106 { return this->length_; } 64 107 65 108 private: 66 void registerVariables(); 109 void registerVariables(); //!< Registers variables to be synchronized over the network. 67 110 68 float movement_; 69 bool bMoveLocal_; 70 float speed_; 71 float length_; 72 float fieldHeight_; 73 bool bSteadiedPosition_; 111 float movement_; //!< The amount (and direction), in z-direction, of movement of the bat. 112 bool bMoveLocal_; //!< Helper to know whether the movement is caused by moveFrontBack() or moveRightLeft(). 113 float speed_; //!< The movement speed of the bat. 114 float length_; //!< The length of the bat (in z-direction) as percentage of the height of the playing field. 115 float fieldHeight_; //!< The height of the playing field. 116 bool bSteadiedPosition_; //!< Helper boolean, to keep track of when to steady the position, to ensure network synchronicity. 74 117 }; 75 118 } -
code/trunk/src/modules/pong/PongBot.cc
r5781 r8108 27 27 */ 28 28 29 /** 30 @file PongBot.cc 31 @brief Implementation of the PongBot class. 32 */ 33 29 34 #include "PongBot.h" 30 35 … … 36 41 CreateFactory(PongBot); 37 42 43 /** 44 @brief 45 Constructor. Registers the object and creates a PongAI controller. 46 */ 38 47 PongBot::PongBot(BaseObject* creator) : Bot(creator) 39 48 { -
code/trunk/src/modules/pong/PongBot.h
r5781 r8108 27 27 */ 28 28 29 /** 30 @file PongBot.h 31 @brief Declaration of the PongBot class. 32 @ingroup Pong 33 */ 34 29 35 #ifndef _PongBot_H__ 30 36 #define _PongBot_H__ … … 35 41 namespace orxonox 36 42 { 43 44 /** 45 @brief 46 A bot especially for @ref orxonox::Pong "Pong". 47 48 Uses the @ref orxonox::PongAI "PongAI". 49 50 @author 51 Fabian 'x3n' Landau 52 53 @ingroup Pong 54 */ 37 55 class _PongExport PongBot : public Bot 38 56 { -
code/trunk/src/modules/pong/PongCenterpoint.cc
r5929 r8108 27 27 */ 28 28 29 /** 30 @file PongCenterpoint.cc 31 @brief Implementation of the PongCenterpoint class. 32 */ 33 29 34 #include "PongCenterpoint.h" 30 35 31 36 #include "core/CoreIncludes.h" 32 37 #include "core/XMLPort.h" 38 33 39 #include "Pong.h" 34 40 … … 37 43 CreateFactory(PongCenterpoint); 38 44 45 /** 46 @brief 47 Constructor. Registers and initializes the object and checks whether the gametype is actually Pong. 48 */ 39 49 PongCenterpoint::PongCenterpoint(BaseObject* creator) : StaticEntity(creator) 40 50 { … … 51 61 } 52 62 63 /** 64 @brief 65 Method to create a PongCenterpoint through XML. 66 */ 53 67 void PongCenterpoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) 54 68 { … … 64 78 } 65 79 80 /** 81 @brief 82 Is called when the gametype has changed. 83 */ 66 84 void PongCenterpoint::changedGametype() 67 85 { 68 86 SUPER(PongCenterpoint, changedGametype); 69 87 88 // Check, whether it's still Pong. 70 89 this->checkGametype(); 71 90 } 72 91 92 /** 93 @brief 94 Checks whether the gametype is Pong and if it is, sets its centerpoint. 95 */ 73 96 void PongCenterpoint::checkGametype() 74 97 { 75 if (this->getGametype() && this->getGametype()->isA(Class(Pong)))98 if (this->getGametype() != NULL && this->getGametype()->isA(Class(Pong))) 76 99 { 77 Pong* pong _gametype = orxonox_cast<Pong*>(this->getGametype().get());78 pong _gametype->setCenterpoint(this);100 Pong* pongGametype = orxonox_cast<Pong*>(this->getGametype().get()); 101 pongGametype->setCenterpoint(this); 79 102 } 80 103 } -
code/trunk/src/modules/pong/PongCenterpoint.h
r5929 r8108 27 27 */ 28 28 29 /** 30 @file PongCenterpoint.h 31 @brief Declaration of the PongCenterpoint class. 32 @ingroup Pong 33 */ 34 29 35 #ifndef _PongCenterpoint_H__ 30 36 #define _PongCenterpoint_H__ … … 33 39 34 40 #include <string> 41 35 42 #include <util/Math.h> 43 36 44 #include "worldentities/StaticEntity.h" 37 45 38 46 namespace orxonox 39 47 { 48 49 /** 50 @brief 51 The PongCenterpoint implements the playing field @ref orxonox::Pong "Pong" takes place in and allows for many parameters of the minigame to be set. 52 The playing field resides in the x,z-plane, with the x-axis being the horizontal axis and the z-axis being the vertical axis. 53 54 Various parameters can be set: 55 - The <b>dimension</b> is a vector, that defines the width and height of the playing field. The default is <em>(200, 120)</em>. 56 - The <b>balltemplate</b> is a template that is applied to the @ref orxonox::PongBall "PongBall", it can be used to attach different things to it, e.g. its @ref orxonox::Model "Model". See below for a usage example. 57 - The <b>battemplate</b> is a template that is applied to the @ref orxonox::PongBall "PongBat", it can be used to attach different things to it, e.g. its @ref orxonox::Model "Model". See below for a usage example. 58 - The <b>ballspeed</b> is the speed with which the @ref orxonox::PongBall "PongBall" moves. The default is <em>100</em>. 59 - The <b>ballaccfactor</b> is the acceleration factor for the @ref orxonox::PongBall "PongBall". The default is <em>1.0</em>. 60 - The <b>batspeed</b> is the speed with which the @ref orxonox::PongBat "PongBats" move. The default is <em>60</em>. 61 - The <b>batlength</b> is the length of the @ref orxonox::PongBat "PongBats" as the percentage of the height of the playing field. The default is <em>0.25</em>. 62 63 An example in XML of the PongCenterpoint would be: 64 65 First the needed templates: 66 The template for the @ref orxonox::PongBall "PongBall". 67 @code 68 <Template name="pongball"> 69 <PongBall> 70 <attached> 71 <Model mesh="sphere.mesh" scale="2" /> 72 <ParticleSpawner name="hiteffect" position="0,0,0" source="Orxonox/sparks2" lifetime="0.01" autostart="0" mainstate="spawn" /> 73 </attached> 74 <eventlisteners> 75 <EventTarget target="hiteffect" /> 76 </eventlisteners> 77 </PongBall> 78 </Template> 79 @endcode 80 As can be seen, a sphere is attached as the @ref orxonox::Model "Model" for the @ref orxonox::PongBall "PongBall", and also an @ref orxonox::EventListener "EventListener" that triggers a @ref orxonox::ParticleSpawner "ParticleSpawner", whenever the ball hits the boundaries is attached. 81 82 Additionally the template for the @ref orxonox::PongBat "PongBat". 83 @code 84 <Template name="pongbatcameras" defaults="0"> 85 <PongBat> 86 <camerapositions> 87 <CameraPosition position="0,200,0" pitch="-90" absolute="true" /> 88 </camerapositions> 89 </PongBat> 90 </Template> 91 92 <Template name="pongbat"> 93 <PongBat camerapositiontemplate=pongbatcameras> 94 <attached> 95 <Model position="0,0,3" mesh="cube.mesh" scale3D="14,2,2" /> 96 </attached> 97 </PongBat> 98 </Template> 99 @endcode 100 As can be seen, there are actually two templates. The first template is needed to set the camera for the @ref orxonox::PongBat "PongBat". The second template ist the actual template for the @ref orxonox::PongBat "PongBat", the template for the camera position is added and a @ref orxonox::Model "Model" for the @ref orxonox::PongBat "PongBat" is attached. 101 102 Finally the PongCenterpoint is created. 103 @code 104 <PongCenterpoint name="pongcenter" dimension="200,120" balltemplate="pongball" battemplate="pongbat" ballspeed="200" ballaccfactor="1.0" batspeed="130" batlength="0.25"> 105 <attached> 106 <Model position="0,0,60" mesh="cube.mesh" scale3D="105,1,1" /> 107 <Model position="0,0,-60" mesh="cube.mesh" scale3D="105,1,1" /> 108 </attached> 109 </PongCenterpoint> 110 @endcode 111 All parameters are specified. And also two @ref orxonox::Model "Models" (for the upper and lower boundary) are attached. 112 113 For a more elaborate example, have a look at the <code>pong.oxw</code> level file. 114 115 @author 116 Fabian 'x3n' Landau 117 118 @ingroup Pong 119 */ 40 120 class _PongExport PongCenterpoint : public StaticEntity 41 121 { 42 122 public: 43 PongCenterpoint(BaseObject* creator); 123 PongCenterpoint(BaseObject* creator); //!< Constructor. Registers and initializes the object and checks whether the gametype is actually Pong. 44 124 virtual ~PongCenterpoint() {} 45 125 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 48 virtual void changedGametype(); 49 126 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method to create a PongCenterpoint through XML. 127 128 virtual void changedGametype(); //!< Is called when the gametype has changed. 129 130 /** 131 @brief Set the template for the ball. (e.g. to attach the model of the ball, but also to attach an EventListener to it to detect, when it hits the boundaries, and e.g. display some ParticleEffets, when it does.) 132 @param balltemplate The name of the template to be set. 133 */ 50 134 void setBalltemplate(const std::string& balltemplate) 51 135 { this->balltemplate_ = balltemplate; } 136 /** 137 @brief Get the template of the ball. 138 @return Returns the name of the template of the ball. 139 */ 52 140 const std::string& getBalltemplate() const 53 141 { return this->balltemplate_; } 54 142 143 /** 144 @brief Set the template for the bats. (e.g. to attach the model of the bat, but also to attach CameraPositions to it, to be able to view the game from the bats perspective) 145 @param battemplate The name of the template to be set. 146 */ 55 147 void setBattemplate(const std::string& battemplate) 56 148 { this->battemplate_ = battemplate; } 149 /** 150 @brief Get the template of the bats. 151 @return Returns the name of the template of the bats. 152 */ 57 153 const std::string& getBattemplate() const 58 154 { return this->battemplate_; } 59 155 156 /** 157 @brief Set the dimensions of the playing field. 158 @param dimension A vector with the width of the playing field as first component and the height as second. 159 */ 60 160 void setFieldDimension(const Vector2& dimension) 61 161 { this->width_ = dimension.x; this->height_ = dimension.y; } 162 /** 163 @brief Get the dimensions of the playing field. 164 @return Returns a vector with the width of the playing field as first component and the height as second. 165 */ 62 166 Vector2 getFieldDimension() const 63 167 { return Vector2(this->width_, this->height_); } 64 168 169 /** 170 @brief Set the speed of the ball. 171 @param ballspeed The speed of the ball. 172 */ 65 173 void setBallSpeed(float ballspeed) 66 174 { this->ballspeed_ = ballspeed; } 175 /** 176 @brief Get the speed of the ball. 177 @return Returns the speed of the ball. 178 */ 67 179 float getBallSpeed() const 68 180 { return this->ballspeed_; } 69 181 182 /** 183 @brief Set the ball's acceleration factor. 184 @param ballaccfactor The ball's acceleration factor. 185 */ 70 186 void setBallAccelerationFactor(float ballaccfactor) 71 187 { this->ballaccfactor_ = ballaccfactor; } 188 /** 189 @brief Get the ball's acceleration factor 190 @return Returns the ball's acceleration factor. 191 */ 72 192 float getBallAccelerationFactor() const 73 193 { return this->ballaccfactor_; } 74 194 195 /** 196 @brief Set the speed of the bats. 197 @param batspeed The speed of the bats. 198 */ 75 199 void setBatSpeed(float batspeed) 76 200 { this->batspeed_ = batspeed; } 201 /** 202 @brief Get the speed of the bats. 203 @return Returns the speed of the bats. 204 */ 77 205 float getBatSpeed() const 78 206 { return this->batspeed_; } 79 207 208 /** 209 @brief Set the length of the bats. 210 @param batlength The length of the bats (in z-direction) as a percentage of the height of the playing field. 211 */ 80 212 void setBatLength(float batlength) 81 213 { this->batlength_ = batlength; } 214 /** 215 @brief Get the length of the bats. 216 @return Returns the length of the bats (in z-direction) as a percentage of the height of the playing field. 217 */ 82 218 float getBatLength() const 83 219 { return this->batlength_; } 84 220 85 221 private: 86 void checkGametype(); 87 88 std::string balltemplate_; 89 std::string battemplate_; 90 91 float ballspeed_; 92 float ballaccfactor_; 93 float batspeed_; 94 float batlength_; 95 96 float width_; 97 float height_; 222 void checkGametype(); //!< Checks whether the gametype is Pong and if it is, sets its centerpoint. 223 224 std::string balltemplate_; //!< The template for the ball. 225 std::string battemplate_; //!< The template for the bats. 226 227 float ballspeed_; //!< The speed of then ball. 228 float ballaccfactor_; //!< The acceleration factor of the ball. 229 float batspeed_; //!< The speed of the bat. 230 float batlength_; //!< The length of the bat (in z-direction) as a percentage of the height of the playing field. 231 232 float width_; //!< The height of the playing field. 233 float height_; //!< The width of the playing field. 98 234 }; 99 235 } -
code/trunk/src/modules/pong/PongScore.cc
r6417 r8108 27 27 */ 28 28 29 /** 30 @file PongScore.cc 31 @brief Implementation of the PongScore class. 32 */ 33 29 34 #include "PongScore.h" 30 35 31 #include "util/Convert.h"32 36 #include "core/CoreIncludes.h" 33 37 #include "core/XMLPort.h" 38 #include "util/Convert.h" 39 40 #include "infos/PlayerInfo.h" 41 34 42 #include "Pong.h" 35 #include "infos/PlayerInfo.h"36 43 37 44 namespace orxonox … … 39 46 CreateFactory(PongScore); 40 47 48 /** 49 @brief 50 Constructor. Registers and initializes the object. 51 */ 41 52 PongScore::PongScore(BaseObject* creator) : OverlayText(creator) 42 53 { … … 51 62 } 52 63 64 /** 65 @brief 66 Destructor. 67 */ 53 68 PongScore::~PongScore() 54 69 { 55 70 } 56 71 72 /** 73 @brief 74 Method to create a PongScore through XML. 75 */ 57 76 void PongScore::XMLPort(Element& xmlelement, XMLPort::Mode mode) 58 77 { … … 65 84 } 66 85 86 /** 87 @brief 88 Is called each tick. 89 Creates and sets the caption to be displayed by the PongScore. 90 @param dt 91 The time that has elapsed since the last tick. 92 */ 67 93 void PongScore::tick(float dt) 68 94 { 69 95 SUPER(PongScore, tick, dt); 70 96 71 if (this->owner_) 97 // If the owner is set. The owner being a Pong game. 98 if (this->owner_ != NULL) 72 99 { 100 // Get the two players. 73 101 PlayerInfo* player1 = this->owner_->getLeftPlayer(); 74 102 PlayerInfo* player2 = this->owner_->getRightPlayer(); … … 80 108 std::string score2("0"); 81 109 82 if (player1) 110 // Save the name and score of each player as a string. 111 if (player1 != NULL) 83 112 { 84 113 name1 = player1->getName(); 85 114 score1 = multi_cast<std::string>(this->owner_->getScore(player1)); 86 115 } 87 88 if (player2) 116 if (player2 != NULL) 89 117 { 90 118 name2 = player2->getName(); … … 92 120 } 93 121 122 // Assemble the strings, depending on what should all be displayed. 94 123 std::string output1; 95 124 if (this->bShowLeftPlayer_) 96 125 { 97 if (this->bShowName_ && this->bShowScore_ && player1 )126 if (this->bShowName_ && this->bShowScore_ && player1 != NULL) 98 127 output1 = name1 + " - " + score1; 99 128 else if (this->bShowScore_) … … 106 135 if (this->bShowRightPlayer_) 107 136 { 108 if (this->bShowName_ && this->bShowScore_ && player2 )137 if (this->bShowName_ && this->bShowScore_ && player2 != NULL) 109 138 output2 = score2 + " - " + name2; 110 139 else if (this->bShowScore_) … … 127 156 } 128 157 129 158 /** 159 @brief 160 Is called when the owner changes. 161 Sets the owner to NULL, if it is not a pointer to a Pong game. 162 */ 130 163 void PongScore::changedOwner() 131 164 { 132 165 SUPER(PongScore, changedOwner); 133 166 134 if (this->getOwner() && this->getOwner()->getGametype())167 if (this->getOwner() != NULL && this->getOwner()->getGametype()) 135 168 this->owner_ = orxonox_cast<Pong*>(this->getOwner()->getGametype().get()); 136 169 else -
code/trunk/src/modules/pong/PongScore.h
r5781 r8108 27 27 */ 28 28 29 /** 30 @file PongScore.h 31 @brief Declaration of the PongScore class. 32 @ingroup Pong 33 */ 34 29 35 #ifndef _PongScore_H__ 30 36 #define _PongScore_H__ … … 33 39 34 40 #include "tools/interfaces/Tickable.h" 41 35 42 #include "overlays/OverlayText.h" 36 43 37 44 namespace orxonox 38 45 { 46 47 /** 48 @brief 49 The PongScore class displays the score for a game of @ref orxonox::Pong "Pong". 50 51 @author 52 Fabian 'x3n' Landau 53 54 @ingroup Pong 55 */ 39 56 class _PongExport PongScore : public OverlayText, public Tickable 40 57 { … … 43 60 virtual ~PongScore(); 44 61 45 virtual void tick(float dt); 62 virtual void tick(float dt); //!< Creates and sets the caption to be displayed by the PongScore. 46 63 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 virtual void changedOwner(); 64 virtual void changedOwner(); //!< Is called when the owner changes. 48 65 66 /** 67 @brief Set whether the PongScore displays the players' names. 68 @param value If true the players' names are displayed. 69 */ 49 70 inline void setShowName(bool value) 50 71 { this->bShowName_ = value; } 72 /** 73 @brief Get whether the PongScore displays the players' names. 74 @return Returns true if the players' names are displayed, false otherwise. 75 */ 51 76 inline bool getShowName() const 52 77 { return this->bShowName_; } 53 78 79 /** 80 @brief Set whether the PongScore displays the players' scores. 81 @param value If true the players' scores are displayed. 82 */ 54 83 inline void setShowScore(bool value) 55 84 { this->bShowScore_ = value; } 85 /** 86 @brief Get whether the PongScore displays the players' scores. 87 @return Returns true if the players' scores are displayed, false otherwise. 88 */ 56 89 inline bool getShowScore() const 57 90 { return this->bShowScore_; } 58 91 92 /** 93 @brief Set whether the PongScore displays the left player. 94 @param value If true the left player is displayed. 95 */ 59 96 inline void setShowLeftPlayer(bool value) 60 97 { this->bShowLeftPlayer_ = value; } 98 /** 99 @brief Get whether the PongScore displays the left player. 100 @return Returns true if the left player is displayed, false otherwise. 101 */ 61 102 inline bool getShowLeftPlayer() const 62 103 { return this->bShowLeftPlayer_; } 63 104 105 /** 106 @brief Set whether the PongScore displays the right player. 107 @param value If true the right player is displayed. 108 */ 64 109 inline void setShowRightPlayer(bool value) 65 110 { this->bShowRightPlayer_ = value; } 111 /** 112 @brief Get whether the PongScore displays the right player. 113 @return Returns true if the right player is displayed, false otherwise. 114 */ 66 115 inline bool getShowRightPlayer() const 67 116 { return this->bShowRightPlayer_; } 68 117 69 118 private: 70 Pong* owner_; 71 bool bShowName_; 72 bool bShowScore_; 73 bool bShowLeftPlayer_; 74 bool bShowRightPlayer_; 119 Pong* owner_; //!< The Pong game that owns this PongScore. 120 bool bShowName_; //!< Whether the names of the players are shown. 121 bool bShowScore_; //!< Whether the score of the players is shown. 122 bool bShowLeftPlayer_; //!< Whether the left player is shown. 123 bool bShowRightPlayer_; //!< Whether the right player is shown. 75 124 }; 76 125 }
Note: See TracChangeset
for help on using the changeset viewer.