Changeset 9092 for code/branches/pCuts/src/modules/tetris
- Timestamp:
- Apr 17, 2012, 11:51:21 PM (13 years ago)
- Location:
- code/branches/pCuts/src/modules/tetris
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pCuts/src/modules/tetris/CMakeLists.txt
r9090 r9092 12 12 LINK_LIBRARIES 13 13 orxonox 14 overlays 14 15 SOURCE_FILES ${TETRIS_SRC_FILES} 15 16 ) -
code/branches/pCuts/src/modules/tetris/Tetris.cc
r9090 r9092 26 26 * 27 27 * 28 *BUG b) the falling brick is set the wrong way after a (brick-brick) collision, if the falling brick was turned29 28 *BUG c) destroying the old stones causes segfault -> WeakPointer as solution ? 30 29 *BUG d) wrong collision detection: sometimes stones "bounce off" 31 *BUG e) multiple rows are not cleared in one round 32 * 33 * 34 *TASK b) write a hud (show points gained; new brick) 30 * 31 * 35 32 *TASK c) end the game in a nicer way 36 33 *TASK d) save the highscore … … 64 61 @brief 65 62 Constructor. Registers and initializes the object. 63 @ingroup Tetris 66 64 */ 67 65 Tetris::Tetris(BaseObject* creator) : Deathmatch(creator) … … 77 75 this->player_ = NULL; 78 76 this->endGameCriteria_ = 0.0f; 77 this->setHUDTemplate("TetrisHUD"); 78 this->futureBrick_ = NULL; 79 79 } 80 80 … … 158 158 { 159 159 TetrisStone* stone = brick->getStone(i); 160 Vector3 stonePosition; 160 Vector3 stonePosition; //the current stone's offset to position 161 161 if(isRotation) 162 162 stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()+1); … … 164 164 stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()); 165 165 166 if(! this->isValidMove(stone, position + stonePosition )) // wrong position??166 if(! this->isValidMove(stone, position + stonePosition )) 167 167 { 168 168 return false; 169 } 170 171 //catch illegal rotation (such that collisions with ground are not permitted) 172 if(isRotation) 173 { 174 if((position + stonePosition).y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level 175 { 176 return false; 177 } 169 178 } 170 179 } … … 193 202 if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize())) 194 203 { 195 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->getPosition().z)); 204 int y_offset = static_cast<int>((this->activeBrick_->getPosition().y-currentStonePosition.y+10)/10)*10 + currentStonePosition.y; 205 if(y_offset < 0) //filter out extreme cases (very rare bug) 206 y_offset = 0; 207 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, y_offset, this->activeBrick_->getPosition().z)); 196 208 return false; 197 209 }// This case applies if the stones overlap partially vertically … … 201 213 if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level 202 214 { 203 int yOffset = stone->getPosition().y;//calculate offset 204 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f+yOffset, this->activeBrick_->getPosition().z)); 215 int yOffset = stone->getPosition().y + this->center_->getStoneSize()/2.0f;//calculate offset 216 if(yOffset < 0) //catch brake-throughs 217 yOffset = 0; 218 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, yOffset, this->activeBrick_->getPosition().z)); 205 219 return false; 206 220 } … … 208 222 return true; 209 223 } 210 224 /** 225 * @brief This function determines wether a brick touches another brick or the ground. 226 * 227 */ 211 228 bool Tetris::isValidBrickPosition(TetrisBrick* brick, const Vector3& position) 212 229 { … … 247 264 if (this->center_ != NULL) // There needs to be a TetrisCenterpoint, i.e. the area the game takes place. 248 265 { 266 // Create the futureBrick_ 267 this->createBrick(); 249 268 // Create the first brick. 250 269 this->createBrick(); … … 343 362 void Tetris::createBrick(void) //TODO: random rotation offset between 0 and 3 (times 90°) 344 363 { 345 // Create a new brick and add it to the list of bricks && to the list of stones. 346 TetrisBrick* brick = new TetrisBrick(this->center_); 347 this->bricks_.push_back(brick); 348 for (unsigned int i = 0; i < brick->getNumberOfStones(); i++) 349 { 350 this->stones_.push_back(brick->getStone(i)); 351 } 364 // Use the futureBrick_ as new currentBrick by setting its position and storing it in this->bricks 365 if(this->futureBrick_ != NULL) 366 { 367 for (unsigned int i = 0; i < this->futureBrick_->getNumberOfStones(); i++) 368 { 369 this->stones_.push_back(this->futureBrick_->getStone(i)); 370 } 371 float xPos = (this->center_->getWidth()/2 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize(); 372 float yPos = (this->center_->getHeight()-0.5f)*this->center_->getStoneSize(); 373 this->futureBrick_->setPosition(xPos, yPos, 0.0f); 374 this->bricks_.push_back(this->futureBrick_); 375 } 376 // create new futureBrick_ 377 this->futureBrick_ = new TetrisBrick(this->center_); 378 352 379 353 380 // Apply the stone template to the stone. 354 brick->addTemplate(this->center_->getBrickTemplate());355 356 // Attach the brick to the Centerpoint and set the position of the brick to be at the top middle.357 this->center_->attach( brick);358 float xPos = (this->center_->getWidth() /2+ ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();359 float yPos = (this->center_->getHeight()- 0.5f)*this->center_->getStoneSize();360 brick->setPosition(xPos, yPos, 0.0f);361 brick->setGame(this);381 this->futureBrick_->addTemplate(this->center_->getBrickTemplate()); 382 383 // Attach the brick to the Centerpoint and set the position of the brick to be at the left side. 384 this->center_->attach(this->futureBrick_); 385 float xPos = (this->center_->getWidth()*1.6 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize(); 386 float yPos = (this->center_->getHeight()-5.1f)*this->center_->getStoneSize(); 387 this->futureBrick_->setPosition(xPos, yPos, 0.0f); 388 this->futureBrick_->setGame(this); 362 389 } 363 390 … … 389 416 390 417 /** 391 @brief Check each row if it is full. Remove all full rows. Let all stones above the deleted row sink down.392 @brief Manage score.418 @brief Check each row if it is full. Removes all full rows. Update 419 @brief Manages score. 393 420 */ 394 421 void Tetris::findFullRows() … … 399 426 { 400 427 stonesPerRow = 0; 401 for(std::vector<TetrisStone*>:: const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)428 for(std::vector<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it) 402 429 { 403 430 correctPosition = static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()); … … 408 435 { 409 436 clearRow(row); 437 row--; //the row counter has to be decreased in order to detect multiple rows! 410 438 this->playerScored(this->player_);// add points 411 439 //increase the stone's speed … … 413 441 } 414 442 } 415 416 443 } 417 418 444 } 419 445 } -
code/branches/pCuts/src/modules/tetris/Tetris.h
r9087 r9092 96 96 std::vector< std::vector<bool> > grid_; 97 97 TetrisBrick* activeBrick_; 98 TetrisBrick* futureBrick_; 98 99 99 100 Timer starttimer_; //!< A timer to delay the start of the game. -
code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
r9087 r9092 49 49 @brief 50 50 Constructor. Registers and initializes the object. 51 @ingroup Tetris 51 52 */ 52 53 TetrisBrick::TetrisBrick(BaseObject* creator): ControllableEntity(creator) … … 71 72 { //Index 0 : single stone, 1 : 4 in a row; 2: 4-Block right shifted; 3: 'T' 4: 4-Block left shifted; 72 73 //Index 5 : 4-Block; 6 : 'L'; 7 : mirrored 'L'; 73 orxout()<< "TetrisBrick::createBrick" << endl;74 74 if(this->shapeIndex_ == 0) 75 75 this->stonesPerBrick_ = 1; -
code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc
r9082 r9092 30 30 @file TetrisCenterpoint.cc 31 31 @brief Implementation of the TetrisCenterpoint class. 32 @ingroup Tetris 32 33 */ 33 34 -
code/branches/pCuts/src/modules/tetris/TetrisScore.cc
r9091 r9092 30 30 @file TetrisScore.cc 31 31 @brief Implementation of the TetrisScore class. 32 @ingroup Tetris 32 33 */ 33 34 … … 49 50 @brief 50 51 Constructor. Registers and initializes the object. 52 @ingroup Tetris 51 53 */ 52 54 TetrisScore::TetrisScore(BaseObject* creator) : OverlayText(creator) … … 56 58 this->owner_ = 0; 57 59 this->player_ = NULL; 58 this->lock_ = true;59 60 } 60 61 … … 91 92 { 92 93 std::string score("0"); 93 if(!this->owner_->hasEnded() && this->lock_)94 if(!this->owner_->hasEnded()) 94 95 { 95 96 //get the player 96 97 player_ = this->owner_->getPlayer(); 97 this->lock_ = false;98 98 } 99 99 -
code/branches/pCuts/src/modules/tetris/TetrisScore.h
r9091 r9092 67 67 Tetris* owner_; //!< The Tetris game that owns this TetrisScore. 68 68 PlayerInfo* player_; //!< Store information about the player permanently. 69 bool lock_;70 69 }; 71 70 } -
code/branches/pCuts/src/modules/tetris/TetrisStone.cc
r9085 r9092 30 30 @file TetrisStone.cc 31 31 @brief Implementation of the TetrisStone class. 32 @ingroup Tetris 32 33 */ 33 34
Note: See TracChangeset
for help on using the changeset viewer.