[Orxonox-commit 3987] r8661 - code/branches/presentation/src/modules/tetris
landauf at orxonox.net
landauf at orxonox.net
Sun May 29 17:01:53 CEST 2011
Author: landauf
Date: 2011-05-29 17:01:53 +0200 (Sun, 29 May 2011)
New Revision: 8661
Modified:
code/branches/presentation/src/modules/tetris/Tetris.cc
Log:
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)
Modified: code/branches/presentation/src/modules/tetris/Tetris.cc
===================================================================
--- code/branches/presentation/src/modules/tetris/Tetris.cc 2011-05-29 14:02:07 UTC (rev 8660)
+++ code/branches/presentation/src/modules/tetris/Tetris.cc 2011-05-29 15:01:53 UTC (rev 8661)
@@ -126,14 +126,9 @@
{
assert(stone);
- if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
+ // we use a reverse iterator because we have to check for collisions with the topmost stones first
+ for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
{
- stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0f, stone->getPosition().z));
- return false;
- }
-
- for(std::vector<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
- {
if(stone == *it)
continue;
@@ -146,6 +141,13 @@
}// This case applies if the stones overlap partially vertically
}
+ // after we checked for collision with all stones, we also check for collision with the bottom
+ if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
+ {
+ stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0f, stone->getPosition().z));
+ return false;
+ }
+
return true;
}
More information about the Orxonox-commit
mailing list