Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9160


Ignore:
Timestamp:
May 4, 2012, 4:12:47 PM (12 years ago)
Author:
mentzerf
Message:
  • Fixed height of towers

+ not adding towers when they were added already

Location:
code/branches/newlevel2012/src/modules/towerdefense
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.cc

    r9154 r9160  
    150150        }
    151151       
     152        bool TowerDefense::hasTower(int x, int y)
     153        {
     154                for(std::vector<coordinate>::iterator it = addedTowersCoordinates_.begin(); it != addedTowersCoordinates_.end(); ++it)
     155                {
     156                        coordinate currentCoordinates = (coordinate) (*it);
     157                        if (currentCoordinates.x == x && currentCoordinates.y == y)
     158                                return true;
     159                }
     160               
     161                return false;
     162        }
    152163       
    153164        void TowerDefense::addTower(int x, int y)
    154165        {
     166                if (this->hasTower(x,y))
     167                {
     168                        orxout() << "tower exists!!" << endl;
     169                        return;
     170                }
     171               
     172                coordinate newTowerCooridnates;
     173                newTowerCooridnates.x = x; newTowerCooridnates.y = y;
     174                addedTowersCoordinates_.push_back(newTowerCooridnates);
     175               
    155176                unsigned int width = this->center_->getWidth();
    156177                unsigned int height = this->center_->getHeight();
     
    158179               
    159180                orxout() << "tile scale = " << tileScale << endl;
     181               
     182               
    160183               
    161184                if (x > 15 || y > 15 || x < 0 || y < 0)
     
    173196                this->center_->attach(newTower);
    174197               
    175                 newTower->setPosition((x-8) * tileScale, (y-8) * tileScale, 0);
     198                newTower->setPosition((x-8) * tileScale, (y-8) * tileScale, 100);
    176199                newTower->setGame(this);
     200               
    177201                //TODO: Save the Tower in a Vector. I would suggest std::vector< std::vector<Tower*> > towers_ as a protected member variable;
    178202               
  • code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.h

    r9143 r9160  
    7878//              WeakPtr<TowerDefenseCenterpoint> center_;
    7979                TowerDefenseCenterpoint *center_;
     80       
     81       
     82                bool hasTower(int x, int y);
     83               
     84                typedef struct {
     85                        int x;
     86                        int y;
     87                } coordinate;
     88               
     89       
     90               
     91                std::vector<coordinate> addedTowersCoordinates_;
     92                std::vector<Tower*> towers_;
    8093               
    8194                void addWaypointsAndFirstEnemy();
Note: See TracChangeset for help on using the changeset viewer.