[Orxonox-commit 4415] r9086 - code/branches/pCuts/src/modules/tetris
jo at orxonox.net
jo at orxonox.net
Sat Apr 14 15:32:57 CEST 2012
Author: jo
Date: 2012-04-14 15:32:56 +0200 (Sat, 14 Apr 2012)
New Revision: 9086
Modified:
code/branches/pCuts/src/modules/tetris/Tetris.cc
code/branches/pCuts/src/modules/tetris/Tetris.h
code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
Log:
Tetris contais almost the same features as before introducing bricks. Two bugs are still left. And the clear row feature has to be implemented.
Modified: code/branches/pCuts/src/modules/tetris/Tetris.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/Tetris.cc 2012-04-13 15:44:29 UTC (rev 9085)
+++ code/branches/pCuts/src/modules/tetris/Tetris.cc 2012-04-14 13:32:56 UTC (rev 9086)
@@ -121,10 +121,6 @@
continue;
const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
- orxout()<< "position.x: " << position.x << endl;
- orxout()<< "currentStonePosition.x: " << currentStonePosition.x << endl;
- if(position.x == currentStonePosition.x)
- orxout()<< "NON Valid Move Candidate" <<endl;
if((position.x == currentStonePosition.x) && abs(position.y-currentStonePosition.y) < this->center_->getStoneSize())
return false;
@@ -173,17 +169,9 @@
//Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount());
const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
//!< Saves the position of the currentStone
- if(position.x == currentStonePosition.x)
- {
- orxout()<< "candidate found" << endl;
- orxout()<< "position.y: "<< position.y << endl;
- orxout()<< "urrentStonePosition.y: " << currentStonePosition.y << endl;
- }
if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
- {//TODO: Why are such events not detected ??
- // Because currentStonePosition.x isn't calculated globally, but locally
- orxout()<< "YEAY !!"<<endl;
+ {
this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->getPosition().z));
return false;
}// This case applies if the stones overlap partially vertically
@@ -315,7 +303,6 @@
{
// Get camera settings
cameraIndex = this->activeBrick_->getCurrentCameraIndex();
- orxout() << "cameraIndex: " << this->activeBrick_->getCurrentCameraIndex() << endl;
this->player_->stopControl();
}
@@ -324,7 +311,6 @@
this->player_->startControl(this->activeBrick_);
this->activeBrick_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
- orxout() << "velocity: " << this->center_->getStoneSpeed() << endl;
this->activeBrick_->setCameraPosition(cameraIndex);
}
@@ -375,4 +361,25 @@
this->center_ = center;
}
+ /**
+ @brief Check each row if it is full. Remove all full rows. Let all stones above the deleted row sink down.
+ @brief Manage score.
+ */
+ void Tetris::clearFullRow()
+ {
+ unsigned int stonesPerRow = 0;
+ for (unsigned int row = 0; row < this->center_->getHeight()/this->center_->getStoneSize(); row++)
+ {
+ stonesPerRow = 0;
+ for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
+ {
+ if((*it)->getPosition().y == row)
+ stonesPerRow++;
+ if(stonesPerRow == this->center_->getWidth()/this->center_->getStoneSize())
+ orxout()<< "CANDIDATE FOUND in row " << row <<endl;
+ }
+
+ }
+ }
+
}
Modified: code/branches/pCuts/src/modules/tetris/Tetris.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/Tetris.h 2012-04-13 15:44:29 UTC (rev 9085)
+++ code/branches/pCuts/src/modules/tetris/Tetris.h 2012-04-14 13:32:56 UTC (rev 9086)
@@ -72,6 +72,7 @@
bool isValidMove(TetrisStone* stone, const Vector3& position);
bool isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation);
+ Vector3 rotateVector(Vector3 position, unsigned int amount);
protected:
virtual void spawnPlayersIfRequested(); //!< Spawns player.
@@ -83,7 +84,8 @@
void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
bool isValidStonePosition(TetrisStone* stone, const Vector3& position);
bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position);
- Vector3 rotateVector(Vector3 position, unsigned int amount);
+ void clearFullRow(void);
+
PlayerInfo* player_;
Modified: code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisBrick.cc 2012-04-13 15:44:29 UTC (rev 9085)
+++ code/branches/pCuts/src/modules/tetris/TetrisBrick.cc 2012-04-14 13:32:56 UTC (rev 9086)
@@ -176,7 +176,7 @@
}
return NULL;
}
-
+//TODO: refactor this function; is not needed if brickstones are added to Tetris::stones_ after collision.
bool TetrisBrick::contains(TetrisStone* stone)
{
for(unsigned int i = 0; i < brickStones_.size(); i++)
@@ -240,18 +240,19 @@
{
this->setVelocity(0.0f, 0.0f, 0.0f);
}
+
/**
@brief
Attaches stones to the Centerpoint.
*/
void TetrisBrick::releaseStones(TetrisCenterpoint* center)
{
+ assert(this->tetris_);
for(unsigned int i = 0; i < brickStones_.size(); i++)
{
- //this->brickStones_[i]->detachFromParent();
-
- //this->brickStones_[i]->detach(this);
- //this->brickStones_[i]->attach(center);
+ this->brickStones_[i]->detachFromParent();
+ this->brickStones_[i]->attachToParent(center);
+ this->brickStones_[i]->setPosition(this->getPosition()+this->tetris_->rotateVector(this->brickStones_[i]->getPosition(),this->rotationCount_ ));
}
}
More information about the Orxonox-commit
mailing list