Changeset 2839 for code/trunk/src/orxonox/objects
- Timestamp:
- Mar 25, 2009, 3:26:06 AM (16 years ago)
- Location:
- code/trunk/src/orxonox/objects
- Files:
-
- 4 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/objects/controllers/CMakeLists.txt
r2710 r2839 5 5 AIController.cc 6 6 ScriptController.cc 7 PongAI.cc 7 8 ) -
code/trunk/src/orxonox/objects/gametypes/Gametype.cc
r2826 r2839 200 200 // Reward killer 201 201 if (killer) 202 this->playerScored(killer->getPlayer()); 202 { 203 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(killer->getPlayer()); 204 if (it != this->players_.end()) 205 it->second.frags_++; 206 } 203 207 204 208 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator()); … … 348 352 { 349 353 for (unsigned int i = 0; i < amount; ++i) 350 new Bot(this);354 this->botclass_.fabricate(this); 351 355 } 352 356 -
code/trunk/src/orxonox/objects/gametypes/Gametype.h
r2826 r2839 142 142 float initialStartCountdown_; 143 143 unsigned int numberOfBots_; 144 SubclassIdentifier<Bot> botclass_; 144 145 145 146 std::map<PlayerInfo*, Player> players_; -
code/trunk/src/orxonox/objects/gametypes/Pong.cc
r2826 r2839 37 37 #include "objects/worldentities/PongBall.h" 38 38 #include "objects/worldentities/PongBat.h" 39 #include "objects/infos/PlayerInfo.h" 39 #include "objects/infos/HumanPlayer.h" 40 #include "objects/infos/PongBot.h" 41 #include "objects/controllers/PongAI.h" 40 42 41 43 namespace orxonox … … 56 58 this->starttimer_.setTimer(1.0, false, this, createExecutor(createFunctor(&Pong::startBall))); 57 59 this->starttimer_.stopTimer(); 60 61 this->botclass_ = Class(PongBot); 58 62 } 59 63 … … 133 137 this->players_[player].state_ = PlayerState::Alive; 134 138 } 139 else 140 return; 141 142 if (player && player->getController() && player->getController()->isA(Class(PongAI))) 143 { 144 PongAI* ai = dynamic_cast<PongAI*>(player->getController()); 145 ai->setPongBall(this->ball_); 146 } 135 147 } 136 148 -
code/trunk/src/orxonox/objects/infos/CMakeLists.txt
r2710 r2839 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Bot.cc 3 PongBot.cc 3 4 Info.cc 4 5 PlayerInfo.cc -
code/trunk/src/orxonox/objects/infos/PlayerInfo.cc
r2826 r2839 110 110 void PlayerInfo::createController() 111 111 { 112 if (this->controller_) 113 { 114 delete this->controller_; 115 this->controller_ = 0; 116 } 112 117 this->controller_ = this->defaultController_.fabricate(this); 113 118 assert(this->controller_); -
code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc
r2826 r2839 251 251 } 252 252 } 253 254 this->changedPlayer(); 253 255 } 254 256 … … 263 265 this->bHasHumanController_ = false; 264 266 this->setObjectMode(objectDirection::toclient); 267 268 this->changedPlayer(); 265 269 266 270 if (this->bDestroyWhenPlayerLeft_) -
code/trunk/src/orxonox/objects/worldentities/ControllableEntity.h
r2662 r2839 49 49 50 50 virtual void changedGametype(); 51 virtual void changedPlayer() {} 51 52 52 53 virtual void setPlayer(PlayerInfo* player); -
code/trunk/src/orxonox/objects/worldentities/PongBall.cc
r2826 r2839 44 44 this->speed_ = 0; 45 45 this->bat_ = 0; 46 this->relMercyOffset_ = 0.05; 46 47 } 47 48 … … 67 68 if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2) 68 69 { 69 velocity.x = -velocity.x;70 70 float distance = 0; 71 71 72 if ( position.x > this->fieldWidth_ / 2)72 if (this->bat_) 73 73 { 74 position.x = this->fieldWidth_ / 2; 75 if (this->bat_ && this->bat_[1]) 74 if (position.x > this->fieldWidth_ / 2 && this->bat_[1]) 76 75 { 77 distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * this->batlength_/ 2);78 if ( this->getGametype() && this->bat_[0] && fabs(distance) >1)76 distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2); 77 if (fabs(distance) <= 1) 79 78 { 80 this->getGametype()->playerScored(this->bat_[0]->getPlayer()); 81 return; 79 position.x = this->fieldWidth_ / 2; 80 velocity.x = -velocity.x; 81 velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_; 82 } 83 else if (position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_)) 84 { 85 if (this->getGametype() && this->bat_[0]) 86 { 87 this->getGametype()->playerScored(this->bat_[0]->getPlayer()); 88 return; 89 } 90 } 91 } 92 if (position.x < -this->fieldWidth_ / 2 && this->bat_[0]) 93 { 94 distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2); 95 if (fabs(distance) <= 1) 96 { 97 position.x = -this->fieldWidth_ / 2; 98 velocity.x = -velocity.x; 99 velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_; 100 } 101 else if (position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_)) 102 { 103 if (this->getGametype() && this->bat_[1]) 104 { 105 this->getGametype()->playerScored(this->bat_[1]->getPlayer()); 106 return; 107 } 82 108 } 83 109 } 84 110 } 85 if (position.x < -this->fieldWidth_ / 2)86 {87 position.x = -this->fieldWidth_ / 2;88 if (this->bat_ && this->bat_[0])89 {90 distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * this->batlength_ / 2);91 if (this->getGametype() && this->bat_[1] && fabs(distance) > 1)92 {93 this->getGametype()->playerScored(this->bat_[1]->getPlayer());94 return;95 }96 }97 }98 99 velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;100 111 } 101 112 -
code/trunk/src/orxonox/objects/worldentities/PongBall.h
r2826 r2839 48 48 void setFieldDimension(const Vector2& dimension) 49 49 { this->setFieldDimension(dimension.x, dimension.y); } 50 Vector2 getFieldDimension() const 51 { return Vector2(this->fieldWidth_, this->fieldHeight_); } 50 52 51 53 void setSpeed(float speed); … … 67 69 float batlength_; 68 70 PongBat** bat_; 71 float relMercyOffset_; 69 72 }; 70 73 } -
code/trunk/src/orxonox/objects/worldentities/PongBat.cc
r2826 r2839 46 46 this->length_ = 0.25; 47 47 this->fieldHeight_ = 100; 48 this->bSteadiedPosition_ = false; 48 49 49 50 this->registerVariables(); … … 61 62 if (this->hasLocalController()) 62 63 { 63 this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_; 64 if (this->movement_ != 0) 65 { 66 this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_; 64 67 65 if (this->bMoveLocal_)66 this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0));67 else68 this->setVelocity(0, 0, this->movement_);68 if (this->bMoveLocal_) 69 this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0)); 70 else 71 this->setVelocity(0, 0, this->movement_); 69 72 70 this->movement_ = 0; 73 this->movement_ = 0; 74 this->bSteadiedPosition_ = false; 75 } 76 else if (!this->bSteadiedPosition_) 77 { 78 // To ensure network synchronicity 79 this->setVelocity(0, 0, 0); 80 this->setPosition(this->getPosition()); 81 this->bSteadiedPosition_ = true; 82 } 71 83 } 72 84 73 85 SUPER(PongBat, tick, dt); 74 86 75 if (this->hasLocalController()) 76 { 77 Vector3 position = this->getPosition(); 78 79 if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2) 80 position.z = this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2; 81 if (position.z < -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2) 82 position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2; 83 84 if (position != this->getPosition()) 85 this->setPosition(position); 86 } 87 Vector3 position = this->getPosition(); 88 if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2) 89 position.z = this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2; 90 if (position.z < -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2) 91 position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2; 92 if (position != this->getPosition()) 93 this->setPosition(position); 87 94 } 88 95 … … 98 105 this->movement_ = value.x; 99 106 } 107 108 void PongBat::changedPlayer() 109 { 110 this->setVelocity(0, 0, 0); 111 } 100 112 } -
code/trunk/src/orxonox/objects/worldentities/PongBat.h
r2826 r2839 48 48 virtual void moveRightLeft(const Vector2& value); 49 49 50 virtual void changedPlayer(); 51 50 52 void setSpeed(float speed) 51 53 { this->speed_ = speed; } … … 69 71 float length_; 70 72 float fieldHeight_; 73 bool bSteadiedPosition_; 71 74 }; 72 75 }
Note: See TracChangeset
for help on using the changeset viewer.