- Timestamp:
- Apr 26, 2015, 10:16:26 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefense.cc
r10397 r10406 35 35 * pawnKilled() // wird aufgerufen, wenn ein Pawn stirbt (z.B: wenn ) 36 36 * playerScored() // kann man aufrufen um dem Spieler Punkte zu vergeben. 37 *38 37 * 39 38 * … … 110 109 111 110 selecter = NULL; 112 113 111 this->player_ = NULL; 114 112 this->setHUDTemplate("TowerDefenseHUD"); 115 113 this->nextwaveTimer_.setTimer(10, false, createExecutor(createFunctor(&TowerDefense::nextwave, this))); … … 145 143 void TowerDefense::start() 146 144 { 145 if (center_ != NULL) // There needs to be a TowerDefenseCenterpoint, i.e. the area the game takes place. 146 { 147 if (selecter == NULL) 148 { 149 selecter = new TowerDefenseSelecter(this->center_->getContext()); 150 } 151 selecter->addTemplate(center_->getSelecterTemplate()); 152 center_->attach(selecter); 153 } 154 else // If no centerpoint was specified, an error is thrown and the level is exited. 155 { 156 orxout(internal_error) << "Jump: No Centerpoint specified." << endl; 157 return; 158 } 147 159 148 160 TeamDeathmatch::start(); 149 161 150 // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path162 // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path 151 163 for (int i=0; i < 16 ; i++) 152 164 { … … 158 170 } 159 171 160 selecter = new TowerDefenseSelecter(this->center_->getContext()); 172 173 174 if (player_ != NULL) 175 { 176 //this->player_->startControl(selecter); 177 } 178 else 179 { 180 orxout() << "player=NULL" << endl; 181 } 182 161 183 162 184 Model* dummyModel = new Model(this->center_->getContext()); … … 219 241 en1->setTeam(2); 220 242 en1->getController(); 221 en1->setPosition(path.at(0)->get3dcoordinate()); 243 en1->setPosition(path.at(0)->get3dcoordinate()); 222 244 TowerDefenseEnemyvector.push_back(en1); 223 245 … … 237 259 } 238 260 261 void TowerDefense::spawnPlayer(PlayerInfo* player) 262 { 263 assert(player); 264 this->player_ = player; 265 266 if (selecter->getPlayer() == NULL) 267 { 268 this->player_ = player; 269 player->startControl(selecter); 270 players_[player].state_ = PlayerState::Alive; 271 } 272 } 273 274 /** 275 @brief 276 Get the player. 277 @return 278 Returns a pointer to the player. If there is no player, NULL is returned. 279 */ 280 PlayerInfo* TowerDefense::getPlayer(void) const 281 { 282 return this->player_; 283 } 284 239 285 //not working yet 240 286 void TowerDefense::upgradeTower(int x,int y) 241 287 { 288 TDCoordinate* coord = new TDCoordinate(x,y); 289 x = coord->GetX(); 290 y = coord->GetY(); 291 242 292 const int upgradeCost = 20; 243 293 … … 266 316 /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret") 267 317 so towers have ability if the turrets 268 269 318 */ 319 270 320 void TowerDefense::addTower(int x, int y) 271 { 321 { 322 TDCoordinate* coord = new TDCoordinate(x,y); 323 x = coord->GetX(); 324 y = coord->GetY(); 325 272 326 const int towerCost = 20; 273 327 … … 291 345 int tileScale = (int) this->center_->getTileScale(); 292 346 293 if (x > 15 || y > 15 || x < 0 || y < 0)347 /*if (x > 15 || y > 15 || x < 0 || y < 0) 294 348 { 295 349 //Hard coded: TODO: let this depend on the centerpoint's height, width and fieldsize (fieldsize doesn't exist yet) 296 350 orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl; 297 351 return; 298 } 299 300 orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl;301 352 }*/ 353 354 //orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl; 355 orxout() << "Will add tower at (" << x << "," << y << ")" << endl; 302 356 303 357 304 358 //Create Model 305 Model* newtowermodel = new Model(this->center_->getContext()); 306 newtowermodel->setMeshSource("Tower.mesh"); 307 newtowermodel->setScale(45); 308 newtowermodel->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 50); 309 310 359 Model* newTowerModel = new Model(this->center_->getContext()); 360 newTowerModel->setMeshSource("Tower.mesh"); 361 newTowerModel->setScale(45); 362 newTowerModel->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 50); 311 363 312 364 //Creates tower … … 318 370 //Reduce credit 319 371 this->buyTower(towerCost); 320 towerModelMatrix [x][y]= new towermodel;372 towerModelMatrix [x][y]= newTowerModel; 321 373 towerTurretMatrix [x][y]= towernew; 322 } 374 } 323 375 324 376 bool TowerDefense::hasEnoughCreditForTower(int towerCost)
Note: See TracChangeset
for help on using the changeset viewer.