Changeset 9802 for code/trunk/src
- Timestamp:
- Nov 21, 2013, 10:11:27 PM (11 years ago)
- Location:
- code/trunk/src/modules/tetris
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/tetris/Tetris.cc
r9801 r9802 183 183 184 184 185 186 bool Tetris::isValidStonePosition(TetrisStone* stone, const Vector3& position) 185 /** 186 * @brief Returns true, if NO collision was detected. 187 * Else returns false and the active brick is repositioned as side-effect. 188 */ 189 bool Tetris::checkStoneStoneCollision(TetrisStone* stone, const Vector3& position) 187 190 { 188 191 assert(stone); … … 193 196 //Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount()); 194 197 const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone 195 //!< Saves the position of the currentStone196 198 197 199 //filter out cases where the falling stone is already below a steady stone … … 208 210 } 209 211 210 // after we checked for collision with all stones, we also check for collision with the bottom 212 return true; 213 } 214 215 /** 216 * @brief Returns true, if NO collision was detected. 217 * Else returns false and the active brick is repositioned as side-effect. 218 */ 219 bool Tetris::checkStoneBottomCollision(TetrisStone* stone, const Vector3& position) 220 { 221 assert(stone); 211 222 if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level 212 223 { … … 220 231 return false; 221 232 } 222 223 233 return true; 224 234 } 235 225 236 /** 226 237 * @brief This function determines wether a brick touches another brick or the ground. … … 238 249 TetrisStone* stone = brick->getStone(i); 239 250 const Vector3& stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()); 240 if(! this->isValidStonePosition(stone, brickPosition + stonePosition) ) 241 { 242 // recurse because all stones have to checked again after the brick was re-positioned 251 if(! this->checkStoneStoneCollision(stone, brickPosition + stonePosition) ) 252 { 243 253 return false; 244 254 } 245 255 } 256 // check all stones in the brick 257 for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ ) 258 { 259 TetrisStone* stone = brick->getStone(i); 260 const Vector3& stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()); 261 if(! this->checkStoneBottomCollision(stone, brickPosition + stonePosition) ) 262 { 263 return false; 264 } 265 } 266 246 267 return true; 247 268 } -
code/trunk/src/modules/tetris/Tetris.h
r9667 r9802 83 83 void createBrick(void); 84 84 void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats. 85 bool isValidStonePosition(TetrisStone* stone, const Vector3& position); 85 bool checkStoneStoneCollision(TetrisStone* stone, const Vector3& position); 86 bool checkStoneBottomCollision(TetrisStone* stone, const Vector3& position); 86 87 bool isValidBrickPosition(TetrisBrick* brick); 87 88 void findFullRows(void);
Note: See TracChangeset
for help on using the changeset viewer.