Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 29, 2011, 5:01:53 PM (14 years ago)
Author:
landauf
Message:

fixed two possible causes which stacked multiple tetris stones at the same position (happens if a stone moves so fast that it "tunnels" the topmost stone. before the collisions were checked from lower to upper, now its the other way round, which fixes the issue)

File:
1 edited

Legend:

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

    r8645 r8661  
    127127        assert(stone);
    128128
    129         if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
    130         {
    131             stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0f, stone->getPosition().z));
    132             return false;
    133         }
    134 
    135         for(std::vector<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     129        // we use a reverse iterator because we have to check for collisions with the topmost stones first
     130        for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
    136131        {
    137132            if(stone == *it)
     
    145140                return false;
    146141            }// This case applies if the stones overlap partially vertically
     142        }
     143
     144        // after we checked for collision with all stones, we also check for collision with the bottom
     145        if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
     146        {
     147            stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0f, stone->getPosition().z));
     148            return false;
    147149        }
    148150
Note: See TracChangeset for help on using the changeset viewer.