- Timestamp:
- May 18, 2012, 4:00:21 PM (13 years ago)
- File:
-
- 1 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)
Note: See TracChangeset
for help on using the changeset viewer.