Changeset 10406 for code/branches/towerdefenseFS15/src/modules/towerdefense
- Timestamp:
- Apr 26, 2015, 10:16:26 PM (10 years ago)
- Location:
- code/branches/towerdefenseFS15/src/modules/towerdefense
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/towerdefenseFS15/src/modules/towerdefense/TDCoordinate.cc
r10258 r10406 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/branches/towerdefenseFS15/src/modules/towerdefense/TDCoordinate.h
r10258 r10406 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/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) -
code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefense.h
r10397 r10406 45 45 #include "core/object/WeakPtr.h" 46 46 #include "TowerDefenseSelecter.h" 47 #include "graphics/Camera.h" 47 48 48 49 … … 62 63 virtual void end(); 63 64 virtual void tick(float dt); 64 //virtual void playerEntered(PlayerInfo* player); 65 //virtual bool playerLeft(PlayerInfo* player); 66 //Player Stats (set,get, reduce) 65 virtual void spawnPlayer(PlayerInfo* player); 66 PlayerInfo* getPlayer(void) const; 67 67 int getCredit(){ return this->credit_; } 68 68 int getLifes(){ return this->lifes_; } … … 75 75 void nextwave(){ TowerDefenseEnemyvector.clear(); waves_++; time=0;} 76 76 int reduceLifes(int NumberofLifes){ return lifes_-=NumberofLifes; } 77 TDCoordinate* selectedPos;78 77 TowerDefenseSelecter* selecter; 79 78 … … 89 88 /* Adds a tower at x, y in the playfield */ 90 89 void addTower(int x, int y); 91 92 90 void upgradeTower(int x, int y); 93 91 … … 99 97 private: 100 98 TowerDefenseCenterpoint *center_; 99 PlayerInfo* player_; 101 100 float time; 102 101 // float time2; … … 109 108 bool hasEnoughCreditForTower(int towerCost); 110 109 bool hasEnoughCreditForUpgrade(); 111 112 113 114 std::vector<TowerTurret*> towers_;115 110 }; 116 111 } -
code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefenseCenterpoint.cc
r10325 r10406 71 71 XMLPortParam(TowerDefenseCenterpoint, "height", setHeight, getHeight, xmlelement, mode); 72 72 XMLPortParam(TowerDefenseCenterpoint, "tileScale", setTileScale, getTileScale, xmlelement, mode); 73 XMLPortParam(TowerDefenseCenterpoint, "selecterTemplate", setSelecterTemplate, getSelecterTemplate, xmlelement, mode); 73 74 74 75 //TODO: add XMLPortObject(TowerDefenseCenterpoint, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode); -
code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefenseCenterpoint.h
r10325 r10406 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) … … 82 82 void checkGametype(); 83 83 84 std::string selecterTemplate_; 84 85 unsigned int width_; 85 86 unsigned int height_; -
code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefenseSelecter.cc
r10397 r10406 51 51 moveLeftPressed_ = false; 52 52 moveRightPressed_ = false; 53 selectedPos_ = new TDCoordinate(0,0); 54 55 Model* selecterModel = new Model(context); 56 selecterModel->setMeshSource("cube.mesh"); 57 selecterModel->setScale(45); 58 53 setSelectedPosition(0,0); 59 54 } 60 55 … … 67 62 { 68 63 SUPER(TowerDefenseSelecter, XMLPort, xmlelement, mode); 69 // Beispielport // XMLPortParam(TowerDefenseSelecter, "mouseFactor", setMouseFactor, getMouseFactor, xmlelement, mode);70 71 64 } 72 65 … … 77 70 if (hasLocalController()) 78 71 { 72 int selecterPosX = selectedPos_->GetX(); 73 int selecterPosY = selectedPos_->GetY(); 79 74 80 75 if (moveUpPressed_ == true) 81 76 { 82 if(this->selectedPos_->y >= 15) 83 { 84 } 85 else 86 { 87 this->selectedPos_->y +=1; 88 this->setPosition(selectedPos_->get3dcoordinate()); 89 } 90 77 selectedPos_->Set(selecterPosX, selecterPosY + 1); 78 updatePosition(); 79 orxout() << "up" << endl; 91 80 } 92 81 if (moveDownPressed_ == true) 93 82 { 94 if(this->selectedPos_->y <= 0) 95 { 96 } 97 else 98 { 99 this->selectedPos_->y -= 1; 100 this->setPosition(selectedPos_->get3dcoordinate()); 101 } 102 103 moveDownPressed_ = false; 83 selectedPos_->Set(selecterPosX, selecterPosY - 1); 84 updatePosition(); 85 orxout() << "Down" << endl; 104 86 } 105 87 106 88 if (moveLeftPressed_ == true) 107 89 { 108 if(this->selectedPos_->x <= 0) 109 { 110 } 111 else 112 { 113 this->selectedPos_->x -=1; 114 this->setPosition(selectedPos_->get3dcoordinate()); 115 } 116 90 selectedPos_->Set(selecterPosX - 1, selecterPosY); 91 updatePosition(); 92 orxout() << "Left" << endl; 117 93 } 118 94 if (moveRightPressed_ == true) 119 95 { 120 if(this->selectedPos_->x >= 15) 121 { 122 } 123 else 124 { 125 this->selectedPos_->x += 1; 126 this->setPosition(selectedPos_->get3dcoordinate()); 127 } 128 129 moveDownPressed_ = false; 96 selectedPos_->Set(selecterPosX + 1, selecterPosY); 97 updatePosition(); 98 orxout() << "Right" << endl; 130 99 } 131 132 133 100 134 101 /* … … 137 104 firePressed_ = false; 138 105 timeSinceLastFire_ = 0.0; 139 fireSignal_ = true;140 106 } 141 107 */ … … 146 112 moveDownPressed_ = false; 147 113 moveLeftPressed_ = false; 148 move DownPressed_ = false;114 moveRightPressed_ = false; 149 115 //firePressed_ = false; 150 116 } … … 199 165 //firePressed_ = true; 200 166 } 167 168 void TowerDefenseSelecter::updatePosition() 169 { 170 setPosition(selectedPos_->get3dcoordinate()); 171 } 172 173 void TowerDefenseSelecter::setSelectedPosition(TDCoordinate* newPos) 174 { 175 selectedPos_ = newPos; 176 updatePosition(); 177 } 178 179 void TowerDefenseSelecter::setSelectedPosition(int x, int y) 180 { 181 setSelectedPosition(new TDCoordinate(x,y)); 182 } 183 184 201 185 } -
code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefenseSelecter.h
r10397 r10406 41 41 TowerDefenseSelecter(Context* context); //!< Constructor. Registers and initializes the object. 42 42 virtual ~TowerDefenseSelecter(); 43 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 44 virtual void tick(float dt); 43 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 44 virtual void tick(float dt); 45 45 virtual void moveFrontBack(const Vector2& value); //!< Overloaded the function to steer the bat up and down. 46 46 virtual void moveRightLeft(const Vector2& value); //!< Overloaded the function to steer the bat up and down. … … 50 50 void fire(unsigned int firemode); 51 51 virtual void fired(unsigned int firemode); 52 virtual void setSelectedPosition(TDCoordinate* newPos); 53 virtual void setSelectedPosition(int x, int y); 54 55 private: 56 virtual void updatePosition(); 57 52 58 TDCoordinate* selectedPos_; 53 54 55 56 private:57 58 59 bool moveUpPressed_; 59 60 bool moveDownPressed_; 60 61 bool moveLeftPressed_; 61 bool moveRightPressed_; 62 bool moveRightPressed_; 62 63 }; 63 64 }
Note: See TracChangeset
for help on using the changeset viewer.