Changeset 10040 for code/branches/pickupsFS14/src/modules/jump/Jump.cc
- Timestamp:
- Apr 17, 2014, 4:29:25 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickupsFS14/src/modules/jump/Jump.cc
r10032 r10040 21 21 * 22 22 * Author: 23 * F lorian Zinggeler23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 25 * ... … … 33 33 34 34 #include "Jump.h" 35 35 36 #include "core/CoreIncludes.h" 36 37 #include "core/EventIncludes.h" … … 41 42 #include "chat/ChatManager.h" 42 43 43 // ! HACK 44 #include "JumpCenterpoint.h" 45 #include "JumpPlatform.h" 46 #include "JumpFigure.h" 47 44 48 #include "infos/PlayerInfo.h" 45 46 #include "JumpCenterPoint.h"47 #include "JumpShip.h"48 /*49 #include "JumpEnemy.h"50 #include "JumpEnemyShooter.h"*/51 52 #include "core/command/ConsoleCommand.h"53 #include "worldentities/BigExplosion.h"54 49 55 50 namespace orxonox 56 51 { 52 // Events to allow to react to scoring of a player, in the level-file. 53 CreateEventName(JumpCenterpoint, right); 54 CreateEventName(JumpCenterpoint, left); 55 57 56 RegisterUnloadableClass(Jump); 58 57 58 /** 59 @brief 60 Constructor. Registers and initializes the object. 61 */ 59 62 Jump::Jump(Context* context) : Deathmatch(context) 60 63 { 61 64 RegisterObject(Jump); 62 platformList.clear(); 63 yScreenPosition= 0;64 screenShiftSinceLastUpdate= 0;65 66 //this->numberOfBots_ = 0; //sets number of default bots temporarly to 067 //this->center_ = 0; 65 66 this->center_ = 0; 67 this->ball_ = 0; 68 this->figure_ = 0; 69 this->camera = 0; 70 68 71 //this->setHUDTemplate("JumpHUD"); 69 72 70 71 } 72 73 74 /*void Jump::levelUp() 75 { 76 level++; 77 if (getPlayer() != NULL) 78 { 79 for (int i = 0; i < 7; i++) 73 // Pre-set the timer, but don't start it yet. 74 this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Jump::startBall, this))); 75 this->starttimer_.stopTimer(); 76 77 78 this->scoreLimit_ = 10; 79 this->setConfigValues(); 80 } 81 82 /** 83 @brief 84 Destructor. Cleans up, if initialized. 85 */ 86 Jump::~Jump() 87 { 88 if (this->isInitialized()) 89 { 90 this->cleanup(); 91 } 92 } 93 94 void Jump::tick(float dt) 95 { 96 SUPER(Jump, tick, dt); 97 98 if (figure_ != NULL) 99 { 100 Vector3 figurePosition = figure_->getPosition(); 101 102 if (figurePosition.z > totalScreenShift) 103 { 104 totalScreenShift = figurePosition.z; 105 } 106 107 if (this->camera != NULL) 108 { 109 Vector3 cameraPosition = Vector3(0,totalScreenShift,0); 110 camera->setPosition(cameraPosition); 111 } 112 else 113 { 114 orxout() << "no camera found" << endl; 115 //this->camera = this->figure_->getCamera(); 116 } 117 } 118 119 120 121 122 123 } 124 125 126 void Jump::setConfigValues() 127 { 128 SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins."); 129 } 130 131 /** 132 @brief 133 Cleans up the Gametype by destroying the ball and the bats. 134 */ 135 void Jump::cleanup() 136 { 137 if (this->ball_ != NULL) // Destroy the ball, if present. 138 { 139 this->ball_->destroy(); 140 this->ball_ = 0; 141 } 142 143 // Destroy both bats, if present. 144 if (this->figure_ != NULL) 145 { 146 this->figure_->destroy(); 147 this->figure_ = 0; 148 } 149 this->camera = 0; 150 } 151 152 /** 153 @brief 154 Starts the Jump minigame. 155 */ 156 void Jump::start() 157 { 158 if (this->center_ != NULL) // There needs to be a JumpCenterpoint, i.e. the area the game takes place. 159 { 160 if (this->ball_ == NULL) // If there is no ball, create a new ball. 80 161 { 81 WeakPtr<BigExplosion> chunk = new BigExplosion(this->center_->getContext()); 82 chunk->setPosition(Vector3(600, 0, 100.f * i - 300)); 83 chunk->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() 84 chunk->setScale(20); 162 this->ball_ = new JumpPlatform(this->center_->getContext()); 163 // Apply the template for the ball specified by the centerpoint. 164 this->ball_->addTemplate(this->center_->getBalltemplate()); 85 165 } 86 } 87 addPoints(multiplier * 42); 88 multiplier *= 2; 89 toggleShowLevel(); 90 showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Jump::toggleShowLevel, this))); 91 }*/ 92 93 WeakPtr<JumpShip> Jump::getPlayer() 94 { 95 if (player == NULL) 96 { 97 for (ObjectList<JumpShip>::iterator it = ObjectList<JumpShip>::begin(); it != ObjectList<JumpShip>::end(); ++it) 98 { 99 player = *it; 100 } 101 } 102 return player; 103 } 104 105 void Jump::tick(float dt) 106 { 107 108 109 if (getPlayer() != NULL) 110 { 111 Vector3 shipPosition = getPlayer()->getPosition(); 112 113 // Bildschirmposition kann nur nach oben verschoben werden 114 if (shipPosition.y > yScreenPosition) 115 { 116 screenShiftSinceLastUpdate += shipPosition.y - yScreenPosition; 117 118 yScreenPosition = shipPosition.y; 119 } 120 121 // Kameraposition nachfuehren 122 if (camera == NULL) 123 { 124 camera = getPlayer()->getCamera(); 125 } 126 if (camera != NULL) 127 { 128 camera->setPosition(Vector3(-shipPosition.x, yScreenPosition-shipPosition.y, 100)); 129 //camera->setOrientation(Vector3::UNIT_Z, Degree(180)); 130 } 131 132 if (screenShiftSinceLastUpdate > 200.0) 133 { 134 screenShiftSinceLastUpdate -= 200.0; 135 orxout() << "new section added" << endl; 136 addPlatform(shipPosition.x, shipPosition.y + 300.0); 137 } 138 139 } 140 141 SUPER(Jump, tick, dt); 142 } 143 144 145 /*void Jump::spawnEnemy() 146 { 147 if (getPlayer() == NULL) 148 return; 149 150 for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++) 151 { 152 WeakPtr<JumpEnemy> newPawn; 153 if (rand() % 42/(1 + level*level) == 0) 154 { 155 newPawn = new JumpEnemyShooter(this->center_->getContext()); 156 newPawn->addTemplate("enemyjumpshooter"); 157 } 158 else 159 { 160 newPawn = new JumpEnemy(this->center_->getContext()); 161 newPawn->addTemplate("enemyjump"); 162 } 163 newPawn->setPlayer(player); 164 newPawn->level = level; 165 // spawn enemy at random points in front of player. 166 newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200)); 167 } 168 }*/ 169 170 /*void Jump::costLife() 171 { 172 lives--; 173 multiplier = 1; 174 // end the game in 30 seconds. 175 if (lives <= 0) 176 enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&Jump::end, this))); 177 };*/ 178 179 /*void Jump::comboControll() 180 { 181 if (b_combo) 182 multiplier++; 183 // if no combo was performed before, reset multiplier 184 else 185 multiplier = 1; 186 b_combo = false; 187 }*/ 188 189 190 void Jump::start() 191 { 192 // Call start for the parent class. 193 Deathmatch::start(); 194 195 /* 196 // Set variable to temporarily force the player to spawn. 197 this->bForceSpawn_ = true; 198 199 if (this->center_ == NULL) // abandon mission! 166 167 // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to. 168 this->center_->attach(this->ball_); 169 this->ball_->setPosition(0, 0, 0); 170 this->ball_->setFieldDimension(this->center_->getFieldDimension()); 171 172 // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint. 173 if (this->figure_ == NULL) 174 { 175 this->figure_ = new JumpFigure(this->center_->getContext()); 176 this->figure_->addTemplate(this->center_->getBattemplate()); 177 } 178 179 // Attach the bats to the centerpoint and set the parameters as specified in the centerpoint, the bats are attached to. 180 this->center_->attach(this->figure_); 181 this->figure_->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0); 182 this->figure_->yaw(Degree(-90)); 183 this->figure_->setSpeed(this->center_->getBatSpeed()); 184 this->figure_->setFieldDimension(this->center_->getFieldDimension()); 185 this->figure_->setLength(this->center_->getBatLength()); 186 187 // Set the bats for the ball. 188 this->ball_->setFigure(this->figure_); 189 } 190 else // If no centerpoint was specified, an error is thrown and the level is exited. 200 191 { 201 192 orxout(internal_error) << "Jump: No Centerpoint specified." << endl; … … 203 194 return; 204 195 } 196 197 // Start the timer. After it has expired the ball is started. 198 this->starttimer_.startTimer(); 199 200 // Set variable to temporarily force the player to spawn. 201 bool temp = this->bForceSpawn_; 202 this->bForceSpawn_ = true; 203 204 // Call start for the parent class. 205 Deathmatch::start(); 206 207 // Reset the variable. 208 this->bForceSpawn_ = temp; 209 210 if (this->figure_ != NULL) 211 { 212 this->camera = this->figure_->getCamera(); 213 } 214 215 totalScreenShift = 0.0; 216 } 217 218 /** 219 @brief 220 Ends the Jump minigame. 221 */ 222 void Jump::end() 223 { 224 this->cleanup(); 225 226 // Call end for the parent class. 227 Deathmatch::end(); 228 } 229 230 /** 231 @brief 232 Spawns players, and fills the rest up with bots. 233 */ 234 void Jump::spawnPlayersIfRequested() 235 { 236 237 // first spawn human players to assign always the left bat to the player in singleplayer 238 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 239 if (it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_)) 240 this->spawnPlayer(it->first); 241 // now spawn bots 242 /* 243 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 244 if (!it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_)) 245 this->spawnPlayer(it->first); 205 246 */ 206 207 //addPlatform(0,0); 208 209 } 210 211 212 /*void Jump::addPoints(int numPoints) 213 { 214 if (!bEndGame) 215 { 216 point += numPoints * multiplier; 217 b_combo = true; 218 } 219 }*/ 220 221 /*void Jump::end() 222 { 223 // DON'T CALL THIS! 224 // Deathmatch::end(); 225 // It will misteriously crash the game! 226 // Instead startMainMenu, this won't crash. 227 GSLevel::startMainMenu(); 228 }*/ 229 230 void Jump::addPlatform(float xPosition, float yPosition) 231 { 232 JumpPlatform* newPlatform = new JumpPlatform(center_->getContext()); 233 newPlatform->setPosition(Vector3(xPosition, yPosition, 0)); 234 platformList.push_front(newPlatform); 247 } 248 249 /** 250 @brief 251 Spawns the input player. 252 @param player 253 The player to be spawned. 254 */ 255 void Jump::spawnPlayer(PlayerInfo* player) 256 { 257 assert(player); 258 259 // If the first (left) bat has no player. 260 if (this->figure_->getPlayer() == NULL) 261 { 262 player->startControl(this->figure_); 263 this->players_[player].state_ = PlayerState::Alive; 264 } 265 // If both bats are taken. 266 else 267 { 268 return; 269 } 270 271 } 272 273 /** 274 @brief 275 Is called when the player scored. 276 */ 277 void Jump::playerScored(PlayerInfo* player, int score) 278 { 279 /* 280 Deathmatch::playerScored(player, score); 281 if (this->center_ != NULL) // If there is a centerpoint. 282 { 283 // Fire an event for the player that has scored, to be able to react to it in the level, e.g. by displaying fireworks. 284 if (player == this->getRightPlayer()) 285 this->center_->fireEvent(FireEventName(JumpCenterpoint, right)); 286 else if (player == this->getLeftPlayer()) 287 this->center_->fireEvent(FireEventName(JumpCenterpoint, left)); 288 289 // Also announce, that the player has scored. 290 if (player != NULL) 291 this->gtinfo_->sendAnnounceMessage(player->getName() + " scored"); 292 } 293 294 // If there is a ball present, reset its position, velocity and acceleration. 295 if (this->ball_ != NULL) 296 { 297 this->ball_->setPosition(Vector3::ZERO); 298 this->ball_->setVelocity(Vector3::ZERO); 299 this->ball_->setAcceleration(Vector3::ZERO); 300 this->ball_->setSpeed(0); 301 } 302 303 // If there are bats reset them to the middle position. 304 if (this->figure_[0] != NULL && this->figure_[1] != NULL) 305 { 306 this->figure_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0); 307 this->figure_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0); 308 } 309 310 // If a player gets enough points, he won the game -> end of game 311 PlayerInfo* winningPlayer = NULL; 312 if (this->getLeftPlayer() && this->getScore(this->getLeftPlayer()) >= scoreLimit_) 313 winningPlayer = this->getLeftPlayer(); 314 else if (this->getRightPlayer() && this->getScore(this->getRightPlayer()) >= scoreLimit_) 315 winningPlayer = getLeftPlayerthis->getRightPlayer(); 316 317 if (winningPlayer) 318 { 319 ChatManager::message(winningPlayer->getName() + " has won!"); 320 this->end(); 321 } 322 323 // Restart the timer to start the ball. 324 this->starttimer_.startTimer(); 325 326 */ 327 } 328 329 /** 330 @brief 331 Starts the ball with some default speed. 332 */ 333 void Jump::startBall() 334 { 335 336 } 337 338 /** 339 @brief 340 Get the left player. 341 @return 342 Returns a pointer to the player playing on the left. If there is no left player, NULL is returned. 343 */ 344 PlayerInfo* Jump::getPlayer() const 345 { 346 if (this->figure_ != NULL) 347 { 348 return this->figure_->getPlayer(); 349 } 350 else 351 { 352 return 0; 353 } 235 354 } 236 355
Note: See TracChangeset
for help on using the changeset viewer.