Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9329


Ignore:
Timestamp:
Jul 22, 2012, 6:46:05 PM (12 years ago)
Author:
landauf
Message:

fixed collision bug in tetris which made stones overlap in some cases (especially with low fps or high game speed)

Location:
code/branches/presentation2012merge/src/modules/tetris
Files:
2 edited

Legend:

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

    r9328 r9329  
    118118        {
    119119            this->endGameCriteria_ += dt;
    120             if(!this->isValidBrickPosition(this->activeBrick_, this->activeBrick_->getPosition()))
     120            if(!this->isValidBrickPosition(this->activeBrick_))
    121121            {
    122122                for (unsigned int i = 0; i < this->activeBrick_->getNumberOfStones(); i++)
     
    195195        assert(stone);
    196196
    197         // we use a reverse iterator because we have to check for collisions with the topmost stones first
    198         for(std::list<SmartPtr<TetrisStone> >::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
     197        // check for collisions with all stones
     198        for(std::list<SmartPtr<TetrisStone> >::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
    199199        {
    200200            //Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount());
     
    231231     *
    232232     */
    233     bool Tetris::isValidBrickPosition(TetrisBrick* brick, const Vector3& position)
     233    bool Tetris::isValidBrickPosition(TetrisBrick* brick)
    234234    {
    235235        assert(brick);
    236236
     237        const Vector3& brickPosition = this->activeBrick_->getPosition();
     238
     239        // check all stones in the brick
    237240        for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
    238241        {
    239242            TetrisStone* stone = brick->getStone(i);
    240             Vector3 stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
    241             if(! this->isValidStonePosition(stone, position + stonePosition) )
     243            const Vector3& stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
     244            if(! this->isValidStonePosition(stone, brickPosition + stonePosition) )
     245            {
     246                // recurse because all stones have to checked again after the brick was re-positioned
     247                this->isValidBrickPosition(brick);
    242248                return false;
     249            }
    243250        }
    244251        return true;
  • code/branches/presentation2012merge/src/modules/tetris/Tetris.h

    r9328 r9329  
    8484            void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
    8585            bool isValidStonePosition(TetrisStone* stone, const Vector3& position);
    86             bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position);
     86            bool isValidBrickPosition(TetrisBrick* brick);
    8787            void findFullRows(void);
    8888            void clearRow(unsigned int row);
Note: See TracChangeset for help on using the changeset viewer.