Changeset 9211 for code/branches/newlevel2012/src/modules/towerdefense
- Timestamp:
- May 18, 2012, 4:00:21 PM (13 years ago)
- Location:
- code/branches/newlevel2012/src/modules/towerdefense
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.cc
r9207 r9211 77 77 #include "Tower.h" 78 78 #include "TowerDefenseCenterpoint.h" 79 #include "TowerDefensePlayerStats.h"80 79 81 80 #include "worldentities/SpawnPoint.h" … … 156 155 } 157 156 158 bool TowerDefense::hasTower(int x, int y) 159 { 160 for(std::vector<coordinate>::iterator it = addedTowersCoordinates_.begin(); it != addedTowersCoordinates_.end(); ++it) 157 void TowerDefense::addTower(int x, int y) 158 { 159 const TowerCost towerCost = TDDefaultTowerCost; 160 161 if (!this->hasEnoughCreditForTower(towerCost)) 161 162 { 162 coordinate currentCoordinates = (coordinate) (*it); 163 if (currentCoordinates.x == x && currentCoordinates.y == y) 164 return true; 163 orxout() << "not enough credit: " << (this->stats_->getCredit()) << " available, " << TDDefaultTowerCost << " needed."; 164 return; 165 165 } 166 166 167 return false; 168 } 169 170 void TowerDefense::addTower(int x, int y) 171 { 172 if (this->hasTower(x,y)) 167 if (this->towerExists(x,y)) 173 168 { 174 169 orxout() << "tower exists!!" << endl; 175 170 return; 176 } 177 178 coordinate newTowerCoordinates; 179 newTowerCoordinates.x = x; newTowerCoordinates.y = y; 180 addedTowersCoordinates_.push_back(newTowerCoordinates); 181 171 } 172 173 /* 182 174 unsigned int width = this->center_->getWidth(); 183 175 unsigned int height = this->center_->getHeight(); 176 */ 177 184 178 int tileScale = (int) this->center_->getTileScale(); 185 186 orxout() << "tile scale = " << tileScale << endl;187 179 188 180 if (x > 15 || y > 15 || x < 0 || y < 0) … … 195 187 orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl; 196 188 189 // Add tower to coordinatesStack 190 Coordinate newTowerCoordinates = {x, y}; 191 addedTowersCoordinates_.push_back(newTowerCoordinates); 192 193 // Reduce credit 194 this->stats_->buyTower(towerCost); 195 196 // Create tower 197 197 Tower* newTower = new Tower(this->center_); 198 198 newTower->addTemplate(this->center_->getTowerTemplate()); … … 207 207 // TODO: load Tower mesh 208 208 } 209 210 bool TowerDefense::hasEnoughCreditForTower(TowerCost towerCost) 211 { 212 return ((this->stats_->getCredit()) >= towerCost); 213 } 214 215 bool TowerDefense::towerExists(int x, int y) 216 { 217 for(std::vector<Coordinate>::iterator it = addedTowersCoordinates_.begin(); it != addedTowersCoordinates_.end(); ++it) 218 { 219 Coordinate currentCoordinates = (Coordinate) (*it); 220 if (currentCoordinates.x == x && currentCoordinates.y == y) 221 return true; 222 } 223 224 return false; 225 } 226 209 227 210 228 void TowerDefense::tick(float dt) -
code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.h
r9207 r9211 41 41 #include "gametypes/Deathmatch.h" 42 42 43 #include "TowerDefensePlayerStats.h" 44 43 45 namespace orxonox 44 46 { … … 81 83 /* handles stats */ 82 84 TowerDefensePlayerStats *stats_; 85 bool hasEnoughCreditForTower(TowerCost towerCost); 83 86 84 bool hasTower(int x, int y);87 bool towerExists(int x, int y); 85 88 86 89 typedef struct { 87 90 int x; 88 91 int y; 89 } coordinate;92 } Coordinate; 90 93 91 94 92 95 93 std::vector< coordinate> addedTowersCoordinates_;96 std::vector<Coordinate> addedTowersCoordinates_; 94 97 std::vector<Tower*> towers_; 95 98 -
code/branches/newlevel2012/src/modules/towerdefense/TowerDefensePlayerStats.h
r9207 r9211 42 42 namespace orxonox 43 43 { 44 typedef enum _TowerCosts { 45 TDDefaultTowerCost = 200 46 } TowerCost; 47 44 48 class _TowerDefenseExport TowerDefensePlayerStats 45 49 { … … 52 56 inline void setCredit(int credit) 53 57 { credit_ = credit; } 58 59 inline void buyTower(TowerCost cost) 60 { credit_ -= cost;} 54 61 55 62 inline int getWaveNumber()
Note: See TracChangeset
for help on using the changeset viewer.