Changeset 9084 for code/branches/pCuts/src/modules/tetris/Tetris.cc
- Timestamp:
- Apr 12, 2012, 7:05:57 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pCuts/src/modules/tetris/Tetris.cc
r9082 r9084 130 130 /** 131 131 @brief 132 Check for each stone in a brick wetherit is moved the right way.133 */ 134 bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position )132 Check for each stone in a brick if it is moved the right way. 133 */ 134 bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation = false) 135 135 { 136 136 assert(brick); … … 139 139 { 140 140 TetrisStone* stone = brick->getStone(i); 141 if(! this->isValidMove(stone, position + stone->getPosition())) // wrong position?? 141 Vector3 stonePosition; 142 if(isRotation) 143 stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()+1); 144 else 145 stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()); 146 147 /*orxout()<< "stoneRelativePoistion: " << stonePosition << endl; 148 orxout()<< "stoneTotalPoistion : " << position + stonePosition << endl;*/ 149 150 if(! this->isValidMove(stone, position + stonePosition )) // wrong position?? 151 { 142 152 return false; 143 orxout()<< "stoneRelativePoistion: " << stone->getPosition() << endl; 144 orxout()<< "stoneTotalPoistion: " << position + stone->getPosition() << endl; 153 } 145 154 } 146 155 return true; … … 159 168 if(this->activeBrick_->contains(*it)) 160 169 continue; 161 162 const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone 170 //TODO: is this rotation correct ?? 171 Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount()); 172 //!< Saves the position of the currentStone 163 173 164 174 if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize())) 165 { 175 {//TODO: Why are such events not detected ?? 176 orxout()<< "YEAY !!"<<endl; 166 177 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->getPosition().z)); 167 178 return false; … … 171 182 // after we checked for collision with all stones, we also check for collision with the bottom 172 183 if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level 173 {//TODO: correct positioning !! 174 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f, this->activeBrick_->getPosition().z)); 184 { 185 int yOffset = stone->getPosition().y;//calculate offset 186 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f+yOffset, this->activeBrick_->getPosition().z)); 175 187 return false; 176 188 } … … 186 198 { 187 199 TetrisStone* stone = brick->getStone(i); 188 if(! this->isValidStonePosition(stone, position + stone->getPosition()) ) // wrong position?? 200 Vector3 stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()); 201 if(! this->isValidStonePosition(stone, position + stonePosition) ) 189 202 return false; 190 203 } 191 204 return true; 192 205 } 206 207 /** 208 @brief 209 Nasty function that allocates memory!! it rolls a vector 90° * amount 210 */ 211 Vector3 Tetris::rotateVector(Vector3 position, unsigned int amount) 212 { 213 214 int temp = 0; 215 for(unsigned int i = 0; i < amount; i++) 216 { 217 temp = position.x; 218 position.x = -position.y; 219 position.y = temp; 220 } 221 return position; 193 222 } 194 223
Note: See TracChangeset
for help on using the changeset viewer.