Changeset 9082 for code/branches/pCuts/src/modules/tetris
- Timestamp:
- Apr 11, 2012, 3:53:43 PM (13 years ago)
- Location:
- code/branches/pCuts/src/modules/tetris
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pCuts/src/modules/tetris/CMakeLists.txt
r8706 r9082 3 3 TetrisCenterpoint.cc 4 4 TetrisStone.cc 5 TetrisBrick.cc 5 6 ) 6 7 -
code/branches/pCuts/src/modules/tetris/Tetris.cc
r8858 r9082 42 42 #include "TetrisCenterpoint.h" 43 43 #include "TetrisStone.h" 44 #include "TetrisBrick.h" 44 45 #include "infos/PlayerInfo.h" 45 46 … … 57 58 RegisterObject(Tetris); 58 59 59 this->active Stone_ = NULL;60 this->activeBrick_ = NULL; 60 61 61 62 // Pre-set the timer, but don't start it yet. 62 this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::start Stone, this)));63 this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::startBrick, this))); 63 64 this->starttimer_.stopTimer(); 64 65 … … 82 83 void Tetris::cleanup() 83 84 { 85 /*for(int i = 0;i < this->stones_.size(); i++) //TODO: Why isn't there any code like this 86 { // compensating the 'new' statement? 87 delete this->stones_[i]; 88 }//*/ 84 89 85 90 } … … 89 94 SUPER(Tetris, tick, dt); 90 95 91 if(this->active Stone_ != NULL)92 { 93 if(!this->isValid StonePosition(this->activeStone_, this->activeStone_->getPosition()))96 if(this->activeBrick_ != NULL) 97 { 98 if(!this->isValidBrickPosition(this->activeBrick_, this->activeBrick_->getPosition())) 94 99 { 95 this->active Stone_->setVelocity(Vector3::ZERO);96 this->create Stone();97 this->start Stone();100 this->activeBrick_->setVelocity(Vector3::ZERO); 101 this->createBrick(); 102 this->startBrick(); 98 103 } 99 104 } … … 123 128 } 124 129 130 /** 131 @brief 132 Check for each stone in a brick wether it is moved the right way. 133 */ 134 bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position) 135 { 136 assert(brick); 137 138 for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ ) 139 { 140 TetrisStone* stone = brick->getStone(i); 141 if(! this->isValidMove(stone, position + stone->getPosition())) // wrong position?? 142 return false; 143 orxout()<< "stoneRelativePoistion: " << stone->getPosition() << endl; 144 orxout()<< "stoneTotalPoistion: " << position + stone->getPosition() << endl; 145 } 146 return true; 147 148 } 149 150 151 125 152 bool Tetris::isValidStonePosition(TetrisStone* stone, const Vector3& position) 126 153 { … … 130 157 for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it) 131 158 { 132 if( stone == *it)159 if(this->activeBrick_->contains(*it)) 133 160 continue; 134 161 … … 137 164 if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize())) 138 165 { 139 this->active Stone_->setPosition(Vector3(this->activeStone_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeStone_->getPosition().z));166 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->getPosition().z)); 140 167 return false; 141 168 }// This case applies if the stones overlap partially vertically … … 144 171 // after we checked for collision with all stones, we also check for collision with the bottom 145 172 if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level 146 { 147 stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0f, stone->getPosition().z));173 {//TODO: correct positioning !! 174 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f, this->activeBrick_->getPosition().z)); 148 175 return false; 149 176 } … … 152 179 } 153 180 181 bool Tetris::isValidBrickPosition(TetrisBrick* brick, const Vector3& position) 182 { 183 assert(brick); 184 185 for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ ) 186 { 187 TetrisStone* stone = brick->getStone(i); 188 if(! this->isValidStonePosition(stone, position + stone->getPosition()) ) // wrong position?? 189 return false; 190 } 191 return true; 192 193 } 194 154 195 /** 155 196 @brief … … 161 202 { 162 203 // Create the first stone. 163 this->create Stone();204 this->createBrick(); 164 205 } 165 206 else // If no centerpoint was specified, an error is thrown and the level is exited. … … 225 266 } 226 267 227 /** 228 @brief 229 Starts the first stone. 230 */ 231 void Tetris::startStone(void) 268 269 270 void Tetris::startBrick(void) 232 271 { 233 272 if(this->player_ == NULL) … … 235 274 236 275 unsigned int cameraIndex = 0; 237 if(this->active Stone_ != NULL)276 if(this->activeBrick_ != NULL) 238 277 { 239 278 // Get camera settings 240 cameraIndex = this->activeStone_->getCurrentCameraIndex(); 279 cameraIndex = this->activeBrick_->getCurrentCameraIndex(); 280 orxout() << "cameraIndex: " << this->activeBrick_->getCurrentCameraIndex() << endl; 241 281 this->player_->stopControl(); 242 282 } 243 244 // Make the last stone to be created the active stone. 245 this->activeStone_ = this->stones_.back(); 246 247 this->player_->startControl(this->activeStone_); 248 this->activeStone_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f); 249 this->activeStone_->setCameraPosition(cameraIndex); 250 } 251 252 /** 253 @brief 254 Creates a new stone. 255 */ 256 void Tetris::createStone(void) 257 { 258 // Create a new stone and add it to the list of stones. 259 TetrisStone* stone = new TetrisStone(this->center_); 260 this->stones_.push_back(stone); 261 283 284 // Make the last brick to be created the active brick. 285 this->activeBrick_ = this->bricks_.back(); 286 287 this->player_->startControl(this->activeBrick_); 288 this->activeBrick_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f); 289 orxout() << "velocity: " << this->center_->getStoneSpeed() << endl; 290 this->activeBrick_->setCameraPosition(cameraIndex); 291 } 292 293 void Tetris::createBrick(void) //TODO: random rotation offset between 0 and 3 (times 90°) 294 { 295 // Create a new brick and add it to the list of bricks && to the list of stones. 296 TetrisBrick* brick = new TetrisBrick(this->center_); 297 this->bricks_.push_back(brick); 298 for (unsigned int i = 0; i < brick->getNumberOfStones(); i++) 299 { 300 this->stones_.push_back(brick->getStone(i)); 301 } 302 262 303 // Apply the stone template to the stone. 263 stone->addTemplate(this->center_->getStoneTemplate());264 265 // Attach the stone to the Centerpoint and set the position of the stoneto be at the top middle.266 this->center_->attach( stone);304 brick->addTemplate(this->center_->getStoneTemplate()); // TODO: find error concerning the cameras 305 306 // Attach the brick to the Centerpoint and set the position of the brick to be at the top middle. 307 this->center_->attach(brick); 267 308 float xPos = (this->center_->getWidth()/2 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize(); 268 309 float yPos = (this->center_->getHeight()-0.5f)*this->center_->getStoneSize(); 269 stone->setPosition(xPos, yPos, 0.0f); 270 stone->setGame(this); 271 } 310 brick->setPosition(xPos, yPos, 0.0f); 311 brick->setGame(this); 312 } 313 272 314 273 315 /** … … 282 324 } 283 325 326 /*TetrisCenterpoint* Tetris::getCenterpoint(void) const 327 { 328 return this->center_; 329 }*/ 330 284 331 /** 285 332 @brief Set the TetrisCenterpoint (the playing field). -
code/branches/pCuts/src/modules/tetris/Tetris.h
r8706 r9082 68 68 69 69 PlayerInfo* getPlayer(void) const; //!< Get the player. 70 WeakPtr<TetrisCenterpoint> getCenterpoint(void) 71 { return this->center_; } 70 72 71 73 bool isValidMove(TetrisStone* stone, const Vector3& position); 74 bool isValidMove(TetrisBrick* brick, const Vector3& position); 72 75 73 76 protected: … … 75 78 76 79 private: 77 void start Stone(void); //!< Starts with the first stone.78 void create Stone(void);80 void startBrick(void); 81 void createBrick(void); 79 82 void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats. 80 83 bool isValidStonePosition(TetrisStone* stone, const Vector3& position); 84 bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position); 81 85 82 86 PlayerInfo* player_; 83 87 84 88 WeakPtr<TetrisCenterpoint> center_; //!< The playing field. 89 std::vector<TetrisBrick*> bricks_; //!< A list of all bricks in play. 85 90 std::vector<TetrisStone*> stones_; //!< A list of all stones in play. 86 91 std::vector< std::vector<bool> > grid_; 87 Tetris Stone* activeStone_;92 TetrisBrick* activeBrick_; 88 93 89 94 Timer starttimer_; //!< A timer to delay the start of the game. -
code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc
r8706 r9082 55 55 this->stoneSize_ = 10.0f; 56 56 this->stoneTemplate_ = ""; 57 this->brickTemplate_ = ""; 57 58 this->stoneSpeed_ = 20.0f; 58 59 … … 69 70 70 71 XMLPortParam(TetrisCenterpoint, "width", setWidth, getWidth, xmlelement, mode); // die Breite 71 XMLPortParam(TetrisCenterpoint, "height", setHeight, setWidth, xmlelement, mode); // die Grösse72 XMLPortParam(TetrisCenterpoint, "height", setHeight, getHeight, xmlelement, mode); // die Grösse //was sollte das mit setWidth?? 72 73 XMLPortParam(TetrisCenterpoint, "stoneSize", setStoneSize, getStoneSize, xmlelement, mode); 73 74 XMLPortParam(TetrisCenterpoint, "stoneTemplate", setStoneTemplate, getStoneTemplate, xmlelement, mode); 75 XMLPortParam(TetrisCenterpoint, "brickTemplate", setBrickTemplate, getBrickTemplate, xmlelement, mode); 74 76 XMLPortParam(TetrisCenterpoint, "stoneSpeed", setStoneSpeed, getStoneSpeed, xmlelement, mode); 75 77 } -
code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.h
r8706 r9082 45 45 46 46 namespace orxonox 47 { 47 {//idea: add 2 triggers to the centerpoint (one to determine when a box would go above the centerpoint; 48 //the other to find out when the lowest row is filled totally) 48 49 49 50 /** … … 118 119 119 120 /** 121 @brief Set the template for the bricks. 122 @param template The template name to be applied to each brick. 123 */ 124 void setBrickTemplate(const std::string& templateName) 125 { this->brickTemplate_ = templateName; } 126 /** 127 @brief Get the template for the bricks. 128 @return Returns the template name to be applied to each brick. 129 */ 130 const std::string& getBrickTemplate(void) const 131 { return this->brickTemplate_; } 132 133 /** 120 134 @brief Set the speed of the stones. 121 135 @param speed The speed to be set. … … 137 151 float stoneSize_; 138 152 std::string stoneTemplate_; 153 std::string brickTemplate_; 139 154 float stoneSpeed_; 140 155 -
code/branches/pCuts/src/modules/tetris/TetrisPrereqs.h
r8706 r9082 68 68 class TetrisCenterpoint; 69 69 class TetrisStone; 70 class TetrisBrick; 70 71 } 71 72 -
code/branches/pCuts/src/modules/tetris/TetrisStone.cc
r9081 r9082 36 36 #include "core/CoreIncludes.h" 37 37 #include "core/XMLPort.h" 38 39 #include <OgreSceneNode.h>40 38 41 39 #include "Tetris.h" -
code/branches/pCuts/src/modules/tetris/TetrisStone.h
r9081 r9082 88 88 bool lockRotation_; 89 89 Timer delayTimer_; 90 Timer rotationTimer_; 90 Timer rotationTimer_; ///!< This timer is used to filter out multiple rotation inputs. 91 91 92 92 Tetris* tetris_;
Note: See TracChangeset
for help on using the changeset viewer.