Changeset 10172 for code/branches
- Timestamp:
- Dec 11, 2014, 1:05:08 PM (10 years ago)
- Location:
- code/branches/towerdefenseHS14/src/modules/towerdefense
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/towerdefenseHS14/src/modules/towerdefense/TDEnemy.h
r9272 r10172 5 5 * Author: weigeltm 6 6 */ 7 7 /* 8 8 #ifndef TDENEMY_H_ 9 9 #define TDENEMY_H_ … … 24 24 25 25 26 #endif /*TDENEMY_H_ */26 #endif TDENEMY_H_ */ -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.cc
r10159 r10172 20 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 21 * 22 * 22 * Author: 23 23 * 24 24 * Co-authors: … … 73 73 * 74 74 */ 75 76 75 #include "TowerDefense.h" 77 76 #include "TowerDefenseTower.h" 78 #include "TowerTurret.h"79 77 #include "TowerDefenseCenterpoint.h" 80 78 //#include "TDCoordinate.h" 79 #include "TowerTurret.h" 81 80 #include "worldentities/SpawnPoint.h" 82 81 #include "worldentities/pawns/Pawn.h" 83 82 #include "worldentities/pawns/SpaceShip.h" 84 83 #include "controllers/WaypointController.h" 85 86 84 #include "graphics/Model.h" 87 85 #include "infos/PlayerInfo.h" 88 86 #include "chat/ChatManager.h" 89 87 #include "core/CoreIncludes.h" 90 91 88 /* Part of a temporary hack to allow the player to add towers */ 92 89 #include "core/command/ConsoleCommand.h" … … 99 96 { 100 97 RegisterObject(TowerDefense); 98 /* 99 for (int i=0; i < 16 ; i++){ 100 for (int j = 0; j< 16 ; j++){ 101 towermatrix[i][j] = NULL; 102 } 103 }*/ 101 104 102 105 this->setHUDTemplate("TowerDefenseHUD"); … … 104 107 //this->stats_ = new TowerDefensePlayerStats(); 105 108 106 /* Temporary hack to allow the player to add towers */109 /* Temporary hack to allow the player to add towers and upgrade them */ 107 110 this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) ); 108 111 this->dedicatedUpgradeTower_ = createConsoleCommand( "upgradeTower", createExecutor( createFunctor(&TowerDefense::upgradeTower, this) ) ); … … 128 131 void TowerDefense::start() 129 132 { 130 orxout() << "test0" << endl;131 133 132 134 Deathmatch::start(); 133 /*credits = 5000; 134 life = 20; 135 waves = 0; 136 time=0.0;*/ 137 138 // Waypoints: [1,3] [10,3] [10,11] [13,11] 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 139 137 for (int i=0; i < 16 ; i++){ 140 138 for (int j = 0; j< 16 ; j++){ … … 142 140 } 143 141 } 142 144 143 for (int k=0; k<3; k++) 145 144 towermatrix[1][k]=true; … … 153 152 towermatrix[13][o]=true; 154 153 155 154 //set initial credits, lifes and WaveNumber 156 155 this->setCredit(200); 157 this->setLifes( 10);156 this->setLifes(50); 158 157 this->setWaveNumber(0); 159 158 time=0.0; 160 159 161 const int kInitialTowerCount = 3; 162 163 for (int i = 0; i < kInitialTowerCount; i++) 164 { 165 addTower(i+4,i+5); 166 } 167 168 169 170 //add some TowerDefenseEnemys 171 172 173 174 175 176 //ChatManager::message("Use the console command addTower x y to add towers"); 177 178 //TODO: let the player control his controllable entity && TODO: create a new ControllableEntity for the player 179 } 180 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 }*/ 167 } 181 168 // Generates a TowerDefenseEnemy. Uses Template "enemytowerdefense". Sets position at first waypoint of path. 182 183 169 void TowerDefense::addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr){ 170 184 171 185 172 TowerDefenseEnemy* en1 = new TowerDefenseEnemy(this->center_->getContext()); … … 190 177 en1->addTemplate("enemytowerdefense1"); 191 178 en1->setScale(3); 179 en1->setHealth(en1->getHealth() + this->getWaveNumber()*4); 180 192 181 break; 193 182 case 2 : 194 183 en1->addTemplate("enemytowerdefense2"); 195 184 en1->setScale(2); 185 en1->setHealth(en1->getHealth() + this->getWaveNumber()*4); 186 // en1->setShieldHealth(en1->getShield() = this->getWaveNumber()*2)) 187 196 188 break; 197 189 case 3 : 198 en1->addTemplate("enemytowerdefense3"); 199 en1->setScale(1); 200 break; 190 en1->addTemplate("enemytowerdefense3"); 191 en1->setScale(1); 192 en1->setHealth(en1->getHealth() + this->getWaveNumber()*4); 193 break; 201 194 } 202 195 203 196 en1->getController(); 204 205 197 en1->setPosition(path.at(0)->get3dcoordinate()); 206 207 208 198 TowerDefenseEnemyvector.push_back(en1); 209 199 210 211 200 for(unsigned int i = 0; i < path.size(); ++i) 212 { 213 en1->addWaypoint((path.at(i))); 214 } 215 216 217 /* 218 WaypointController *newController = new WaypointController(en1->getContext());// 219 newController->setAccuracy(3); 220 221 for(int i =0; i < path.size(); ++i) 222 { 223 224 Model *wayPoint = new Model(en1->getContext()); 225 wayPoint->setMeshSource("cube.mesh"); 226 wayPoint->setPosition(path.at(i)->get3dcoordinate()); 227 wayPoint->setScale(0.2); 228 newController->addWaypoint(wayPoint); 229 }*/ 201 { 202 en1->addWaypoint((path.at(i))); 203 } 230 204 } 231 205 … … 234 208 235 209 { 210 236 211 Deathmatch::end(); 237 238 212 ChatManager::message("Match is over! Gameover!"); 239 } 240 213 214 } 215 216 //not working yet 241 217 void TowerDefense::upgradeTower(int x,int y) 242 218 {/* 243 const TowerCost upgradeCost = TDDefaultUpgradeCost;219 const int upgradeCost = 20; 244 220 245 221 if (!this->hasEnoughCreditForTower(upgradeCost)) … … 261 237 } 262 238 263 239 /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret") 240 so towers have ability if the turrets 241 242 */ 264 243 void TowerDefense::addTower(int x, int y) 265 244 { … … 294 273 orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl; 295 274 296 297 298 275 //Reduce credit 299 276 this->buyTower(towerCost); 300 301 277 towermatrix [x][y]=true; 302 278 303 304 // Create tower 279 //Creates tower 305 280 TowerDefenseTower* towernew = new TowerDefenseTower(this->center_->getContext()); 306 281 towernew->addTemplate("towerturret"); 307 282 towernew->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 75); 308 283 towernew->setGame(this); 309 310 284 } 311 285 … … 314 288 return ((this->getCredit()) >= towerCost); 315 289 } 290 316 291 317 292 bool TowerDefense::hasEnoughCreditForUpgrade() … … 329 304 std::vector<TDCoordinate*> path; 330 305 path.push_back(coord1); 331 332 306 if(time>1 && TowerDefenseEnemyvector.size() < 30) 333 307 { 334 addTowerDefenseEnemy(path, rand() %3 +1 ); 335 time = time-1; 336 } 337 338 Vector3* endpoint = new Vector3(500, 700, 150); 339 340 for(int i =0; i < TowerDefenseEnemyvector.size(); ++i) 341 { 342 343 //orxout() << TowerDefenseEnemyvector.at(i) << endl; 344 //continue; 345 346 //ArtificialController* controller = (ArtificialController*)this->getController(); 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 { 347 317 if(TowerDefenseEnemyvector.at(i) != NULL && TowerDefenseEnemyvector.at(i)->isAlive()) 348 { 349 orxout() << "Variable i: " << i << endl; 350 351 Vector3 ship = TowerDefenseEnemyvector.at(i)->getRVWorldPosition(); 352 353 float distance = ship.distance(*endpoint); 354 355 //orxout() << "distance" << distance << endl; 356 if(distance <50){ 357 // orxout() << "ENEMY KILLED!!!!" << endl; 358 TowerDefenseEnemyvector.at(i)->destroy(); 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 } 359 333 } 360 334 } 361 else 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) 362 338 { 363 //TowerDefenseEnemyvector.erase(TowerDefenseEnemyvector.begin() +i); 339 if(TowerDefenseEnemyvector.at(i)!= NULL) 340 { 341 ++count; 342 } 364 343 } 365 } 366 367 int count= 0; 368 for(int i =0; i < TowerDefenseEnemyvector.size(); ++i) 369 { 370 if(TowerDefenseEnemyvector.at(i)!= NULL) 371 { 372 ++count; 373 } 374 } 375 376 if(count== 0) 377 { 378 time2 +=dt; 379 if(time2 > 10) 380 { 381 TowerDefenseEnemyvector.clear(); 382 time=0; 383 time2=0; 384 } 385 } 386 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 } 387 356 388 357 -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.h
r10159 r10172 42 42 #include "TowerDefenseEnemy.h" 43 43 #include "util/Output.h" 44 45 46 #include "TowerDefensePlayerStats.h" 44 #include "core/object/WeakPtr.h" 47 45 48 46 namespace orxonox … … 56 54 std::vector<orxonox::WeakPtr<TowerDefenseEnemy> > TowerDefenseEnemyvector; 57 55 bool towermatrix[16][16]; 58 void addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr); 56 void addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr); 59 57 virtual void start(); //<! The function is called when the gametype starts 60 58 virtual void end(); … … 108 106 bool hasEnoughCreditForUpgrade(); 109 107 108 109 110 110 std::vector<TowerTurret*> towers_; 111 111 }; -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.cc
r10159 r10172 12 12 */ 13 13 #include "TowerDefenseEnemy.h" 14 15 14 #include "core/CoreIncludes.h" 16 15 //#include "core/XMLPort.h" … … 29 28 30 29 this->setCollisionType(WorldEntity::Dynamic); 30 //needed to keep track of the PlayerStats coded in TowerDefense.h 31 31 this->td = orxonox_cast<TowerDefense*>(this->getGametype().get()); 32 once_ = false;33 32 34 33 } 35 36 TowerDefenseEnemy::~TowerDefenseEnemy(){this->td->addCredit(20);} 34 //add credit if enemy is destroyed 35 TowerDefenseEnemy::~TowerDefenseEnemy(){ 36 this->td->addCredit(1); 37 } 37 38 38 39 void TowerDefenseEnemy::addWaypoint(TDCoordinate* coord) … … 45 46 { 46 47 SUPER(TowerDefenseEnemy, tick, dt); 47 48 //ArtificialController* controller = (ArtificialController*)this->getController();49 Vector3 ship = this->getRVWorldPosition();50 Vector3* endpoint = new Vector3(500, 700, 150);51 52 float distance = ship.distance(*endpoint);53 54 //orxout() << "distance" << distance << endl;55 if(distance < 50 && once_ == false){56 this->td->reduceLifes(1);57 once_=true;58 orxout() << "ENEMY KILLED!!!!" << endl;59 this->td->buyTower(20);60 if (this->td->getLifes()==0)61 {62 this->td->end();63 }64 65 }66 48 } 67 49 -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.h
r10159 r10172 32 32 class _TowerDefenseExport TowerDefenseEnemy : public SpaceShip 33 33 { 34 35 34 public: 36 37 35 TowerDefenseEnemy(Context* context); 38 36 virtual ~TowerDefenseEnemy(); … … 47 45 48 46 private: 49 50 47 TowerDefense* td; 51 48 bool once_; -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseHUDController.cc
r10159 r10172 52 52 const std::string& lifes = multi_cast<std::string>(this->td->getLifes()); 53 53 const std::string& credits = multi_cast<std::string>(this->td->getCredit()); 54 const std::string& wave s= multi_cast<std::string>(this->td->getWaveNumber());54 const std::string& wave = multi_cast<std::string>(this->td->getWaveNumber()); 55 55 56 56 if(showlives == true) … … 59 59 this->setCaption(multi_cast<std::string>(credits)); 60 60 else if(showwaves == true) 61 this->setCaption(multi_cast<std::string>(wave s));61 this->setCaption(multi_cast<std::string>(wave)); 62 62 63 63 … … 87 87 } 88 88 } 89 /*if (this->getOwner() != NULL && this->getOwner()->getGametype())90 {91 this->owner_ = orxonox_cast<TowerDefense*>(this->getOwner()->getGametype().get());92 }93 else94 {95 this->owner_ = NULL;96 }*/97 89 } 98 90 -
code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefensePlayerStats.h
r10159 r10172 27 27 */ 28 28 29 /* *29 /* 30 30 @brief 31 31 This manages the stats of the player. It is used by 'TowerDefense', the gametype 32 32 33 33 @ingroup TowerDefense 34 */ 34 35 35 36 36 … … 88 88 } 89 89 90 #endif /*_TowerDefensePlayerStats_H__ */90 #endif _TowerDefensePlayerStats_H__ */
Note: See TracChangeset
for help on using the changeset viewer.