Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 14, 2012, 5:45:44 PM (12 years ago)
Author:
jo
Message:

Still a long way to go. A short todo list can be found at the beginning of Tetric.cc. A first, buggy clear-row function has been implemented.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pCuts/src/modules/tetris/Tetris.cc

    r9086 r9087  
    2323 *      ...
    2424 *   Co-authors:
    25  *      ...
    26  *
     25 *      Johannes Ritz
     26 *
     27 *BUG a) double stone model (@ brick's location the stone's model is duplicated. Why does the brick have a model attached to it.)
     28 *BUG b) the brick is set the wrong way after a (brick-brick) collision, if the brick was turned
     29 *BUG c) destroying the old stones causes segfault -> WeakPointer as solution ?
     30 *BUG
     31 *
     32 *TASK a) give points for winning
     33 *TASK b) write a hud (show points gained; new brick)
     34 *TASK c) end the game in a nicer way
     35 *TASK d) save the highscore
     36 *TASK e) eye candy
    2737 */
    2838
     
    6575
    6676        this->player_ = NULL;
     77        this->endGameCriteria_ = 0.0f;
    6778    }
    6879
     
    94105        SUPER(Tetris, tick, dt);
    95106
    96         if(this->activeBrick_ != NULL)
    97         {
     107        if((this->activeBrick_ != NULL)&&(!this->hasEnded()))
     108        {
     109                this->endGameCriteria_ += dt;
    98110            if(!this->isValidBrickPosition(this->activeBrick_, this->activeBrick_->getPosition()))
    99111            {
     
    101113                this->activeBrick_->releaseStones(this->center_);
    102114                //delete this->activeBrick_; //releasing the memory
     115                this->findFullRows();
     116                if(this->endGameCriteria_ < 0.1f) //end game if two bricks are created within a 0.1s interval.
     117                    this->end();
    103118                this->createBrick();
    104119                this->startBrick();
     120                this->endGameCriteria_ = 0.0f;
    105121            }
    106122        }
     
    257273    void Tetris::end()
    258274    {
     275        this->activeBrick_->setVelocity(Vector3::ZERO);
    259276        this->cleanup();
    260277
     
    366383    @brief Manage score.
    367384    */
    368     void Tetris::clearFullRow()
    369     {
     385    void Tetris::findFullRows()
     386    {
     387        unsigned int correctPosition = 0;
     388                orxout()<< "clear full rows ************ " <<endl;
    370389        unsigned int stonesPerRow = 0;
    371         for (unsigned int row = 0; row < this->center_->getHeight()/this->center_->getStoneSize(); row++)
     390        for (unsigned int row = 0; row < this->center_->getHeight(); row++)
    372391        {
    373392            stonesPerRow = 0;
    374393            for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
    375394            {
    376                 if((*it)->getPosition().y == row)
     395                correctPosition = static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize());
     396                if(correctPosition == row)
    377397                        stonesPerRow++;
    378                 if(stonesPerRow == this->center_->getWidth()/this->center_->getStoneSize())
    379                     orxout()<< "CANDIDATE FOUND in row " << row <<endl;
     398                if(stonesPerRow == this->center_->getWidth())
     399                    {orxout()<< "CANDIDATE FOUND in row " << row <<endl; clearRow(row);}
    380400            }
    381401
     
    383403    }
    384404
     405    void Tetris::clearRow(unsigned int row)
     406    {//std::vector<int>::iterator it = v.begin()
     407        for(std::vector<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     408        {
     409            if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) == row)
     410                (*it)->setPosition(Vector3(-10,-10,0));
     411                //{(*it)->destroy(); this->stones_.erase(it); orxout()<< "destroy row "<<endl;}//experimental
     412        }
     413        for(std::vector<TetrisStone*>::const_reverse_iterator it2 = this->stones_.rbegin(); it2 != this->stones_.rend(); ++it2)
     414        {
     415            /*if(static_cast<unsigned int>(((*it2)->getPosition().y - 5)/this->center_->getStoneSize()) > row)
     416                (*it2)->setPosition((*it2)->getPosition()-Vector3(0,1,0));//*/
     417        }
     418
     419    }
     420
     421
    385422}
Note: See TracChangeset for help on using the changeset viewer.