Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9086


Ignore:
Timestamp:
Apr 14, 2012, 3:32:56 PM (12 years ago)
Author:
jo
Message:

Tetris contais almost the same features as before introducing bricks. Two bugs are still left. And the clear row feature has to be implemented.

Location:
code/branches/pCuts/src/modules/tetris
Files:
3 edited

Legend:

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

    r9085 r9086  
    122122
    123123            const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
    124             orxout()<< "position.x: " << position.x << endl;
    125             orxout()<< "currentStonePosition.x: " << currentStonePosition.x << endl;
    126             if(position.x == currentStonePosition.x)
    127                 orxout()<< "NON Valid Move Candidate" <<endl;
    128124
    129125            if((position.x == currentStonePosition.x) && abs(position.y-currentStonePosition.y) < this->center_->getStoneSize())
     
    174170            const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
    175171            //!< Saves the position of the currentStone
    176             if(position.x == currentStonePosition.x)
     172
     173            if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
    177174            {
    178                 orxout()<< "candidate found" << endl;
    179                 orxout()<< "position.y: "<< position.y << endl;
    180                 orxout()<< "urrentStonePosition.y: " << currentStonePosition.y << endl;
    181             }
    182 
    183             if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
    184             {//TODO: Why are such events not detected ??
    185              // Because currentStonePosition.x isn't calculated globally, but locally
    186                 orxout()<< "YEAY !!"<<endl;
    187175                this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->getPosition().z));
    188176                return false;
     
    316304            // Get camera settings
    317305            cameraIndex = this->activeBrick_->getCurrentCameraIndex();
    318             orxout() << "cameraIndex: " << this->activeBrick_->getCurrentCameraIndex() << endl;
    319306            this->player_->stopControl();
    320307        }
     
    325312        this->player_->startControl(this->activeBrick_);
    326313        this->activeBrick_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
    327         orxout() << "velocity: " << this->center_->getStoneSpeed() << endl;
    328314        this->activeBrick_->setCameraPosition(cameraIndex);
    329315    }
     
    376362    }
    377363
     364    /**
     365    @brief Check each row if it is full. Remove all full rows. Let all stones above the deleted row sink down.
     366    @brief Manage score.
     367    */
     368    void Tetris::clearFullRow()
     369    {
     370        unsigned int stonesPerRow = 0;
     371        for (unsigned int row = 0; row < this->center_->getHeight()/this->center_->getStoneSize(); row++)
     372        {
     373            stonesPerRow = 0;
     374            for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
     375            {
     376                if((*it)->getPosition().y == row)
     377                        stonesPerRow++;
     378                if(stonesPerRow == this->center_->getWidth()/this->center_->getStoneSize())
     379                    orxout()<< "CANDIDATE FOUND in row " << row <<endl;
     380            }
     381
     382        }
     383    }
     384
    378385}
  • code/branches/pCuts/src/modules/tetris/Tetris.h

    r9084 r9086  
    7373            bool isValidMove(TetrisStone* stone, const Vector3& position);
    7474            bool isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation);
     75            Vector3 rotateVector(Vector3 position, unsigned int amount);
    7576
    7677        protected:
     
    8485            bool isValidStonePosition(TetrisStone* stone, const Vector3& position);
    8586            bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position);
    86             Vector3 rotateVector(Vector3 position, unsigned int amount);
     87            void clearFullRow(void);
     88
    8789           
    8890            PlayerInfo* player_;
  • code/branches/pCuts/src/modules/tetris/TetrisBrick.cc

    r9085 r9086  
    177177        return NULL;
    178178    }
    179 
     179//TODO: refactor this function; is not needed if brickstones are added to Tetris::stones_ after collision.
    180180    bool TetrisBrick::contains(TetrisStone* stone)
    181181    {
     
    241241        this->setVelocity(0.0f, 0.0f, 0.0f);
    242242    }
     243
    243244    /**
    244245    @brief
     
    247248    void TetrisBrick::releaseStones(TetrisCenterpoint* center)
    248249    {
     250        assert(this->tetris_);
    249251        for(unsigned int i = 0; i < brickStones_.size(); i++)
    250252        {
    251             //this->brickStones_[i]->detachFromParent();
    252 
    253             //this->brickStones_[i]->detach(this);
    254             //this->brickStones_[i]->attach(center);
     253            this->brickStones_[i]->detachFromParent();
     254            this->brickStones_[i]->attachToParent(center);
     255            this->brickStones_[i]->setPosition(this->getPosition()+this->tetris_->rotateVector(this->brickStones_[i]->getPosition(),this->rotationCount_ ));
    255256        }
    256257
Note: See TracChangeset for help on using the changeset viewer.