[Orxonox-commit 4421] r9092 - in code/branches/pCuts: data/levels src/modules/tetris
jo at orxonox.net
jo at orxonox.net
Tue Apr 17 23:51:21 CEST 2012
Author: jo
Date: 2012-04-17 23:51:21 +0200 (Tue, 17 Apr 2012)
New Revision: 9092
Modified:
code/branches/pCuts/data/levels/tetris.oxw
code/branches/pCuts/src/modules/tetris/CMakeLists.txt
code/branches/pCuts/src/modules/tetris/Tetris.cc
code/branches/pCuts/src/modules/tetris/Tetris.h
code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc
code/branches/pCuts/src/modules/tetris/TetrisScore.cc
code/branches/pCuts/src/modules/tetris/TetrisScore.h
code/branches/pCuts/src/modules/tetris/TetrisStone.cc
Log:
Tetris on the way to get completed. I fixed some bugs concerning rotation, false brick placement on brick-brick collisions, clearing multiple rows and added a preview brick feature and a basic hud.
Modified: code/branches/pCuts/data/levels/tetris.oxw
===================================================================
--- code/branches/pCuts/data/levels/tetris.oxw 2012-04-16 20:42:57 UTC (rev 9091)
+++ code/branches/pCuts/data/levels/tetris.oxw 2012-04-17 21:51:21 UTC (rev 9092)
@@ -8,7 +8,7 @@
<?lua
include("HUDTemplates3.oxo")
include("stats.oxo")
- include("pongHUD.oxo")
+ include("tetrisHUD.oxo")
include("templates/lodInformation.oxt")
?>
@@ -23,7 +23,7 @@
<Template name=tetrisstone>
<TetrisStone camerapositiontemplate=tetrisstonecameras>
<attached>
- <Model position="0,0,0" mesh="crate.mesh" scale=1 />
+ <Model position="0,0,0" mesh="crate.mesh" scale=0.9 />
</attached>
</TetrisStone>
</Template>
@@ -58,8 +58,16 @@
ambientlight = "0.5, 0.5, 0.5"
skybox = "Orxonox/skypanoramagen1"
>
+<!--luke_grey_-_hypermode.ogg allgorythm-lift_up.ogg Fight1.ogg -->
+ <WorldAmbientSound
+ source="Ganymede.ogg"
+ looping="true"
+ playOnLoad="true"
+ />
+
<Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+
<?lua
for i = 1, 10, 1 do
?>
@@ -79,5 +87,16 @@
</collisionShapes-->
</TetrisCenterpoint>
+<!-- ------------ insert eye candy here ---------------- -->
+
+<!-- asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog) -->
+<!-- DONT DARE TO TURN THE FOG ON, whithout finding a better belt position -->
+ <?lua
+ dofile("includes/asteroidField.lua")
+ asteroidBelt(10000, 0, 0, -40, -90, 70, 100, 200, 24000, 20000, 500, 0)
+
+ ?>
+
+
</Scene>
</Level>
Modified: code/branches/pCuts/src/modules/tetris/CMakeLists.txt
===================================================================
--- code/branches/pCuts/src/modules/tetris/CMakeLists.txt 2012-04-16 20:42:57 UTC (rev 9091)
+++ code/branches/pCuts/src/modules/tetris/CMakeLists.txt 2012-04-17 21:51:21 UTC (rev 9092)
@@ -11,5 +11,6 @@
FIND_HEADER_FILES
LINK_LIBRARIES
orxonox
+ overlays
SOURCE_FILES ${TETRIS_SRC_FILES}
)
Modified: code/branches/pCuts/src/modules/tetris/Tetris.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/Tetris.cc 2012-04-16 20:42:57 UTC (rev 9091)
+++ code/branches/pCuts/src/modules/tetris/Tetris.cc 2012-04-17 21:51:21 UTC (rev 9092)
@@ -25,13 +25,10 @@
* Johannes Ritz
*
*
- *BUG b) the falling brick is set the wrong way after a (brick-brick) collision, if the falling brick was turned
*BUG c) destroying the old stones causes segfault -> WeakPointer as solution ?
*BUG d) wrong collision detection: sometimes stones "bounce off"
- *BUG e) multiple rows are not cleared in one round
*
*
- *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
@@ -63,6 +60,7 @@
/**
@brief
Constructor. Registers and initializes the object.
+ @ingroup Tetris
*/
Tetris::Tetris(BaseObject* creator) : Deathmatch(creator)
{
@@ -76,6 +74,8 @@
this->player_ = NULL;
this->endGameCriteria_ = 0.0f;
+ this->setHUDTemplate("TetrisHUD");
+ this->futureBrick_ = NULL;
}
/**
@@ -157,16 +157,25 @@
for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
{
TetrisStone* stone = brick->getStone(i);
- Vector3 stonePosition;
+ Vector3 stonePosition; //the current stone's offset to position
if(isRotation)
stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()+1);
else
stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
- if(! this->isValidMove(stone, position + stonePosition )) // wrong position??
+ if(! this->isValidMove(stone, position + stonePosition ))
{
return false;
}
+
+ //catch illegal rotation (such that collisions with ground are not permitted)
+ if(isRotation)
+ {
+ if((position + stonePosition).y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
+ {
+ return false;
+ }
+ }
}
return true;
@@ -192,7 +201,10 @@
continue;
if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
{
- this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->getPosition().z));
+ int y_offset = static_cast<int>((this->activeBrick_->getPosition().y-currentStonePosition.y+10)/10)*10 + currentStonePosition.y;
+ if(y_offset < 0) //filter out extreme cases (very rare bug)
+ y_offset = 0;
+ this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, y_offset, this->activeBrick_->getPosition().z));
return false;
}// This case applies if the stones overlap partially vertically
}
@@ -200,14 +212,19 @@
// after we checked for collision with all stones, we also check for collision with the bottom
if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
{
- int yOffset = stone->getPosition().y;//calculate offset
- this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f+yOffset, this->activeBrick_->getPosition().z));
+ int yOffset = stone->getPosition().y + this->center_->getStoneSize()/2.0f;//calculate offset
+ if(yOffset < 0) //catch brake-throughs
+ yOffset = 0;
+ this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, yOffset, this->activeBrick_->getPosition().z));
return false;
}
return true;
}
-
+ /**
+ * @brief This function determines wether a brick touches another brick or the ground.
+ *
+ */
bool Tetris::isValidBrickPosition(TetrisBrick* brick, const Vector3& position)
{
assert(brick);
@@ -246,6 +263,8 @@
{
if (this->center_ != NULL) // There needs to be a TetrisCenterpoint, i.e. the area the game takes place.
{
+ // Create the futureBrick_
+ this->createBrick();
// Create the first brick.
this->createBrick();
}
@@ -342,23 +361,31 @@
void Tetris::createBrick(void) //TODO: random rotation offset between 0 and 3 (times 90°)
{
- // Create a new brick and add it to the list of bricks && to the list of stones.
- TetrisBrick* brick = new TetrisBrick(this->center_);
- this->bricks_.push_back(brick);
- for (unsigned int i = 0; i < brick->getNumberOfStones(); i++)
+ // Use the futureBrick_ as new currentBrick by setting its position and storing it in this->bricks
+ if(this->futureBrick_ != NULL)
{
- this->stones_.push_back(brick->getStone(i));
+ for (unsigned int i = 0; i < this->futureBrick_->getNumberOfStones(); i++)
+ {
+ this->stones_.push_back(this->futureBrick_->getStone(i));
+ }
+ float xPos = (this->center_->getWidth()/2 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
+ float yPos = (this->center_->getHeight()-0.5f)*this->center_->getStoneSize();
+ this->futureBrick_->setPosition(xPos, yPos, 0.0f);
+ this->bricks_.push_back(this->futureBrick_);
}
+ // create new futureBrick_
+ this->futureBrick_ = new TetrisBrick(this->center_);
+
// Apply the stone template to the stone.
- brick->addTemplate(this->center_->getBrickTemplate());
+ this->futureBrick_->addTemplate(this->center_->getBrickTemplate());
- // Attach the brick to the Centerpoint and set the position of the brick to be at the top middle.
- this->center_->attach(brick);
- float xPos = (this->center_->getWidth()/2 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
- float yPos = (this->center_->getHeight()-0.5f)*this->center_->getStoneSize();
- brick->setPosition(xPos, yPos, 0.0f);
- brick->setGame(this);
+ // Attach the brick to the Centerpoint and set the position of the brick to be at the left side.
+ this->center_->attach(this->futureBrick_);
+ float xPos = (this->center_->getWidth()*1.6 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
+ float yPos = (this->center_->getHeight()-5.1f)*this->center_->getStoneSize();
+ this->futureBrick_->setPosition(xPos, yPos, 0.0f);
+ this->futureBrick_->setGame(this);
}
@@ -388,8 +415,8 @@
}
/**
- @brief Check each row if it is full. Remove all full rows. Let all stones above the deleted row sink down.
- @brief Manage score.
+ @brief Check each row if it is full. Removes all full rows. Update
+ @brief Manages score.
*/
void Tetris::findFullRows()
{
@@ -398,7 +425,7 @@
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)
+ for(std::vector<TetrisStone*>::iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
{
correctPosition = static_cast<unsigned int>(((*it)->getPosition().y - 5)/this->center_->getStoneSize());
if(correctPosition == row)
@@ -407,14 +434,13 @@
if(stonesPerRow == this->center_->getWidth())
{
clearRow(row);
+ row--; //the row counter has to be decreased in order to detect multiple rows!
this->playerScored(this->player_);// add points
//increase the stone's speed
this->center_->setStoneSpeed(this->center_->getStoneSpeed()+1.0f);
}
}
-
}
-
}
}
Modified: code/branches/pCuts/src/modules/tetris/Tetris.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/Tetris.h 2012-04-16 20:42:57 UTC (rev 9091)
+++ code/branches/pCuts/src/modules/tetris/Tetris.h 2012-04-17 21:51:21 UTC (rev 9092)
@@ -95,6 +95,7 @@
std::vector<TetrisStone*> stones_; //!< A list of all stones in play.
std::vector< std::vector<bool> > grid_;
TetrisBrick* activeBrick_;
+ TetrisBrick* futureBrick_;
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-16 20:42:57 UTC (rev 9091)
+++ code/branches/pCuts/src/modules/tetris/TetrisBrick.cc 2012-04-17 21:51:21 UTC (rev 9092)
@@ -48,6 +48,7 @@
/**
@brief
Constructor. Registers and initializes the object.
+ @ingroup Tetris
*/
TetrisBrick::TetrisBrick(BaseObject* creator): ControllableEntity(creator)
{
@@ -70,7 +71,6 @@
void TetrisBrick::createBrick(void)
{ //Index 0 : single stone, 1 : 4 in a row; 2: 4-Block right shifted; 3: 'T' 4: 4-Block left shifted;
//Index 5 : 4-Block; 6 : 'L'; 7 : mirrored 'L';
- orxout()<< "TetrisBrick::createBrick" << endl;
if(this->shapeIndex_ == 0)
this->stonesPerBrick_ = 1;
for (unsigned int i = 0; i < this->stonesPerBrick_; i++)
Modified: code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc 2012-04-16 20:42:57 UTC (rev 9091)
+++ code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc 2012-04-17 21:51:21 UTC (rev 9092)
@@ -29,6 +29,7 @@
/**
@file TetrisCenterpoint.cc
@brief Implementation of the TetrisCenterpoint class.
+ @ingroup Tetris
*/
#include "TetrisCenterpoint.h"
Modified: code/branches/pCuts/src/modules/tetris/TetrisScore.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisScore.cc 2012-04-16 20:42:57 UTC (rev 9091)
+++ code/branches/pCuts/src/modules/tetris/TetrisScore.cc 2012-04-17 21:51:21 UTC (rev 9092)
@@ -29,6 +29,7 @@
/**
@file TetrisScore.cc
@brief Implementation of the TetrisScore class.
+ @ingroup Tetris
*/
#include "TetrisScore.h"
@@ -48,6 +49,7 @@
/**
@brief
Constructor. Registers and initializes the object.
+ @ingroup Tetris
*/
TetrisScore::TetrisScore(BaseObject* creator) : OverlayText(creator)
{
@@ -55,7 +57,6 @@
this->owner_ = 0;
this->player_ = NULL;
- this->lock_ = true;
}
/**
@@ -90,11 +91,10 @@
if (this->owner_ != NULL)
{
std::string score("0");
- if(!this->owner_->hasEnded() && this->lock_)
+ if(!this->owner_->hasEnded())
{
//get the player
player_ = this->owner_->getPlayer();
- this->lock_ = false;
}
if(this->owner_->hasStarted())
Modified: code/branches/pCuts/src/modules/tetris/TetrisScore.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisScore.h 2012-04-16 20:42:57 UTC (rev 9091)
+++ code/branches/pCuts/src/modules/tetris/TetrisScore.h 2012-04-17 21:51:21 UTC (rev 9092)
@@ -66,7 +66,6 @@
private:
Tetris* owner_; //!< The Tetris game that owns this TetrisScore.
PlayerInfo* player_; //!< Store information about the player permanently.
- bool lock_;
};
}
#endif /* _TetrisScore_H__ */
Modified: code/branches/pCuts/src/modules/tetris/TetrisStone.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisStone.cc 2012-04-16 20:42:57 UTC (rev 9091)
+++ code/branches/pCuts/src/modules/tetris/TetrisStone.cc 2012-04-17 21:51:21 UTC (rev 9092)
@@ -29,6 +29,7 @@
/**
@file TetrisStone.cc
@brief Implementation of the TetrisStone class.
+ @ingroup Tetris
*/
#include "TetrisStone.h"
More information about the Orxonox-commit
mailing list