[Orxonox-commit 3891] r8565 - code/branches/presentation/src/modules/tetris

dafrick at orxonox.net dafrick at orxonox.net
Tue May 24 21:59:01 CEST 2011


Author: dafrick
Date: 2011-05-24 21:59:01 +0200 (Tue, 24 May 2011)
New Revision: 8565

Modified:
   code/branches/presentation/src/modules/tetris/Tetris.cc
   code/branches/presentation/src/modules/tetris/Tetris.h
Log:
Fixing bug in tetris.


Modified: code/branches/presentation/src/modules/tetris/Tetris.cc
===================================================================
--- code/branches/presentation/src/modules/tetris/Tetris.cc	2011-05-24 19:24:39 UTC (rev 8564)
+++ code/branches/presentation/src/modules/tetris/Tetris.cc	2011-05-24 19:59:01 UTC (rev 8565)
@@ -90,7 +90,7 @@
 
         if(this->activeStone_ != NULL)
         {
-            std::pair<bool, TetrisStone*> valid = this->isValidMove(this->activeStone_, this->activeStone_->getPosition());
+            std::pair<bool, TetrisStone*> valid = this->isValidStonePosition(this->activeStone_, this->activeStone_->getPosition());
             if(!valid.first)
             {
                 this->activeStone_->setVelocity(Vector3::ZERO);
@@ -115,11 +115,6 @@
             valid.first = false;
         else if(position.x > (this->center_->getWidth()-0.5)*this->center_->getStoneSize()) //!< If the stone touches the right edge of the level
             valid.first = false;
-        else if(position.y < this->center_->getStoneSize()/2.0) //!< If the stone has reached the bottom of the level
-        {
-            valid.first = false;
-            stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0, stone->getPosition().z));
-        }
 
         for(std::vector<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
         {
@@ -136,7 +131,31 @@
                 valid.first = false;
                 return valid;
             }// This case applies if the stones overlap completely
-            else if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
+        }
+
+        return valid;
+    }
+
+    std::pair<bool, TetrisStone*> Tetris::isValidStonePosition(TetrisStone* stone, const Vector3& position)
+    {
+        assert(stone);
+
+        std::pair<bool, TetrisStone*> valid = std::pair<bool, TetrisStone*>(true, NULL);
+
+        if(position.y < this->center_->getStoneSize()/2.0) //!< If the stone has reached the bottom of the level
+        {
+            valid.first = false;
+            stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0, stone->getPosition().z));
+        }
+
+        for(std::vector<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
+        {
+            if(stone == *it)
+                continue;
+
+            const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
+
+            if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
             {
                 valid.first = false;
                 valid.second = *it;

Modified: code/branches/presentation/src/modules/tetris/Tetris.h
===================================================================
--- code/branches/presentation/src/modules/tetris/Tetris.h	2011-05-24 19:24:39 UTC (rev 8564)
+++ code/branches/presentation/src/modules/tetris/Tetris.h	2011-05-24 19:59:01 UTC (rev 8565)
@@ -77,6 +77,7 @@
             void startStone(void); //!< Starts with the first stone.
             void createStone(void);
             void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
+            std::pair<bool, TetrisStone*> isValidStonePosition(TetrisStone* stone, const Vector3& position);
             
             PlayerInfo* player_;
 




More information about the Orxonox-commit mailing list