Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 26, 2015, 10:16:26 PM (9 years ago)
Author:
fvultier
Message:

There is now a cube that can be moved on the playground using the arrow keys.

File:
1 edited

Legend:

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

    r10397 r10406  
    3535 * pawnKilled() // wird aufgerufen, wenn ein Pawn stirbt (z.B: wenn )
    3636 * playerScored() // kann man aufrufen um dem Spieler Punkte zu vergeben.
    37  *
    3837 *
    3938 *
     
    110109
    111110        selecter = NULL;
    112 
    113 
     111        this->player_ = NULL;       
    114112        this->setHUDTemplate("TowerDefenseHUD");
    115113        this->nextwaveTimer_.setTimer(10, false, createExecutor(createFunctor(&TowerDefense::nextwave, this)));
     
    145143    void TowerDefense::start()
    146144    {
     145        if (center_ != NULL) // There needs to be a TowerDefenseCenterpoint, i.e. the area the game takes place.
     146        {
     147            if (selecter == NULL)
     148            {
     149                selecter = new TowerDefenseSelecter(this->center_->getContext());               
     150            }
     151            selecter->addTemplate(center_->getSelecterTemplate());
     152            center_->attach(selecter);
     153        }
     154        else // If no centerpoint was specified, an error is thrown and the level is exited.
     155        {
     156            orxout(internal_error) << "Jump: No Centerpoint specified." << endl;
     157            return;
     158        }
    147159
    148160        TeamDeathmatch::start();
    149161
    150 // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path
     162        // Waypoints: [1,3] [10,3] [10,11] [13,11] -> add the points to a matrix so the player cant place towers on the path
    151163        for (int i=0; i < 16 ; i++)
    152164        {
     
    158170        }
    159171
    160         selecter = new TowerDefenseSelecter(this->center_->getContext());
     172       
     173
     174        if (player_ != NULL)
     175        {
     176            //this->player_->startControl(selecter);
     177        }
     178        else
     179        {
     180            orxout() << "player=NULL" << endl;
     181        }
     182
    161183
    162184        Model* dummyModel = new Model(this->center_->getContext());
     
    219241        en1->setTeam(2);
    220242        en1->getController();
    221         en1->setPosition(path.at(0)->get3dcoordinate());
     243        en1->setPosition(path.at(0)->get3dcoordinate());       
    222244        TowerDefenseEnemyvector.push_back(en1);
    223245
     
    237259    }
    238260
     261    void TowerDefense::spawnPlayer(PlayerInfo* player)
     262    {
     263        assert(player);
     264        this->player_ = player;
     265
     266        if (selecter->getPlayer() == NULL)
     267        {
     268            this->player_ = player;
     269            player->startControl(selecter);
     270            players_[player].state_ = PlayerState::Alive;
     271        }
     272    }
     273
     274    /**
     275    @brief
     276        Get the player.
     277    @return
     278        Returns a pointer to the player. If there is no player, NULL is returned.
     279    */
     280    PlayerInfo* TowerDefense::getPlayer(void) const
     281    {
     282        return this->player_;
     283    }
     284
    239285    //not working yet
    240286    void TowerDefense::upgradeTower(int x,int y)
    241287    {
     288        TDCoordinate* coord = new TDCoordinate(x,y);
     289        x = coord->GetX();
     290        y = coord->GetY();
     291       
    242292        const int upgradeCost = 20;
    243293
     
    266316    /*adds Tower at Position (x,y) and reduces credit and adds the point to the towermatrix. template ("towerturret")
    267317    so towers have ability if the turrets
    268 
    269318    */
     319
    270320    void TowerDefense::addTower(int x, int y)
    271     {
     321    {       
     322        TDCoordinate* coord = new TDCoordinate(x,y);
     323        x = coord->GetX();
     324        y = coord->GetY();
     325
    272326        const int towerCost = 20;
    273327
     
    291345        int tileScale = (int) this->center_->getTileScale();
    292346
    293         if (x > 15 || y > 15 || x < 0 || y < 0)
     347        /*if (x > 15 || y > 15 || x < 0 || y < 0)
    294348        {
    295349            //Hard coded: TODO: let this depend on the centerpoint's height, width and fieldsize (fieldsize doesn't exist yet)
    296350            orxout() << "Can not add Tower: x and y should be between 0 and 15" << endl;
    297351            return;
    298         }
    299 
    300         orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl;
    301 
     352        }*/
     353
     354        //orxout() << "Will add tower at (" << (x-8) * tileScale << "," << (y-8) * tileScale << ")" << endl;
     355        orxout() << "Will add tower at (" << x << "," << y << ")" << endl;
    302356
    303357
    304358        //Create Model
    305         Model* newtowermodel = new Model(this->center_->getContext());
    306         newtowermodel->setMeshSource("Tower.mesh");
    307         newtowermodel->setScale(45);
    308         newtowermodel->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 50);
    309 
    310 
     359        Model* newTowerModel = new Model(this->center_->getContext());
     360        newTowerModel->setMeshSource("Tower.mesh");
     361        newTowerModel->setScale(45);
     362        newTowerModel->setPosition(static_cast<float>((x-8) * tileScale), static_cast<float>((y-8) * tileScale), 50);
    311363
    312364        //Creates tower
     
    318370        //Reduce credit
    319371         this->buyTower(towerCost);
    320          towerModelMatrix [x][y]= newtowermodel;
     372         towerModelMatrix [x][y]= newTowerModel;
    321373         towerTurretMatrix [x][y]= towernew;
    322     }
     374    }   
    323375
    324376    bool TowerDefense::hasEnoughCreditForTower(int towerCost)
Note: See TracChangeset for help on using the changeset viewer.