[Orxonox-commit 3810] r8488 - code/branches/tetris/src/modules/tetris
youngk at orxonox.net
youngk at orxonox.net
Mon May 16 15:13:56 CEST 2011
Author: youngk
Date: 2011-05-16 15:13:56 +0200 (Mon, 16 May 2011)
New Revision: 8488
Modified:
code/branches/tetris/src/modules/tetris/Tetris.cc
code/branches/tetris/src/modules/tetris/Tetris.h
Log:
Created a skeleton for the position validation of a stone.
Modified: code/branches/tetris/src/modules/tetris/Tetris.cc
===================================================================
--- code/branches/tetris/src/modules/tetris/Tetris.cc 2011-05-16 11:39:51 UTC (rev 8487)
+++ code/branches/tetris/src/modules/tetris/Tetris.cc 2011-05-16 13:13:56 UTC (rev 8488)
@@ -89,14 +89,23 @@
TetrisStone* stone = this->activeStone_;
if(stone != NULL)
{
+ // Get the current position of the active stone
Vector3 position = stone->getPosition();
- if(position.x < this->center_->getStoneSize()/2.0)
+
+ if(position.x < this->center_->getStoneSize()/2.0) //!< If the stone touches the left edge of the level
position.x = this->center_->getStoneSize()/2.0;
- else if(position.x > (this->center_->getWidth()-0.5)*this->center_->getStoneSize())
+ else if(position.x > (this->center_->getWidth()-0.5)*this->center_->getStoneSize()) //!< If the stone touches the right edge of the level
position.x = (this->center_->getWidth()-0.5)*this->center_->getStoneSize();
-
- if(position.y < this->center_->getStoneSize()/2.0)
+
+ if(!this->correctStonePos(stone)) //!< If the stone touches another stone
{
+ stone->setVelocity(Vector3::ZERO);
+ this->createStone();
+ this->startStone();
+ }
+
+ if(position.y < this->center_->getStoneSize()/2.0) //!< If the stone has reached the bottom of the level
+ {
position.y = this->center_->getStoneSize()/2.0;
stone->setVelocity(Vector3::ZERO);
this->createStone();
@@ -221,6 +230,32 @@
/**
@brief
+ Validate the stone position.
+ @return
+ Returns whether the supplied stone is in the correct position.
+ */
+ bool Tetris::correctStonePos(TetrisStone* stone)
+ {
+ for(std::vector<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
+ {
+ TetrisStone* currentStone = it->_Ptr(); //!< Gives access to the current stone in the list
+ Vector3 currentStonePosition = it->_Ptr()->getPosition(); //!< Saves the position of the currentStone
+ Vector3 stonePosition = stone->getPosition(); //!< Saves the position of the supplied stone
+
+ // @TODO: Use the TetrisStone member functions to check both stones for an overlap.
+ // Also make sure to correct the stone position accordingly.
+ //
+ // This case applies if the stones overlap completely
+ //if((stonePosition.x == currentStonePosition.x) && (stonePosition.y == currentStonePosition.y))
+ // This case applies if the stones overlap partially vertically
+ //if(stonePosition.y - stone->getHeight()/2 < currentStonePosition.y + currentStone->getHeight()/2)
+
+
+ }
+ }
+
+ /**
+ @brief
Get the player.
@return
Returns a pointer to the player. If there is no player, NULL is returned.
Modified: code/branches/tetris/src/modules/tetris/Tetris.h
===================================================================
--- code/branches/tetris/src/modules/tetris/Tetris.h 2011-05-16 11:39:51 UTC (rev 8487)
+++ code/branches/tetris/src/modules/tetris/Tetris.h 2011-05-16 13:13:56 UTC (rev 8488)
@@ -79,6 +79,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.
+ bool correctStonePos(TetrisStone* stone); //!< Check whether the supplied stone is in an allowed position
PlayerInfo* player_;
More information about the Orxonox-commit
mailing list