Changeset 10622 for code/trunk/src/modules/towerdefense
- Timestamp:
- Oct 4, 2015, 3:45:56 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 4 deleted
- 11 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/towerdefense/CMakeLists.txt
r10258 r10622 2 2 TowerDefense.cc 3 3 TowerDefenseTower.cc 4 TowerTurret.cc5 4 TowerDefenseCenterpoint.cc 6 5 TowerDefenseHUDController.cc … … 8 7 TDCoordinate.cc 9 8 TowerDefenseEnemy.cc 10 9 TowerDefenseSelecter.cc 11 10 ) 12 11 … … 17 16 orxonox 18 17 overlays 18 objects 19 19 SOURCE_FILES ${TOWERDEFENSE_SRC_FILES} 20 20 ) -
code/trunk/src/modules/towerdefense/TDCoordinate.cc
r10258 r10622 17 17 { 18 18 //RegisterObject(TDCoordinate); 19 x=0; 20 y=0; 19 Set(0,0); 21 20 22 21 } 23 22 24 23 TDCoordinate::TDCoordinate(int x, int y) 25 { 26 this->x=x; 27 this->y=y; 24 { 25 Set(x,y); 26 } 27 28 void TDCoordinate::Set(int x, int y) 29 { 30 if (x < 0) 31 { 32 _x = 0; 33 } 34 else if (x > 15) 35 { 36 _x = 15; 37 } 38 else 39 { 40 _x = x; 41 } 42 43 if (y < 0) 44 { 45 _y = 0; 46 } 47 else if (y > 15) 48 { 49 _y = 15; 50 } 51 else 52 { 53 _y = y; 54 } 55 } 56 57 int TDCoordinate::GetX() 58 { 59 return _x; 60 } 61 62 int TDCoordinate::GetY() 63 { 64 return _y; 28 65 } 29 66 … … 34 71 35 72 Vector3 *coord = new Vector3(); 36 coord->x= ( x-8) * tileScale;37 coord->y= ( y-8) * tileScale;73 coord->x= (_x-8) * tileScale; 74 coord->y= (_y-8) * tileScale; 38 75 coord->z=100; 39 76 -
code/trunk/src/modules/towerdefense/TDCoordinate.h
r10258 r10622 16 16 { 17 17 public: 18 int x; 19 int y; 18 TDCoordinate(); 19 TDCoordinate(int x, int y); 20 virtual ~TDCoordinate() {}; 21 virtual void Set(int x, int y); 22 virtual int GetX(); 23 virtual int GetY(); 24 virtual Vector3 get3dcoordinate(); 20 25 21 TDCoordinate(); 22 23 Vector3 get3dcoordinate(); 24 25 virtual ~TDCoordinate() {}; 26 27 TDCoordinate(int x, int y); 26 private: 27 int _x; 28 int _y; 28 29 }; 29 30 -
code/trunk/src/modules/towerdefense/TowerDefense.cc
r10258 r10622 37 37 * 38 38 * 39 *40 39 *TIPP: Eclipse hilft euch schnell auf bereits vorhanden Funktionen zuzugreifen: 41 40 * einfach "this->" eingeben und kurz warten. Dann tauch eine Liste mit Vorschlägen auf. Wenn ihr jetzt weiter … … 77 76 #include "TowerDefenseCenterpoint.h" 78 77 //#include "TDCoordinate.h" 79 #include "TowerTurret.h"80 78 #include "worldentities/SpawnPoint.h" 81 79 #include "worldentities/pawns/Pawn.h" … … 88 86 /* Part of a temporary hack to allow the player to add towers */ 89 87 #include "core/command/ConsoleCommand.h" 88 #include <cmath> 89 90 90 91 91 namespace orxonox 92 92 { 93 static const std::string __CC_addTower_name = "addTower"; 94 static const std::string __CC_upgradeTower_name = "upgradeTower"; 95 static const int upgradeCost = 20; 96 static const int towerCost = 20; 97 unsigned int maxspaceships = 30; 98 int maxspaceshipsstandard = 30; 99 100 101 102 SetConsoleCommand("TowerDefense", __CC_addTower_name, &TowerDefense::addTower ).addShortcut().defaultValues(1); 103 SetConsoleCommand("TowerDefense", __CC_upgradeTower_name, &TowerDefense::upgradeTower).addShortcut().defaultValues(0); 104 93 105 RegisterUnloadableClass(TowerDefense); 94 106 95 TowerDefense::TowerDefense(Context* context) : Deathmatch(context)107 TowerDefense::TowerDefense(Context* context) : TeamDeathmatch(context) 96 108 { 97 109 RegisterObject(TowerDefense); … … 103 115 }*/ 104 116 117 //Timer for the waves (10 seconds between the waves) 118 selecter = NULL; 119 this->player_ = NULL; 105 120 this->setHUDTemplate("TowerDefenseHUD"); 106 107 //this->stats_ = new TowerDefensePlayerStats(); 108 109 /* Temporary hack to allow the player to add towers and upgrade them */ 110 this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) ); 111 this->dedicatedUpgradeTower_ = createConsoleCommand( "upgradeTower", createExecutor( createFunctor(&TowerDefense::upgradeTower, this) ) ); 121 this->nextwaveTimer_.setTimer(10, false, createExecutor(createFunctor(&TowerDefense::nextwave, this))); 122 this->nextwaveTimer_.stopTimer(); 123 this->waves_ = 0; 124 this->time = 0; 125 this->credit_ = 0; 126 this->lifes_ = 0; 127 this->timeSetTower_ = 0; 128 spaceships =15; 129 eggs=3; 130 ufos=7; 131 randomships=5; 132 133 134 ModifyConsoleCommand(__CC_addTower_name).setObject(this); 135 ModifyConsoleCommand(__CC_upgradeTower_name).setObject(this); 112 136 } 113 137 … … 117 141 if (this->isInitialized()) 118 142 { 119 if( this->dedicatedAddTower_ )120 delete this->dedicatedAddTower_;143 ModifyConsoleCommand(__CC_addTower_name).setObject(NULL); 144 ModifyConsoleCommand(__CC_upgradeTower_name).setObject(NULL); 121 145 } 122 146 } … … 131 155 void TowerDefense::start() 132 156 { 133 134 Deathmatch::start(); 135 136 // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path 137 for (int i=0; i < 16 ; i++){ 138 for (int j = 0; j< 16 ; j++){ 139 towermatrix[i][j] = false; 157 if (center_ != NULL) // There needs to be a TowerDefenseCenterpoint, i.e. the area the game takes place. 158 { 159 if (selecter == NULL) 160 { 161 selecter = new TowerDefenseSelecter(this->center_->getContext()); 140 162 } 141 } 142 163 selecter->addTemplate(center_->getSelecterTemplate()); 164 center_->attach(selecter); 165 } 166 else // If no centerpoint was specified, an error is thrown and the level is exited. 167 { 168 orxout(internal_error) << "Jump: No Centerpoint specified." << endl; 169 return; 170 } 171 172 TeamDeathmatch::start(); 173 174 // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path 175 for (int i=0; i < 16 ; i++) 176 { 177 for (int j = 0; j< 16 ; j++) 178 { 179 towerModelMatrix[i][j] = NULL; 180 towerTurretMatrix[i][j] = NULL; 181 } 182 } 183 184 185 186 if (player_ != NULL) 187 { 188 //this->player_->startControl(selecter); 189 } 190 else 191 { 192 orxout() << "player=NULL" << endl; 193 } 194 195 196 Model* dummyModel = new Model(this->center_->getContext()); 197 198 //the path of the spacehips has to be blocked, so that no towers can be build there 143 199 for (int k=0; k<3; k++) 144 tower matrix[1][k]=true;200 towerModelMatrix[1][k]=dummyModel; 145 201 for (int l=1; l<11; l++) 146 towermatrix[l][3]=true;202 towerModelMatrix[l][3]=dummyModel; 147 203 for (int m=3; m<12; m++) 148 towermatrix[10][m]=true;204 towerModelMatrix[10][m]=dummyModel; 149 205 for (int n=10; n<14; n++) 150 towermatrix[n][11]=true;206 towerModelMatrix[n][11]=dummyModel; 151 207 for (int o=13; o<16; o++) 152 towermatrix[13][o]=true; 208 towerModelMatrix[13][o]=dummyModel; 209 153 210 154 211 //set initial credits, lifes and WaveNumber 155 this->setCredit( 200);156 this->setLifes( 50);212 this->setCredit(100); 213 this->setLifes(100); 157 214 this->setWaveNumber(0); 158 215 time=0.0; 159 216 217 /* 160 218 //adds initial towers 161 219 for (int i=0; i <7; i++){ 162 220 addTower(i+3,4); 163 }/* 164 for (int j=0; j < 7; j++){ 165 addTower(9,j+5); 166 }*/ 221 } 222 */ 167 223 } 168 224 … … 178 234 en1->addTemplate("enemytowerdefense1"); 179 235 en1->setScale(3); 180 en1->setHealth(en1->getHealth() + this->getWaveNumber()*4); 236 en1->lookAt(Vector3(0,0,100000)); 237 en1->setHealth(en1->getHealth() +50 + this->getWaveNumber()*4); 181 238 break; 182 239 … … 184 241 en1->addTemplate("enemytowerdefense2"); 185 242 en1->setScale(2); 186 en1->setHealth(en1->getHealth() + this->getWaveNumber()*4); 243 en1->lookAt(Vector3(0,0,100000)); 244 en1->roll(Degree(120)); 245 en1->setHealth(en1->getHealth() -30 + this->getWaveNumber()*4); 187 246 // en1->setShieldHealth(en1->getShield() = this->getWaveNumber()*2)) 188 247 break; … … 191 250 en1->addTemplate("enemytowerdefense3"); 192 251 en1->setScale(1); 193 en1->setHealth(en1->getHealth() + this->getWaveNumber()*4); 252 en1->lookAt(Vector3(0,0,100000)); 253 en1->roll(Degree(120)); 254 en1->setHealth(en1->getHealth() -10 + this->getWaveNumber()*4); 194 255 break; 195 256 } 196 257 258 en1->setTeam(2); 197 259 en1->getController(); 198 en1->setPosition(path.at(0)->get3dcoordinate()); 260 en1->setPosition(path.at(0)->get3dcoordinate()); 199 261 TowerDefenseEnemyvector.push_back(en1); 200 262 … … 209 271 { 210 272 211 Deathmatch::end();273 TeamDeathmatch::end(); 212 274 ChatManager::message("Match is over! Gameover!"); 213 275 276 } 277 278 void TowerDefense::spawnPlayer(PlayerInfo* player) 279 { 280 assert(player); 281 this->player_ = player; 282 283 if (selecter->getPlayer() == NULL) 284 { 285 this->player_ = player; 286 player->startControl(selecter); 287 players_[player].state_ = PlayerState::Alive; 288 } 289 } 290 291 /** 292 @brief 293 Get the player. 294 @return 295 Returns a pointer to the player. If there is no player, NULL is returned. 296 */ 297 PlayerInfo* TowerDefense::getPlayer(void) const 298 { 299 return this->player_; 214 300 } 215 301 216 302 //not working yet 217 303 void TowerDefense::upgradeTower(int x,int y) 218 {/* 219 const int upgradeCost = 20; 304 { 305 TDCoordinate* coord = new TDCoordinate(x,y); 306 x = coord->GetX(); 307 y = coord->GetY(); 308 220 309 221 310 if (!this->hasEnoughCreditForTower(upgradeCost)) … … 225 314 } 226 315 227 if (towermatrix [x][y] == NULL) 316 317 Model* dummyModel2 = new Model(this->center_->getContext()); 318 319 if (towerModelMatrix [x][y] == NULL || (towerModelMatrix [x][y])->getMeshSource() == dummyModel2->getMeshSource()) 228 320 { 229 321 orxout() << "no tower on this position" << endl; … … 233 325 else 234 326 { 235 (towermatrix [x][y])->upgradeTower(); 236 }*/ 327 (towerTurretMatrix [x][y])->upgradeTower(); 328 switch(towerTurretMatrix[x][y]->upgrade) 329 { 330 case 1 : 331 towerModelMatrix[x][y]->setMeshSource("TD_T2.mesh"); 332 break; 333 334 case 2 : 335 towerModelMatrix[x][y]->setMeshSource("TD_T3.mesh"); 336 break; 337 case 3 : 338 towerModelMatrix[x][y]->setMeshSource("TD_T4.mesh"); 339 break; 340 case 4 : 341 towerModelMatrix[x][y]->setMeshSource("TD_T5.mesh"); 342 break; 343 344 } 345 346 this->buyTower(upgradeCost); 347 } 237 348 } 238 349 239 350 /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret") 240 351 so towers have ability if the turrets 241 242 352 */ 353 243 354 void TowerDefense::addTower(int x, int y) 244 { 245 const int towerCost = 20; 355 { 356 TDCoordinate* coord = new TDCoordinate(x,y); 357 x = coord->GetX(); 358 y = coord->GetY(); 359 246 360 247 361 if (!this->hasEnoughCreditForTower(towerCost)) … … 251 365 } 252 366 253 if (tower matrix [x][y]==true)367 if (towerModelMatrix [x][y]!=NULL) 254 368 { 255 369 orxout() << "not possible to put tower here!!" << endl; … … 264 378 int tileScale = (int) this->center_->getTileScale(); 265 379 266 if (x > 15 || y > 15 || x < 0 || y < 0)380 /*if (x > 15 || y > 15 || x < 0 || y < 0) 267 381 { 268 382 //Hard coded: TODO: let this depend on the centerpoint's height, width and fieldsize (fieldsize doesn't exist yet) 269 383 orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl; 270 384 return; 271 } 272 273 orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl; 274 275 //Reduce credit 276 this->buyTower(towerCost); 277 towermatrix [x][y]=true; 385 }*/ 386 387 //orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl; 388 orxout() << "Will add tower at (" << x << "," << y << ")" << endl; 389 390 391 //Create Model 392 Model* newTowerModel = new Model(this->center_->getContext()); 393 newTowerModel->setMeshSource("TD_T1.mesh"); 394 newTowerModel->setScale(30); 395 newTowerModel->pitch(Degree(90)); 396 newTowerModel->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 80); 278 397 279 398 //Creates tower 280 399 TowerDefenseTower* towernew = new TowerDefenseTower(this->center_->getContext()); 281 towernew->addTemplate("towerturret"); 282 towernew->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 75); 400 towernew->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 275); 283 401 towernew->setGame(this); 284 } 402 towernew->setTeam(1); 403 404 //Reduce credit 405 this->buyTower(towerCost); 406 towerModelMatrix [x][y]= newTowerModel; 407 towerTurretMatrix [x][y]= towernew; 408 } 285 409 286 410 bool TowerDefense::hasEnoughCreditForTower(int towerCost) … … 296 420 297 421 422 void TowerDefense::nextwave() 423 { 424 425 orxout() << "newwave" << endl; 426 TowerDefenseEnemyvector.clear(); 427 waves_++; 428 //maxspaceships = round(maxspaceshipsstandard + 0.25*(waves_)); 429 time=0; 430 431 int helpnumber = 40 -(waves_); 432 if(helpnumber <= 0) {helpnumber =1;} 433 float numSpaceships = std::abs((rand() % 100)*5.0f*(helpnumber)); 434 float numEggs = std::abs((rand() % 100)*1.0f*(waves_)); 435 float numUfos = std::abs((rand() % 100)*1.5f*(0.5f*(waves_))) ; 436 437 float totalnumber = (numSpaceships + numEggs + numUfos)*1.3f; 438 439 int newspaceships = (int)(maxspaceships* numSpaceships / totalnumber); 440 int neweggs = (int)(maxspaceships*numEggs / totalnumber); 441 int newufos = (int)(maxspaceships*numUfos / totalnumber); 442 int newrandomships = maxspaceships -newspaceships - neweggs - newufos; 443 spaceships =newspaceships; 444 eggs=neweggs; 445 ufos=newufos; 446 randomships=newrandomships; 447 448 orxout() << spaceships << endl; 449 orxout() << eggs << endl; 450 orxout() << ufos << endl; 451 orxout() << randomships << endl; 452 453 454 455 456 457 } 458 298 459 void TowerDefense::tick(float dt) 299 460 { 300 461 SUPER(TowerDefense, tick, dt); 301 462 time +=dt; 463 timeSetTower_ +=dt; 464 465 //Check if tower has to be set (because TowerDefenseSelecter asks for it) 466 if(timeSetTower_ >= 0.25) 467 { 468 timeSetTower_ =0; 469 if(selecter != NULL && selecter->firePressed_) 470 { 471 472 int x = selecter->selectedPos_->GetX(); 473 int y = selecter->selectedPos_->GetY(); 474 Model* dummyModel2 = new Model(this->center_->getContext()); 475 476 477 478 if(towerModelMatrix[x][y] == NULL) 479 { 480 addTower(x,y); 481 } 482 else 483 { 484 if(!((towerModelMatrix [x][y])->getMeshSource() == dummyModel2->getMeshSource())) 485 { 486 towerTurretMatrix[x][y]->upgradeTower(); 487 if(towerTurretMatrix[x][y]->upgrade < towerTurretMatrix[x][y]->upgradeMax) 488 { 489 int specificupgradecost = (int)(upgradeCost*(std::pow(1.5,towerTurretMatrix[x][y]->upgrade))); 490 if(this->credit_ >= specificupgradecost) 491 { 492 this->buyTower(specificupgradecost); 493 switch(towerTurretMatrix[x][y]->upgrade) 494 { 495 case 1 : 496 towerModelMatrix[x][y]->setMeshSource("TD_T2.mesh"); 497 break; 498 499 case 2 : 500 towerModelMatrix[x][y]->setMeshSource("TD_T3.mesh"); 501 break; 502 case 3 : 503 towerModelMatrix[x][y]->setMeshSource("TD_T4.mesh"); 504 break; 505 case 4 : 506 towerModelMatrix[x][y]->setMeshSource("TD_T5.mesh"); 507 break; 508 509 } 510 } 511 512 513 } 514 } 515 } 516 selecter->firePressed_ = false; 517 } 518 } 302 519 303 520 TDCoordinate* coord1 = new TDCoordinate(1,1); 304 521 std::vector<TDCoordinate*> path; 305 522 path.push_back(coord1); 306 if(time>1 && TowerDefenseEnemyvector.size() < 30) 307 { 308 //adds different types of enemys depending on the WaveNumber 309 addTowerDefenseEnemy(path, this->getWaveNumber() % 3 +1 ); 310 time = time-1; 311 } 523 524 525 526 527 528 if(time>=TowerDefenseEnemyvector.size() && TowerDefenseEnemyvector.size() < maxspaceships) 529 { 530 531 //adds different types of enemys depending on the WaveNumber progressively making the combination of enemys more difficult 532 if(spaceships>0) 533 { 534 addTowerDefenseEnemy(path, 1); 535 spaceships--; 536 537 }else if(ufos>0) 538 { 539 addTowerDefenseEnemy(path, 3); 540 ufos--; 541 }else if(eggs>0) 542 { 543 addTowerDefenseEnemy(path, 2); 544 eggs--; 545 }else if(randomships>0) 546 { 547 addTowerDefenseEnemy(path, rand() % 3 +1); 548 randomships--; 549 550 } 551 552 } 553 312 554 313 555 Vector3* endpoint = new Vector3(500, 700, 150); … … 317 559 if(TowerDefenseEnemyvector.at(i) != NULL && TowerDefenseEnemyvector.at(i)->isAlive()) 318 560 { 319 //destroys enemys at the end of t ehpath and reduces the life by 1. no credits gifted561 //destroys enemys at the end of the path and reduces the life by 1. no credits gifted 320 562 321 563 Vector3 ship = TowerDefenseEnemyvector.at(i)->getRVWorldPosition(); … … 333 575 } 334 576 } 577 335 578 //goes thorugh vector to see if an enemy is still alive. if not next wave is launched 336 579 int count= 0; … … 343 586 } 344 587 588 if (count == 0 && !this->nextwaveTimer_.isActive()) 589 this->nextwaveTimer_.startTimer(); 590 591 /* time2 +=dt; 345 592 if(count== 0) 346 593 { 347 time2 +=dt;348 594 if(time2 > 10) 349 595 { … … 354 600 } 355 601 } 356 357 358 } 602 */ 603 604 } 605 359 606 360 607 // Function to test if we can add waypoints using code only. Doesn't work yet … … 399 646 void TowerDefense::playerEntered(PlayerInfo* player) 400 647 { 401 Deathmatch::playerEntered(player);648 TeamDeathmatch::playerEntered(player); 402 649 403 650 const std::string& message = player->getName() + " entered the game"; … … 407 654 bool TowerDefense::playerLeft(PlayerInfo* player) 408 655 { 409 bool valid_player = Deathmatch::playerLeft(player);656 bool valid_player = TeamDeathmatch::playerLeft(player); 410 657 411 658 if (valid_player) … … 437 684 } 438 685 439 Deathmatch::pawnKilled(victim, killer);686 TeamDeathmatch::pawnKilled(victim, killer); 440 687 } 441 688 -
code/trunk/src/modules/towerdefense/TowerDefense.h
r10258 r10622 38 38 #define _TowerDefense_H__ 39 39 #include "TDCoordinate.h" 40 #include "TowerDefenseSelecter.h" 40 41 #include "towerdefense/TowerDefensePrereqs.h" 41 #include "gametypes/ Deathmatch.h"42 #include "gametypes/TeamDeathmatch.h" 42 43 #include "TowerDefenseEnemy.h" 43 44 #include "util/Output.h" 44 45 #include "core/object/WeakPtr.h" 46 #include "TowerDefenseSelecter.h" 47 #include "graphics/Camera.h" 48 45 49 46 50 namespace orxonox 47 51 { 48 class _TowerDefenseExport TowerDefense : public Deathmatch52 class _TowerDefenseExport TowerDefense : public TeamDeathmatch 49 53 { 50 54 public: … … 53 57 54 58 std::vector<orxonox::WeakPtr<TowerDefenseEnemy> > TowerDefenseEnemyvector; 55 bool towermatrix[16][16]; 59 Model* towerModelMatrix[16][16]; 60 TowerDefenseTower* towerTurretMatrix[16][16]; 56 61 void addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr); 57 62 virtual void start(); //<! The function is called when the gametype starts 58 63 virtual void end(); 59 64 virtual void tick(float dt); 60 //virtual void playerEntered(PlayerInfo* player); 61 //virtual bool playerLeft(PlayerInfo* player); 62 //Player Stats (set,get, reduce) 65 virtual void spawnPlayer(PlayerInfo* player); 66 PlayerInfo* getPlayer(void) const; 63 67 int getCredit(){ return this->credit_; } 64 68 int getLifes(){ return this->lifes_; } … … 69 73 void buyTower(int cost){ credit_ -= cost;} 70 74 void addCredit(int credit) { credit_+=credit; } 71 void nextwave() { waves_++;}75 void nextwave(); 72 76 int reduceLifes(int NumberofLifes){ return lifes_-=NumberofLifes; } 77 TowerDefenseSelecter* selecter; 78 int spaceships; 79 int eggs; 80 int ufos; 81 int randomships; 82 73 83 74 84 //virtual void pawnKilled(Pawn* victim, Pawn* killer = 0); … … 83 93 /* Adds a tower at x, y in the playfield */ 84 94 void addTower(int x, int y); 85 86 95 void upgradeTower(int x, int y); 87 /* Part of a temporary hack to allow the player to add towers */88 ConsoleCommand* dedicatedAddTower_;89 ConsoleCommand* dedicatedUpgradeTower_;90 96 91 97 //TODO: void spawnNewWave() … … 96 102 private: 97 103 TowerDefenseCenterpoint *center_; 104 PlayerInfo* player_; 98 105 float time; 99 float time2; 106 float timeSetTower_; 107 // float time2; 100 108 int credit_; 101 109 int waves_; 102 110 int lifes_; 111 Timer nextwaveTimer_; 103 112 104 113 /* handles stats */ 105 114 bool hasEnoughCreditForTower(int towerCost); 106 115 bool hasEnoughCreditForUpgrade(); 107 108 109 110 std::vector<TowerTurret*> towers_;111 116 }; 112 117 } -
code/trunk/src/modules/towerdefense/TowerDefenseCenterpoint.cc
r9667 r10622 53 53 this->width_ = 15; 54 54 this->height_ = 15; 55 this->towerTemplate_ = "";56 55 57 56 //this->setCollisionType(Static); … … 72 71 XMLPortParam(TowerDefenseCenterpoint, "height", setHeight, getHeight, xmlelement, mode); 73 72 XMLPortParam(TowerDefenseCenterpoint, "tileScale", setTileScale, getTileScale, xmlelement, mode); 74 XMLPortParam(TowerDefenseCenterpoint, " towerTemplate", setTowerTemplate, getTowerTemplate, xmlelement, mode);73 XMLPortParam(TowerDefenseCenterpoint, "selecterTemplate", setSelecterTemplate, getSelecterTemplate, xmlelement, mode); 75 74 76 75 //TODO: add XMLPortObject(TowerDefenseCenterpoint, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode); -
code/trunk/src/modules/towerdefense/TowerDefenseCenterpoint.h
r9667 r10622 60 60 void setWidth(unsigned int width) 61 61 { this->width_ = width; } 62 63 62 unsigned int getWidth(void) const 64 63 { return this->width_; } 65 66 64 void setHeight(unsigned int height) 67 65 { this->height_ = height; } 68 69 66 unsigned int getHeight(void) const 70 67 { return this->height_; } 71 68 void setSelecterTemplate(const std::string& newTemplate) 69 { this->selecterTemplate_ = newTemplate; } 70 const std::string& getSelecterTemplate() const 71 { return this->selecterTemplate_; } 72 72 /** 73 73 @brief How to convert to world coordinates, e.g. that 0,15 is not at -8,-8 but at -80,-80 (if scale would be 10) … … 79 79 { return this->tileScale_; } 80 80 81 /**82 @brief Set the template for the towers.83 @param template The template name to be applied to each tower.84 */85 void setTowerTemplate(const std::string& templateName)86 { this->towerTemplate_ = templateName; }87 88 const std::string& getTowerTemplate(void) const89 { return this->towerTemplate_; }90 91 81 private: 92 82 void checkGametype(); 93 83 84 std::string selecterTemplate_; 94 85 unsigned int width_; 95 86 unsigned int height_; 96 87 unsigned int tileScale_; 97 98 std::string towerTemplate_;99 88 }; 100 89 } -
code/trunk/src/modules/towerdefense/TowerDefenseEnemy.cc
r10258 r10622 35 35 //add credit if enemy is destroyed 36 36 TowerDefenseEnemy::~TowerDefenseEnemy(){ 37 //this->td->addCredit(1); 37 38 if (this->isInitialized()) 39 { 40 getGame()->addCredit(1); 41 } 38 42 } 39 43 … … 64 68 if (getGame() && once_ == false && getHealth() <= 0) 65 69 { 70 orxout() << "damagefunctionIF" << endl; 66 71 getGame()->addCredit(1); 67 72 once_ = true; 68 73 } 74 orxout() << "damagefunction" << endl; 75 69 76 } 77 70 78 /* 71 79 void TowerDefenseEnemy::popWaypoint() -
code/trunk/src/modules/towerdefense/TowerDefenseTower.cc
r10258 r10622 22 22 Constructor. Registers and initializes the object. 23 23 */ 24 TowerDefenseTower::TowerDefenseTower(Context* context) : Pawn(context)24 TowerDefenseTower::TowerDefenseTower(Context* context) : Turret(context) 25 25 { 26 26 RegisterObject(TowerDefenseTower); 27 game_ =NULL; 28 this->setCollisionType(WorldEntity::None); 29 upgrade = 0; 30 this->addTemplate("towerdefensetower"); 27 31 28 this->setCollisionType(WorldEntity::Dynamic);29 upgrade = 0; 32 upgradeMax = 5; 33 30 34 31 35 //this->removeAllEngines(); … … 38 42 } 39 43 44 /* 40 45 void TowerDefenseTower::setOrientation(const Quaternion& orientation) 41 46 { … … 53 58 { 54 59 } 60 */ 55 61 56 62 bool TowerDefenseTower::upgradeTower() 57 63 { 58 if(upgrade < 3)64 if(upgrade < upgradeMax) 59 65 { 60 66 upgrade++; 61 67 float reloadrate = getReloadRate(); 62 68 float reloadwaittime = getReloadWaitTime(); 63 this->setDamageMultiplier( 5000);64 65 reloadrate = 0. 5f*reloadrate;66 reloadwaittime = 0. 5f*reloadwaittime;69 this->setDamageMultiplier((upgrade+1)*1.5f); 70 this->setRotationThrust(2*this->getRotationThrust()); 71 reloadrate = 0.7f*reloadrate; 72 reloadwaittime = 0.7f*reloadwaittime; 67 73 setReloadRate(reloadrate); 68 74 setReloadWaitTime(reloadwaittime); 69 this->addTemplate("towerturret1");75 //this->addTemplate("towerturret1"); 70 76 } 71 77 else -
code/trunk/src/modules/towerdefense/TowerDefenseTower.h
r10258 r10622 20 20 #include "towerdefense/TowerDefensePrereqs.h" 21 21 #include "worldentities/pawns/SpaceShip.h" 22 #include "objects/Turret.h" 22 23 23 24 24 25 namespace orxonox 25 26 { 26 class _TowerDefenseExport TowerDefenseTower : public Pawn27 class _TowerDefenseExport TowerDefenseTower : public Turret 27 28 { 28 29 public: … … 37 38 38 39 // Overriding these to stop TowerDefenseTowers from spasing out 40 /* 39 41 void setOrientation(const Quaternion& orientation); 40 42 virtual void rotateYaw(const Vector2& value); 41 43 virtual void rotatePitch(const Vector2& value); 42 44 virtual void rotateRoll(const Vector2& value); 45 */ 43 46 virtual bool upgradeTower(); 44 47 … … 46 49 void setGame(TowerDefense* Towerdefense) 47 50 { assert(Towerdefense); game_ = Towerdefense; } 51 int upgrade; 52 int upgradeMax; 48 53 private: 49 54 TowerDefense* game_; 50 int upgrade; 55 51 56 }; 52 57 }
Note: See TracChangeset
for help on using the changeset viewer.