Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9211


Ignore:
Timestamp:
May 18, 2012, 4:00:21 PM (12 years ago)
Author:
mentzerf
Message:

+ Now only adding tower if there is enough credit

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

Legend:

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

    r9207 r9211  
    7777#include "Tower.h"
    7878#include "TowerDefenseCenterpoint.h"
    79 #include "TowerDefensePlayerStats.h"
    8079
    8180#include "worldentities/SpawnPoint.h"
     
    156155        }
    157156       
    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))
    161162                {
    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;
    165165                }
    166166               
    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))
    173168                {
    174169                        orxout() << "tower exists!!" << endl;
    175170                        return;
    176                 }
    177                
    178                 coordinate newTowerCoordinates;
    179                 newTowerCoordinates.x = x; newTowerCoordinates.y = y;
    180                 addedTowersCoordinates_.push_back(newTowerCoordinates);
    181                
     171                }               
     172               
     173                /*
    182174                unsigned int width = this->center_->getWidth();
    183175                unsigned int height = this->center_->getHeight();
     176                */
     177               
    184178                int tileScale = (int) this->center_->getTileScale();
    185                
    186                 orxout() << "tile scale = " << tileScale << endl;
    187179                       
    188180                if (x > 15 || y > 15 || x < 0 || y < 0)
     
    195187                orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl;
    196188               
     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
    197197                Tower* newTower = new Tower(this->center_);
    198198                newTower->addTemplate(this->center_->getTowerTemplate());
     
    207207                // TODO: load Tower mesh
    208208        }
     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       
    209227       
    210228        void TowerDefense::tick(float dt)
  • code/branches/newlevel2012/src/modules/towerdefense/TowerDefense.h

    r9207 r9211  
    4141#include "gametypes/Deathmatch.h"
    4242                 
     43 #include "TowerDefensePlayerStats.h"
     44                 
    4345namespace orxonox
    4446{
     
    8183                /* handles stats */
    8284                TowerDefensePlayerStats *stats_;
     85                bool hasEnoughCreditForTower(TowerCost towerCost);
    8386       
    84                 bool hasTower(int x, int y);
     87                bool towerExists(int x, int y);
    8588               
    8689                typedef struct {
    8790                        int x;
    8891                        int y;
    89                 } coordinate;
     92                } Coordinate;
    9093               
    9194       
    9295               
    93                 std::vector<coordinate> addedTowersCoordinates_;
     96                std::vector<Coordinate> addedTowersCoordinates_;
    9497                std::vector<Tower*> towers_;
    9598               
  • code/branches/newlevel2012/src/modules/towerdefense/TowerDefensePlayerStats.h

    r9207 r9211  
    4242namespace orxonox
    4343{
     44        typedef enum _TowerCosts {
     45                TDDefaultTowerCost = 200
     46        } TowerCost;
     47       
    4448    class _TowerDefenseExport TowerDefensePlayerStats
    4549    {
     
    5256                inline void setCredit(int credit)
    5357                        { credit_ = credit; }
     58               
     59                inline void buyTower(TowerCost cost)
     60                        { credit_ -= cost;}
    5461               
    5562                inline int getWaveNumber()
Note: See TracChangeset for help on using the changeset viewer.