[Orxonox-commit 4416] r9087 - in code/branches/pCuts: data/levels src/modules/tetris
jo at orxonox.net
jo at orxonox.net
Sat Apr 14 17:45:44 CEST 2012
Author: jo
Date: 2012-04-14 17:45:44 +0200 (Sat, 14 Apr 2012)
New Revision: 9087
Modified:
code/branches/pCuts/data/levels/tetris.oxw
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:
Still a long way to go. A short todo list can be found at the beginning of Tetric.cc. A first, buggy clear-row function has been implemented.
Modified: code/branches/pCuts/data/levels/tetris.oxw
===================================================================
--- code/branches/pCuts/data/levels/tetris.oxw 2012-04-14 13:32:56 UTC (rev 9086)
+++ code/branches/pCuts/data/levels/tetris.oxw 2012-04-14 15:45:44 UTC (rev 9087)
@@ -26,9 +26,6 @@
<attached>
<Model position="0,0,0" mesh="crate.mesh" scale=1 />
</attached>
- <!--collisionShapes>
- <BoxCollisionShape position="0,0,0" halfExtents="5,5,5" />
- </collisionShapes-->
</TetrisStone>
</Template>
@@ -38,8 +35,8 @@
<TetrisBrick>
<camerapositions>
<CameraPosition position="55,75,200" absolute=true />
- <CameraPosition position="0,50,160" drag=true mouselook=true />
- <CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true />
+ <!--CameraPosition position="0,50,160" drag=true mouselook=true /-->
+ <!--CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true /-->
</camerapositions>
</TetrisBrick>
</Template>
Modified: code/branches/pCuts/src/modules/tetris/Tetris.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/Tetris.cc 2012-04-14 13:32:56 UTC (rev 9086)
+++ code/branches/pCuts/src/modules/tetris/Tetris.cc 2012-04-14 15:45:44 UTC (rev 9087)
@@ -22,8 +22,18 @@
* Author:
* ...
* Co-authors:
- * ...
+ * Johannes Ritz
*
+ *BUG a) double stone model (@ brick's location the stone's model is duplicated. Why does the brick have a model attached to it.)
+ *BUG b) the brick is set the wrong way after a (brick-brick) collision, if the brick was turned
+ *BUG c) destroying the old stones causes segfault -> WeakPointer as solution ?
+ *BUG
+ *
+ *TASK a) give points for winning
+ *TASK b) write a hud (show points gained; new brick)
+ *TASK c) end the game in a nicer way
+ *TASK d) save the highscore
+ *TASK e) eye candy
*/
/**
@@ -64,6 +74,7 @@
this->starttimer_.stopTimer();
this->player_ = NULL;
+ this->endGameCriteria_ = 0.0f;
}
/**
@@ -93,15 +104,20 @@
{
SUPER(Tetris, tick, dt);
- if(this->activeBrick_ != NULL)
+ if((this->activeBrick_ != NULL)&&(!this->hasEnded()))
{
+ this->endGameCriteria_ += dt;
if(!this->isValidBrickPosition(this->activeBrick_, this->activeBrick_->getPosition()))
{
this->activeBrick_->setVelocity(Vector3::ZERO);
this->activeBrick_->releaseStones(this->center_);
//delete this->activeBrick_; //releasing the memory
+ this->findFullRows();
+ if(this->endGameCriteria_ < 0.1f) //end game if two bricks are created within a 0.1s interval.
+ this->end();
this->createBrick();
this->startBrick();
+ this->endGameCriteria_ = 0.0f;
}
}
}
@@ -256,6 +272,7 @@
*/
void Tetris::end()
{
+ this->activeBrick_->setVelocity(Vector3::ZERO);
this->cleanup();
// Call end for the parent class.
@@ -365,21 +382,41 @@
@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()
+ void Tetris::findFullRows()
{
+ unsigned int correctPosition = 0;
+ orxout()<< "clear full rows ************ " <<endl;
unsigned int stonesPerRow = 0;
- for (unsigned int row = 0; row < this->center_->getHeight()/this->center_->getStoneSize(); row++)
+ for (unsigned int row = 0; row < this->center_->getHeight(); row++)
{
stonesPerRow = 0;
for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
{
- if((*it)->getPosition().y == row)
+ correctPosition = static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize());
+ if(correctPosition == row)
stonesPerRow++;
- if(stonesPerRow == this->center_->getWidth()/this->center_->getStoneSize())
- orxout()<< "CANDIDATE FOUND in row " << row <<endl;
+ if(stonesPerRow == this->center_->getWidth())
+ {orxout()<< "CANDIDATE FOUND in row " << row <<endl; clearRow(row);}
}
}
}
+ void Tetris::clearRow(unsigned int row)
+ {//std::vector<int>::iterator it = v.begin()
+ for(std::vector<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
+ {
+ if(static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize()) == row)
+ (*it)->setPosition(Vector3(-10,-10,0));
+ //{(*it)->destroy(); this->stones_.erase(it); orxout()<< "destroy row "<<endl;}//experimental
+ }
+ for(std::vector<TetrisStone*>::const_reverse_iterator it2 = this->stones_.rbegin(); it2 != this->stones_.rend(); ++it2)
+ {
+ /*if(static_cast<unsigned int>(((*it2)->getPosition().y - 5)/this->center_->getStoneSize()) > row)
+ (*it2)->setPosition((*it2)->getPosition()-Vector3(0,1,0));//*/
+ }
+
+ }
+
+
}
Modified: code/branches/pCuts/src/modules/tetris/Tetris.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/Tetris.h 2012-04-14 13:32:56 UTC (rev 9086)
+++ code/branches/pCuts/src/modules/tetris/Tetris.h 2012-04-14 15:45:44 UTC (rev 9087)
@@ -84,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);
- void clearFullRow(void);
+ void findFullRows(void);
+ void clearRow(unsigned int row);
PlayerInfo* player_;
@@ -96,6 +97,7 @@
TetrisBrick* activeBrick_;
Timer starttimer_; //!< A timer to delay the start of the game.
+ float endGameCriteria_; //<! Works as a timer which is resetted, whenever a brick is created.
};
}
Modified: code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisBrick.cc 2012-04-14 13:32:56 UTC (rev 9086)
+++ code/branches/pCuts/src/modules/tetris/TetrisBrick.cc 2012-04-14 15:45:44 UTC (rev 9087)
@@ -39,6 +39,7 @@
#include "TetrisCenterpoint.h"
#include "TetrisStone.h"
#include "Tetris.h"
+#include "util/Math.h"
namespace orxonox
{
@@ -51,8 +52,7 @@
TetrisBrick::TetrisBrick(BaseObject* creator): ControllableEntity(creator)
{
RegisterObject(TetrisBrick);
-
- this->shapeIndex_ = 4; //<! TODO: random number between 0 and 7
+ this->shapeIndex_ = static_cast<unsigned int>(rnd(7.0f)); //<! random number between 0 and 7
this->stonesPerBrick_ = 4; //<! most tetris bricks is formed by 4 stones
this->delay_ = false;
this->delayTimer_.setTimer(0.2f, false, createExecutor(createFunctor(&TetrisBrick::enableMovement, this)));
@@ -104,8 +104,6 @@
*/
void TetrisBrick::formBrick(TetrisStone* stone, unsigned int i)
{
- if(i != 0 && this->shapeIndex_ == 0)
- orxout() << "So it has come to this in TetrisBrick.cc"<< endl;
if(i == 0) //setting the first stone as
{
stone->setPosition(0.0f, 0.0f, 0.0f);
More information about the Orxonox-commit
mailing list