Changeset 10246 for code/branches/towerdefenseHS14/src/modules
- Timestamp:
- Feb 1, 2015, 9:30:37 PM (10 years ago)
- Location:
- code/branches/towerdefenseHS14/src/modules/towerdefense
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/towerdefenseHS14/src/modules/towerdefense/TDCoordinate.cc
r10245 r10246 24 24 TDCoordinate::TDCoordinate(int x, int y) 25 25 { 26 27 26 this->x=x; 27 this->y=y; 28 28 } 29 29 … … 31 31 Vector3 TDCoordinate::get3dcoordinate() 32 32 { 33 33 float tileScale = 100; 34 34 35 36 37 38 35 Vector3 *coord = new Vector3(); 36 coord->x= (x-8) * tileScale; 37 coord->y= (y-8) * tileScale; 38 coord->z=100; 39 39 40 40 return *coord; 41 41 } 42 42 } -
code/branches/towerdefenseHS14/src/modules/towerdefense/TDCoordinate.h
r10244 r10246 8 8 #include "towerdefense/TowerDefensePrereqs.h" 9 9 #include "worldentities/pawns/SpaceShip.h" 10 namespace orxonox {11 10 namespace orxonox 11 { 12 12 13 13 //Class to save the Coordinates in a class instead of struct 14 14 //Convert 2d coordinates to 3d in order to set waypoints 15 class _TowerDefenseExport TDCoordinate: public OrxonoxClass { 16 public: 17 int x; 15 class _TowerDefenseExport TDCoordinate : public OrxonoxClass 16 { 17 public: 18 int x; 18 19 int y; 19 20 … … 25 26 26 27 TDCoordinate(int x, int y); 27 }; 28 28 }; 29 29 30 30 } -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc
r10172 r10246 98 98 /* 99 99 for (int i=0; i < 16 ; i++){ 100 101 102 100 for (int j = 0; j< 16 ; j++){ 101 towermatrix[i][j] = NULL; 102 } 103 103 }*/ 104 104 … … 109 109 /* Temporary hack to allow the player to add towers and upgrade them */ 110 110 this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) ); 111 111 this->dedicatedUpgradeTower_ = createConsoleCommand( "upgradeTower", createExecutor( createFunctor(&TowerDefense::upgradeTower, this) ) ); 112 112 } 113 113 … … 136 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 137 for (int i=0; i < 16 ; i++){ 138 139 140 138 for (int j = 0; j< 16 ; j++){ 139 towermatrix[i][j] = false; 140 } 141 141 } 142 142 143 143 for (int k=0; k<3; k++) 144 144 towermatrix[1][k]=true; 145 145 for (int l=1; l<11; l++) 146 146 towermatrix[l][3]=true; 147 147 for (int m=3; m<12; m++) 148 148 towermatrix[10][m]=true; 149 149 for (int n=10; n<14; n++) 150 150 towermatrix[n][11]=true; 151 151 for (int o=13; o<16; o++) 152 153 154 //set initial credits, lifes and WaveNumber152 towermatrix[13][o]=true; 153 154 //set initial credits, lifes and WaveNumber 155 155 this->setCredit(200); 156 156 this->setLifes(50); … … 158 158 time=0.0; 159 159 160 //adds initial towers161 for (int i=0; i <7; i++){162 addTower(i+3,4);163 164 for (int j=0; j < 7; j++){165 addTower(9,j+5);160 //adds initial towers 161 for (int i=0; i <7; i++){ 162 addTower(i+3,4); 163 }/* 164 for (int j=0; j < 7; j++){ 165 addTower(9,j+5); 166 166 }*/ 167 } 167 } 168 168 169 // Generates a TowerDefenseEnemy. Uses Template "enemytowerdefense". Sets position at first waypoint of path. 169 void TowerDefense::addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr){170 171 172 170 void TowerDefense::addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr){ 171 172 173 TowerDefenseEnemy* en1 = new TowerDefenseEnemy(this->center_->getContext()); 173 174 174 switch(templatenr) 175 { 176 case 1 : 177 en1->addTemplate("enemytowerdefense1"); 178 en1->setScale(3); 179 180 181 break; 182 case 2 : 183 184 en1->setScale(2);185 186 187 188 break; 189 case 3 : 190 191 192 193 194 } 175 switch(templatenr) 176 { 177 case 1 : 178 en1->addTemplate("enemytowerdefense1"); 179 en1->setScale(3); 180 en1->setHealth(en1->getHealth() + this->getWaveNumber()*4); 181 break; 182 183 case 2 : 184 en1->addTemplate("enemytowerdefense2"); 185 en1->setScale(2); 186 en1->setHealth(en1->getHealth() + this->getWaveNumber()*4); 187 // en1->setShieldHealth(en1->getShield() = this->getWaveNumber()*2)) 188 break; 189 190 case 3 : 191 en1->addTemplate("enemytowerdefense3"); 192 en1->setScale(1); 193 en1->setHealth(en1->getHealth() + this->getWaveNumber()*4); 194 break; 195 } 195 196 196 197 en1->getController(); … … 199 200 200 201 for(unsigned int i = 0; i < path.size(); ++i) 201 202 203 202 { 203 en1->addWaypoint((path.at(i))); 204 } 204 205 } 205 206 206 207 207 208 void TowerDefense::end() 208 209 209 { 210 210 … … 217 217 void TowerDefense::upgradeTower(int x,int y) 218 218 {/* 219 219 const int upgradeCost = 20; 220 220 221 221 if (!this->hasEnoughCreditForTower(upgradeCost)) … … 233 233 else 234 234 { 235 235 (towermatrix [x][y])->upgradeTower(); 236 236 }*/ 237 237 } … … 292 292 bool TowerDefense::hasEnoughCreditForUpgrade() 293 293 { 294 294 return true; 295 295 } 296 296 … … 306 306 if(time>1 && TowerDefenseEnemyvector.size() < 30) 307 307 { 308 309 310 311 } 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 308 //adds different types of enemys depending on the WaveNumber 309 addTowerDefenseEnemy(path, this->getWaveNumber() % 3 +1 ); 310 time = time-1; 311 } 312 313 Vector3* endpoint = new Vector3(500, 700, 150); 314 //if ships are at the end they get destroyed 315 for(unsigned int i =0; i < TowerDefenseEnemyvector.size(); ++i) 316 { 317 if(TowerDefenseEnemyvector.at(i) != NULL && TowerDefenseEnemyvector.at(i)->isAlive()) 318 { 319 //destroys enemys at the end of teh path and reduces the life by 1. no credits gifted 320 321 Vector3 ship = TowerDefenseEnemyvector.at(i)->getRVWorldPosition(); 322 float distance = ship.distance(*endpoint); 323 324 if(distance <50){ 325 TowerDefenseEnemyvector.at(i)->destroy(); 326 this->reduceLifes(1); 327 this->buyTower(1); 328 if (this->getLifes()==0) 329 { 330 this->end(); 331 } 332 } 333 } 334 } 335 //goes thorugh vector to see if an enemy is still alive. if not next wave is launched 336 int count= 0; 337 for(unsigned int i =0; i < TowerDefenseEnemyvector.size(); ++i) 338 { 339 if(TowerDefenseEnemyvector.at(i)!= NULL) 340 { 341 ++count; 342 } 343 } 344 345 if(count== 0) 346 { 347 time2 +=dt; 348 if(time2 > 10) 349 { 350 TowerDefenseEnemyvector.clear(); 351 this->nextwave(); 352 time=0; 353 time2=0; 354 } 355 } 356 356 357 357 -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.h
r10172 r10246 61 61 //virtual bool playerLeft(PlayerInfo* player); 62 62 //Player Stats (set,get, reduce) 63 int getCredit(){ return this->credit_;}64 int getLifes(){ return this->lifes_;}65 int getWaveNumber(){ return this->waves_;}63 int getCredit(){ return this->credit_; } 64 int getLifes(){ return this->lifes_; } 65 int getWaveNumber(){ return this->waves_; } 66 66 void setCredit(int credit){ credit_ = credit; } 67 67 void setLifes(int lifes){ lifes_ = lifes; } 68 void setWaveNumber(int wavenumber){ waves_=wavenumber;}68 void setWaveNumber(int wavenumber){ waves_=wavenumber; } 69 69 void buyTower(int cost){ credit_ -= cost;} 70 void addCredit(int credit) { credit_+=credit;}70 void addCredit(int credit) { credit_+=credit; } 71 71 void nextwave(){ waves_++;} 72 int reduceLifes(int NumberofLifes){ return lifes_-=NumberofLifes;}72 int reduceLifes(int NumberofLifes){ return lifes_-=NumberofLifes; } 73 73 74 74 //virtual void pawnKilled(Pawn* victim, Pawn* killer = 0); -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.cc
r10244 r10246 34 34 //add credit if enemy is destroyed 35 35 TowerDefenseEnemy::~TowerDefenseEnemy(){ 36 36 this->td->addCredit(1); 37 37 } 38 38 39 39 void TowerDefenseEnemy::addWaypoint(TDCoordinate* coord) 40 40 { 41 41 this->Waypointsvector_.push_back(coord); 42 42 } 43 43 … … 51 51 void TowerDefenseEnemy::popWaypoint() 52 52 { 53 54 53 if(Waypointsvector_.size()>0) 54 Waypointsvector_.pop_back(); 55 55 } 56 56 57 57 TDCoordinate TowerDefenseEnemy::peekWaypoint() 58 58 { 59 60 61 62 63 59 if(Waypointsvector_.size()<=0){ 60 TDCoordinate* coord = TDCoordinate(-1,-1); 61 return coord; 62 }else{ 63 return Waypointsvector_.at(Waypointsvector_.size()-1); 64 64 65 65 } 66 66 67 67 -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.h
r10244 r10246 30 30 * 31 31 */ 32 class _TowerDefenseExport TowerDefenseEnemy : public SpaceShip 33 34 35 32 class _TowerDefenseExport TowerDefenseEnemy : public SpaceShip 33 { 34 public: 35 TowerDefenseEnemy(Context* context); 36 36 virtual ~TowerDefenseEnemy(); 37 37 … … 44 44 45 45 46 46 private: 47 47 TowerDefense* td; 48 48 bool once_; 49 49 std::vector<TDCoordinate*> Waypointsvector_; 50 50 51 51 }; 52 52 53 53 -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefensePlayerStats.h
r10172 r10246 69 69 70 70 inline int getLifes() 71 {return lifes_;}71 {return lifes_; } 72 72 73 73 inline void reduceLifes(int NumberofLifes) … … 75 75 76 76 inline void upgradeTower(int upgradecost) 77 77 { credit_ -= upgradecost;} 78 78 79 79 -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseTower.cc
r10245 r10246 63 63 64 64 bool TowerDefenseTower::upgradeTower() 65 66 67 68 69 70 71 65 { 66 if(upgrade < 3) 67 { 68 upgrade++; 69 float reloadrate = getReloadRate(); 70 float reloadwaittime = getReloadWaitTime(); 71 this->setDamageMultiplier(5000); 72 72 73 74 75 76 77 78 79 80 81 82 83 84 85 73 reloadrate = 0.5f*reloadrate; 74 reloadwaittime = 0.5f*reloadwaittime; 75 setReloadRate(reloadrate); 76 setReloadWaitTime(reloadwaittime); 77 this->addTemplate("towerturret1"); 78 } 79 else 80 { 81 orxout() << "Tower fully upgraded" << endl; 82 return false; 83 } 84 return true; 85 } 86 86 87 87 // This function is called whenever a player presses the up or the down key.
Note: See TracChangeset
for help on using the changeset viewer.