Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9087 for code


Ignore:
Timestamp:
Apr 14, 2012, 5:45:44 PM (13 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.

Location:
code/branches/pCuts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pCuts/data/levels/tetris.oxw

    r9085 r9087  
    2727      <Model position="0,0,0" mesh="crate.mesh" scale=1 />
    2828    </attached>
    29     <!--collisionShapes>
    30       <BoxCollisionShape position="0,0,0" halfExtents="5,5,5" />
    31     </collisionShapes-->
    3229  </TetrisStone>
    3330</Template>
     
    3936    <camerapositions>
    4037      <CameraPosition position="55,75,200" absolute=true />
    41       <CameraPosition position="0,50,160" drag=true mouselook=true />
    42       <CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true />
     38      <!--CameraPosition position="0,50,160" drag=true mouselook=true /-->
     39      <!--CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true /-->
    4340    </camerapositions>
    4441  </TetrisBrick>
  • 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}
  • code/branches/pCuts/src/modules/tetris/Tetris.h

    r9086 r9087  
    8585            bool isValidStonePosition(TetrisStone* stone, const Vector3& position);
    8686            bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position);
    87             void clearFullRow(void);
     87            void findFullRows(void);
     88            void clearRow(unsigned int row);
    8889
    8990           
     
    9798           
    9899            Timer starttimer_; //!< A timer to delay the start of the game.
     100            float endGameCriteria_; //<! Works as a timer which is resetted, whenever a brick is created.
    99101    };
    100102}
  • code/branches/pCuts/src/modules/tetris/TetrisBrick.cc

    r9086 r9087  
    4040#include "TetrisStone.h"
    4141#include "Tetris.h"
     42#include "util/Math.h"
    4243
    4344namespace orxonox
     
    5253    {
    5354        RegisterObject(TetrisBrick);
    54 
    55         this->shapeIndex_ = 4; //<! TODO: random number between 0 and 7
     55        this->shapeIndex_ = static_cast<unsigned int>(rnd(7.0f)); //<! random number between 0 and 7
    5656        this->stonesPerBrick_ = 4; //<! most tetris bricks is formed by 4 stones
    5757        this->delay_ = false;
     
    105105    void TetrisBrick::formBrick(TetrisStone* stone, unsigned int i)
    106106    {
    107         if(i != 0 && this->shapeIndex_ == 0)
    108             orxout() << "So it has come to this in TetrisBrick.cc"<< endl;
    109107        if(i == 0) //setting the first stone as
    110108        {
Note: See TracChangeset for help on using the changeset viewer.