Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10172


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

final version for presentation

Location:
code/branches/towerdefenseHS14/src/modules/towerdefense
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/towerdefenseHS14/src/modules/towerdefense/TDEnemy.h

    r9272 r10172  
    55 *      Author: weigeltm
    66 */
    7 
     7/*
    88#ifndef TDENEMY_H_
    99#define TDENEMY_H_
     
    2424
    2525
    26 #endif /* TDENEMY_H_ */
     26#endif TDENEMY_H_ */
  • 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
  • code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefense.h

    r10159 r10172  
    4242#include "TowerDefenseEnemy.h"
    4343#include "util/Output.h"
    44 
    45 
    46  #include "TowerDefensePlayerStats.h"
     44#include "core/object/WeakPtr.h"
    4745
    4846namespace orxonox
     
    5654        std::vector<orxonox::WeakPtr<TowerDefenseEnemy> > TowerDefenseEnemyvector;
    5755        bool towermatrix[16][16];
    58         void addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr); 
     56        void addTowerDefenseEnemy(std::vector<TDCoordinate*> path, int templatenr);
    5957        virtual void start(); //<! The function is called when the gametype starts
    6058        virtual void end();
     
    108106        bool hasEnoughCreditForUpgrade();
    109107
     108
     109
    110110        std::vector<TowerTurret*> towers_;
    111111    };
  • code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.cc

    r10159 r10172  
    1212*/
    1313#include "TowerDefenseEnemy.h"
    14 
    1514#include "core/CoreIncludes.h"
    1615//#include "core/XMLPort.h"
     
    2928
    3029        this->setCollisionType(WorldEntity::Dynamic);
     30        //needed to keep track of the PlayerStats coded in TowerDefense.h
    3131        this->td = orxonox_cast<TowerDefense*>(this->getGametype().get());
    32         once_ = false;
    3332
    3433    }
    35 
    36     TowerDefenseEnemy::~TowerDefenseEnemy(){this->td->addCredit(20);}
     34    //add credit if enemy is destroyed
     35    TowerDefenseEnemy::~TowerDefenseEnemy(){
     36                this->td->addCredit(1);
     37    }
    3738
    3839    void TowerDefenseEnemy::addWaypoint(TDCoordinate* coord)
     
    4546    {
    4647        SUPER(TowerDefenseEnemy, tick, dt);
    47 
    48         //ArtificialController* controller = (ArtificialController*)this->getController();
    49         Vector3 ship = this->getRVWorldPosition();
    50         Vector3* endpoint = new Vector3(500, 700, 150);
    51 
    52         float distance = ship.distance(*endpoint);
    53 
    54         //orxout() << "distance" << distance << endl;
    55         if(distance < 50 && once_ == false){
    56                 this->td->reduceLifes(1);
    57                 once_=true;
    58                 orxout() << "ENEMY KILLED!!!!" << endl;
    59                 this->td->buyTower(20);
    60                 if (this->td->getLifes()==0)
    61                 {
    62                     this->td->end();
    63                 }
    64 
    65         }
    6648    }
    6749
  • code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseEnemy.h

    r10159 r10172  
    3232        class _TowerDefenseExport TowerDefenseEnemy : public SpaceShip
    3333        {
    34 
    3534        public:
    36 
    3735                TowerDefenseEnemy(Context* context);
    3836        virtual ~TowerDefenseEnemy();
     
    4745
    4846        private:
    49 
    5047        TowerDefense* td;
    5148        bool once_;
  • code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefenseHUDController.cc

    r10159 r10172  
    5252        const std::string& lifes = multi_cast<std::string>(this->td->getLifes());
    5353        const std::string& credits = multi_cast<std::string>(this->td->getCredit());
    54         const std::string& waves = multi_cast<std::string>(this->td->getWaveNumber());
     54        const std::string& wave = multi_cast<std::string>(this->td->getWaveNumber());
    5555
    5656        if(showlives == true)
     
    5959          this->setCaption(multi_cast<std::string>(credits));
    6060        else if(showwaves == true)
    61           this->setCaption(multi_cast<std::string>(waves));
     61          this->setCaption(multi_cast<std::string>(wave));
    6262
    6363
     
    8787                    }
    8888                }
    89             /*if (this->getOwner() != NULL && this->getOwner()->getGametype())
    90             {
    91                 this->owner_ = orxonox_cast<TowerDefense*>(this->getOwner()->getGametype().get());
    92             }
    93             else
    94             {
    95                 this->owner_ = NULL;
    96             }*/
    9789        }
    9890
  • code/branches/towerdefenseHS14/src/modules/towerdefense/TowerDefensePlayerStats.h

    r10159 r10172  
    2727 */
    2828
    29  /**
     29 /*
    3030    @brief
    3131        This manages the stats of the player. It is used by 'TowerDefense', the gametype
    3232
    3333    @ingroup TowerDefense
    34  */
     34
    3535
    3636
     
    8888}
    8989
    90 #endif /* _TowerDefensePlayerStats_H__ */
     90#endif _TowerDefensePlayerStats_H__ */
Note: See TracChangeset for help on using the changeset viewer.