Changeset 9084 for code/branches/pCuts
- Timestamp:
- Apr 12, 2012, 7:05:57 PM (13 years ago)
- Location:
- code/branches/pCuts
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pCuts/data/levels/tetris.oxw
r9083 r9084 27 27 <Model position="0,0,0" mesh="crate.mesh" scale=1 /> 28 28 </attached> 29 <!--collisionShapes> 30 <BoxCollisionShape position="0,0,0" halfExtents="5,5,5" /> 31 </collisionShapes--> 29 32 </TetrisStone> 30 33 </Template> … … 77 80 <Model position="111,76,0" mesh="cube.mesh" scale3D="1,76,1" /> 78 81 </attached> 82 <!--collisionShapes> 83 <BoxCollisionShape position="55,-1,0" halfExtents="57,1,11" /> 84 <BoxCollisionShape position="-1,76,0" halfExtents="1,76,1" /> 85 <BoxCollisionShape position="111,76,0" halfExtents="1,76,1" /> 86 </collisionShapes--> 79 87 </TetrisCenterpoint> 80 88 -
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 -
code/branches/pCuts/src/modules/tetris/Tetris.h
r9082 r9084 72 72 73 73 bool isValidMove(TetrisStone* stone, const Vector3& position); 74 bool isValidMove(TetrisBrick* brick, const Vector3& position );74 bool isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation); 75 75 76 76 protected: 77 77 virtual void spawnPlayersIfRequested(); //!< Spawns player. 78 78 79 79 80 private: … … 83 84 bool isValidStonePosition(TetrisStone* stone, const Vector3& position); 84 85 bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position); 86 Vector3 rotateVector(Vector3 position, unsigned int amount); 85 87 86 88 PlayerInfo* player_; -
code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
r9083 r9084 53 53 RegisterObject(TetrisBrick); 54 54 55 this->shapeIndex_ = 3; //<! TODO: random number between 0 and 755 this->shapeIndex_ = 1; //<! TODO: random number between 0 and 7 56 56 this->stonesPerBrick_ = 4; //<! most tetris bricks is formed by 4 stones 57 57 this->delay_ = false; … … 60 60 this->tetris_ = this->getTetris(); 61 61 this->size_ = 10.0f; //TODO: fix this via this->tetris_->center_->getStoneSize(); 62 63 62 this->rotationCount_ = 0; 64 63 this->createBrick(); //<! create a whole new Brick; 65 64 } … … 79 78 // Create a new stone and add it to the brick. 80 79 TetrisStone* stone = new TetrisStone(this); 81 stone->setHealth(1.0f); //TODO: is this value low enough ?80 stone->setHealth(1.0f); 82 81 this->brickStones_.push_back(stone); 83 82 this->attach(stone); … … 156 155 } 157 156 158 bool TetrisBrick::isValidMove(Vector3& position) 159 { 160 161 for(unsigned int i = 0; i < this->stonesPerBrick_ ; i++) 162 {//TODO: check if isValidMove works with this function, 163 if(this->tetris_->isValidMove(this->brickStones_[i], position)) 164 continue; 165 else 166 return false; 167 } 168 return true; 157 bool TetrisBrick::isValidMove(const Vector3& position, bool isRotation = false) 158 { 159 return this->tetris_->isValidMove(this,position, isRotation); 169 160 } 170 161 … … 211 202 else if(!this->lockRotation_) //rotate when key up is pressed 212 203 { 213 orxout() << "The object should be rolled soon." << endl; 204 if(!isValidMove(this->getPosition(), true)) //catch illegal rotations 205 return; 214 206 this->lockRotation_ = true; // multiple calls of this function have to be filtered out. 215 207 this->rotationTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&TetrisBrick::unlockRotation, this))); 216 208 Quaternion q(Degree(90), Vector3::UNIT_Z); 217 209 this->setOrientation(this->getOrientation()*q); //rotation: roll 90° 218 210 this->rotationCount_ = (this->rotationCount_ + 1) % 4; 219 211 } 220 212 } -
code/branches/pCuts/src/modules/tetris/TetrisBrick.h
r9082 r9084 61 61 virtual void changedPlayer(); //!< Is called when the player changed. 62 62 63 bool isValidMove( Vector3& position);63 bool isValidMove(const Vector3& position, bool isRotation); 64 64 unsigned int getNumberOfStones(void) const 65 65 { return this->brickStones_.size(); } … … 69 69 void setGame(Tetris* tetris) 70 70 { assert(tetris); tetris_ = tetris; } 71 unsigned int getRotationCount(void) 72 { return this->rotationCount_;} 71 73 72 74 protected: … … 93 95 bool lockRotation_; 94 96 97 unsigned int rotationCount_; //!< Stores the bricks orientation 95 98 Timer delayTimer_; 96 99 Timer rotationTimer_; ///!< This timer is used to filter out multiple rotation inputs. -
code/branches/pCuts/src/orxonox/worldentities/ControllableEntity.cc
r9083 r9084 177 177 { 178 178 if (this->cameraPositions_.size() <= 0) 179 {orxout()<< "camareapositions_size == 0"<<endl ; return 0;}179 return 0; 180 180 181 181 unsigned int counter = 0; … … 196 196 if(this->camera_ != NULL && this->cameraPositions_.size() > 0) 197 197 { 198 orxout()<< "Cameraposition is set."<<endl;199 198 if(index >= this->cameraPositions_.size()) 200 199 index = 0;
Note: See TracChangeset
for help on using the changeset viewer.