Changeset 8566 for code/branches/presentation
- Timestamp:
- May 24, 2011, 10:12:42 PM (14 years ago)
- Location:
- code/branches/presentation/src/modules/tetris
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/modules/tetris/Tetris.cc
r8565 r8566 106 106 } 107 107 108 std::pair<bool, TetrisStone*>Tetris::isValidMove(TetrisStone* stone, const Vector3& position)108 bool Tetris::isValidMove(TetrisStone* stone, const Vector3& position) 109 109 { 110 110 assert(stone); 111 111 112 std::pair<bool, TetrisStone*> valid = std::pair<bool, TetrisStone*>(true, NULL);113 114 112 if(position.x < this->center_->getStoneSize()/2.0) //!< If the stone touches the left edge of the level 115 valid.first =false;113 return false; 116 114 else if(position.x > (this->center_->getWidth()-0.5)*this->center_->getStoneSize()) //!< If the stone touches the right edge of the level 117 valid.first =false;115 return false; 118 116 119 117 for(std::vector<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it) … … 124 122 const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone 125 123 126 if((position.x == currentStonePosition.x) && (position.y == currentStonePosition.y)) 127 { 128 stone->setVelocity(Vector3::ZERO); 129 this->createStone(); 130 this->startStone(); 131 valid.first = false; 132 return valid; 133 }// This case applies if the stones overlap completely 134 } 135 136 return valid; 124 if((position.x == currentStonePosition.x) && abs(position.y-currentStonePosition.y) < this->center_->getStoneSize()) 125 return false; 126 } 127 128 return true; 137 129 } 138 130 -
code/branches/presentation/src/modules/tetris/Tetris.h
r8565 r8566 69 69 PlayerInfo* getPlayer(void) const; //!< Get the player. 70 70 71 std::pair<bool, TetrisStone*>isValidMove(TetrisStone* stone, const Vector3& position);71 bool isValidMove(TetrisStone* stone, const Vector3& position); 72 72 73 73 protected: -
code/branches/presentation/src/modules/tetris/TetrisStone.cc
r8564 r8566 82 82 const Vector3& position = this->getPosition(); 83 83 Vector3 newPos = Vector3(position.x+value.x/abs(value.x)*this->size_, position.y, position.z); 84 if(!this->tetris_->isValidMove(this, newPos) .first)84 if(!this->tetris_->isValidMove(this, newPos)) 85 85 return; 86 86 87 //this->previousPosition_ = position;88 87 this->setPosition(newPos); 89 88 this->delay_ = true;
Note: See TracChangeset
for help on using the changeset viewer.