Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 11, 2014, 1:05:08 PM (11 years ago)
Author:
maxima
Message:

final version for presentation

File:
1 edited

Legend:

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

    r10159 r10172  
    2020 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    2121 *
    22  *   Author:
     22 *  Author:
    2323 *
    2424 *   Co-authors:
     
    7373 *
    7474 */
    75 
    7675#include "TowerDefense.h"
    7776#include "TowerDefenseTower.h"
    78 #include "TowerTurret.h"
    7977#include "TowerDefenseCenterpoint.h"
    8078//#include "TDCoordinate.h"
     79#include "TowerTurret.h"
    8180#include "worldentities/SpawnPoint.h"
    8281#include "worldentities/pawns/Pawn.h"
    8382#include "worldentities/pawns/SpaceShip.h"
    8483#include "controllers/WaypointController.h"
    85 
    8684#include "graphics/Model.h"
    8785#include "infos/PlayerInfo.h"
    8886#include "chat/ChatManager.h"
    8987#include "core/CoreIncludes.h"
    90 
    9188/* Part of a temporary hack to allow the player to add towers */
    9289#include "core/command/ConsoleCommand.h"
     
    9996    {
    10097        RegisterObject(TowerDefense);
     98/*
     99        for (int i=0; i < 16 ; i++){
     100                for (int j = 0; j< 16 ; j++){
     101                        towermatrix[i][j] = NULL;
     102                }
     103        }*/
    101104
    102105        this->setHUDTemplate("TowerDefenseHUD");
     
    104107        //this->stats_ = new TowerDefensePlayerStats();
    105108
    106         /* Temporary hack to allow the player to add towers */
     109        /* Temporary hack to allow the player to add towers and upgrade them */
    107110        this->dedicatedAddTower_ = createConsoleCommand( "addTower", createExecutor( createFunctor(&TowerDefense::addTower, this) ) );
    108111        this->dedicatedUpgradeTower_ = createConsoleCommand( "upgradeTower", createExecutor( createFunctor(&TowerDefense::upgradeTower, this) ) );
     
    128131    void TowerDefense::start()
    129132    {
    130         orxout() << "test0" << endl;
    131133
    132134        Deathmatch::start();
    133         /*credits = 5000;
    134         life = 20;
    135         waves = 0;
    136         time=0.0;*/
    137 
    138 // Waypoints: [1,3] [10,3] [10,11] [13,11]
     135
     136// Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path
    139137        for (int i=0; i < 16 ; i++){
    140138                for (int j = 0; j< 16 ; j++){
     
    142140                }
    143141        }
     142
    144143        for (int k=0; k<3; k++)
    145144                towermatrix[1][k]=true;
     
    153152                towermatrix[13][o]=true;
    154153
    155 
     154//set initial credits, lifes and WaveNumber
    156155        this->setCredit(200);
    157         this->setLifes(10);
     156        this->setLifes(50);
    158157        this->setWaveNumber(0);
    159158        time=0.0;
    160159
    161         const int kInitialTowerCount = 3;
    162 
    163         for (int i = 0; i < kInitialTowerCount; i++)
    164         {
    165             addTower(i+4,i+5);
    166         }
    167 
    168 
    169 
    170         //add some TowerDefenseEnemys
    171 
    172 
    173 
    174 
    175 
    176         //ChatManager::message("Use the console command addTower x y to add towers");
    177 
    178         //TODO: let the player control his controllable entity && TODO: create a new ControllableEntity for the player
    179     }
    180 
     160//adds initial towers
     161for (int i=0; i <7; i++){
     162          addTower(i+3,4);
     163        }/*
     164for (int j=0; j < 7; j++){
     165          addTower(9,j+5);
     166        }*/
     167}
    181168    // Generates a TowerDefenseEnemy. Uses Template "enemytowerdefense". Sets position at first waypoint of path.
    182 
    183169     void TowerDefense::addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr){
     170
    184171
    185172        TowerDefenseEnemy* en1 = new TowerDefenseEnemy(this->center_->getContext());
     
    190177                en1->addTemplate("enemytowerdefense1");
    191178                en1->setScale(3);
     179            en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
     180
    192181                break;
    193182        case 2 :
    194183                en1->addTemplate("enemytowerdefense2");
    195184                en1->setScale(2);
     185            en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
     186          //  en1->setShieldHealth(en1->getShield() = this->getWaveNumber()*2))
     187
    196188                break;
    197189        case 3 :
    198                 en1->addTemplate("enemytowerdefense3");
    199                 en1->setScale(1);
    200                 break;
     190            en1->addTemplate("enemytowerdefense3");
     191            en1->setScale(1);
     192            en1->setHealth(en1->getHealth() + this->getWaveNumber()*4);
     193            break;
    201194        }
    202                  
     195
    203196        en1->getController();
    204 
    205197        en1->setPosition(path.at(0)->get3dcoordinate());
    206 
    207 
    208198        TowerDefenseEnemyvector.push_back(en1);
    209199
    210 
    211200        for(unsigned int i = 0; i < path.size(); ++i)
    212         {
    213             en1->addWaypoint((path.at(i)));
    214         }
    215 
    216 
    217        /*
    218         WaypointController *newController = new WaypointController(en1->getContext());//
    219         newController->setAccuracy(3);
    220 
    221         for(int i =0; i < path.size(); ++i)
    222         {
    223 
    224             Model *wayPoint = new Model(en1->getContext());
    225             wayPoint->setMeshSource("cube.mesh");
    226             wayPoint->setPosition(path.at(i)->get3dcoordinate());
    227             wayPoint->setScale(0.2);
    228             newController->addWaypoint(wayPoint);
    229         }*/
     201                {
     202                en1->addWaypoint((path.at(i)));
     203                }
    230204    }
    231205
     
    234208
    235209    {
     210
    236211        Deathmatch::end();
    237 
    238212        ChatManager::message("Match is over! Gameover!");
    239     }
    240 
     213
     214    }
     215
     216    //not working yet
    241217    void TowerDefense::upgradeTower(int x,int y)
    242218    {/*
    243         const TowerCost upgradeCost = TDDefaultUpgradeCost;
     219        const int upgradeCost = 20;
    244220
    245221        if (!this->hasEnoughCreditForTower(upgradeCost))
     
    261237    }
    262238
    263 
     239    /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret")
     240    so towers have ability if the turrets
     241
     242    */
    264243    void TowerDefense::addTower(int x, int y)
    265244    {
     
    294273        orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl;
    295274
    296        
    297 
    298275       //Reduce credit
    299276        this->buyTower(towerCost);
    300 
    301277        towermatrix [x][y]=true;
    302278
    303 
    304   //    Create tower
     279        //Creates tower
    305280        TowerDefenseTower* towernew = new TowerDefenseTower(this->center_->getContext());
    306281        towernew->addTemplate("towerturret");
    307282        towernew->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 75);
    308283        towernew->setGame(this);
    309 
    310284    }
    311285
     
    314288        return ((this->getCredit()) >= towerCost);
    315289    }
     290
    316291
    317292    bool TowerDefense::hasEnoughCreditForUpgrade()
     
    329304        std::vector<TDCoordinate*> path;
    330305        path.push_back(coord1);
    331 
    332306        if(time>1 && TowerDefenseEnemyvector.size() < 30)
    333307        {
    334             addTowerDefenseEnemy(path, rand() %3 +1 );
    335             time = time-1;
    336         }
    337 
    338         Vector3* endpoint = new Vector3(500, 700, 150);
    339 
    340         for(int i =0; i < TowerDefenseEnemyvector.size(); ++i)
    341         {
    342 
    343                 //orxout() << TowerDefenseEnemyvector.at(i) << endl;
    344                 //continue;
    345 
    346                         //ArtificialController* controller = (ArtificialController*)this->getController();
     308                //adds different types of enemys depending on the WaveNumber
     309                addTowerDefenseEnemy(path, this->getWaveNumber() % 3 +1 );
     310                time = time-1;
     311        }
     312
     313                Vector3* endpoint = new Vector3(500, 700, 150);
     314                //if ships are at the end they get destroyed
     315                for(unsigned int i =0; i < TowerDefenseEnemyvector.size(); ++i)
     316                {
    347317                        if(TowerDefenseEnemyvector.at(i) != NULL && TowerDefenseEnemyvector.at(i)->isAlive())
    348                         {
    349                                 orxout() << "Variable i: " << i << endl;
    350 
    351                                 Vector3 ship = TowerDefenseEnemyvector.at(i)->getRVWorldPosition();
    352 
    353                                 float distance = ship.distance(*endpoint);
    354 
    355                                 //orxout() << "distance" << distance << endl;
    356                                 if(distance <50){
    357                                   //    orxout() << "ENEMY KILLED!!!!" << endl;
    358                                   TowerDefenseEnemyvector.at(i)->destroy();
     318                                {
     319                                //destroys enemys at the end of teh path and reduces the life by 1. no credits gifted
     320
     321                                        Vector3 ship = TowerDefenseEnemyvector.at(i)->getRVWorldPosition();
     322                                        float distance = ship.distance(*endpoint);
     323
     324                                        if(distance <50){
     325                                                TowerDefenseEnemyvector.at(i)->destroy();
     326                                                this->reduceLifes(1);
     327                                                this->buyTower(1);
     328                                                if (this->getLifes()==0)
     329                                                                {
     330                                                                    this->end();
     331                                                                }
     332                                        }
    359333                                }
    360334                        }
    361                         else
     335                        //goes thorugh vector to see if an enemy is still alive. if not next wave is launched
     336                        int count= 0;
     337                        for(unsigned int i =0; i < TowerDefenseEnemyvector.size(); ++i)
    362338                        {
    363                                 //TowerDefenseEnemyvector.erase(TowerDefenseEnemyvector.begin() +i);
     339                                if(TowerDefenseEnemyvector.at(i)!= NULL)
     340                                {
     341                                        ++count;
     342                                }
    364343                        }
    365                 }
    366 
    367         int count= 0;
    368         for(int i =0; i < TowerDefenseEnemyvector.size(); ++i)
    369         {
    370                 if(TowerDefenseEnemyvector.at(i)!= NULL)
    371                 {
    372                         ++count;
    373                 }
    374         }
    375 
    376         if(count== 0)
    377         {
    378                 time2 +=dt;
    379                 if(time2 > 10)
    380                 {
    381                         TowerDefenseEnemyvector.clear();
    382                         time=0;
    383                         time2=0;
    384                 }
    385         }
    386 
     344
     345                        if(count== 0)
     346                        {
     347                                time2 +=dt;
     348                                if(time2 > 10)
     349                                {
     350                                        TowerDefenseEnemyvector.clear();
     351                                        this->nextwave();
     352                                        time=0;
     353                                        time2=0;
     354                                }
     355                        }
    387356
    388357
Note: See TracChangeset for help on using the changeset viewer.