[Orxonox-commit 4411] r9082 - in code/branches/pCuts: data/levels src/modules/tetris

jo at orxonox.net jo at orxonox.net
Wed Apr 11 15:53:46 CEST 2012


Author: jo
Date: 2012-04-11 15:53:43 +0200 (Wed, 11 Apr 2012)
New Revision: 9082

Added:
   code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
   code/branches/pCuts/src/modules/tetris/TetrisBrick.h
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/TetrisCenterpoint.cc
   code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.h
   code/branches/pCuts/src/modules/tetris/TetrisPrereqs.h
   code/branches/pCuts/src/modules/tetris/TetrisStone.cc
   code/branches/pCuts/src/modules/tetris/TetrisStone.h
Log:
Trying to create tetris bricks. Rough implementation done. Still having a nasty camera bug. (see the debug output concerning the cameraIndex)

Modified: code/branches/pCuts/data/levels/tetris.oxw
===================================================================
--- code/branches/pCuts/data/levels/tetris.oxw	2012-04-05 09:12:08 UTC (rev 9081)
+++ code/branches/pCuts/data/levels/tetris.oxw	2012-04-11 13:53:43 UTC (rev 9082)
@@ -11,24 +11,30 @@
   include("templates/lodInformation.oxt")
 ?>
 
-<Template name=tetrisstonecameras defaults=0>
-  <TetrisStone>
+<Template name=tetrisbrickcameras defaults=0>
+  <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 />
     </camerapositions>
-  </TetrisStone>
+  </TetrisBrick>
 </Template>
 
 <Template name=tetrisstone>
-  <TetrisStone camerapositiontemplate=tetrisstonecameras>
+  <TetrisStone>
     <attached>
       <Model position="0,0,0" mesh="crate.mesh" scale=1 />
     </attached>
   </TetrisStone>
 </Template>
 
+<Template name=tetrisbrick>
+  <TetrisBrick camerapositiontemplate=tetrisbrickcameras>
+  </TetrisBrick>
+</Template>
+
+
 <Level
  gametype = "Tetris"
 >
@@ -49,7 +55,7 @@
       <SpawnPoint position="<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>" lookat="0,0,0" />
     <?lua end ?>
 
-    <TetrisCenterpoint name=tetriscenter width=11 height=15 stoneSize=10 stoneTemplate=tetrisstone stoneSpeed=10 position="-55,-75,0">
+    <TetrisCenterpoint name=tetriscenter width=11 height=15 stoneSize=10 stoneTemplate=tetrisstone brickTemplate=tetrisbrick stoneSpeed=10 position="-55,-75,0">
         <attached>
             <Model position="55,-1,0" mesh="cube.mesh" scale3D="57,1,11" />
             <Model position="-1,76,0" mesh="cube.mesh" scale3D="1,76,1" />

Modified: code/branches/pCuts/src/modules/tetris/CMakeLists.txt
===================================================================
--- code/branches/pCuts/src/modules/tetris/CMakeLists.txt	2012-04-05 09:12:08 UTC (rev 9081)
+++ code/branches/pCuts/src/modules/tetris/CMakeLists.txt	2012-04-11 13:53:43 UTC (rev 9082)
@@ -2,6 +2,7 @@
   Tetris.cc
   TetrisCenterpoint.cc
   TetrisStone.cc
+  TetrisBrick.cc
 )
 
 ORXONOX_ADD_LIBRARY(tetris

Modified: code/branches/pCuts/src/modules/tetris/Tetris.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/Tetris.cc	2012-04-05 09:12:08 UTC (rev 9081)
+++ code/branches/pCuts/src/modules/tetris/Tetris.cc	2012-04-11 13:53:43 UTC (rev 9082)
@@ -41,6 +41,7 @@
 
 #include "TetrisCenterpoint.h"
 #include "TetrisStone.h"
+#include "TetrisBrick.h"
 #include "infos/PlayerInfo.h"
 
 namespace orxonox
@@ -56,10 +57,10 @@
     {
         RegisterObject(Tetris);
 
-        this->activeStone_ = NULL;
+        this->activeBrick_ = NULL;
 
         // Pre-set the timer, but don't start it yet.
-        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::startStone, this)));
+        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::startBrick, this)));
         this->starttimer_.stopTimer();
 
         this->player_ = NULL;
@@ -81,6 +82,10 @@
     */
     void Tetris::cleanup()
     {
+        /*for(int i = 0;i < this->stones_.size(); i++) //TODO: Why isn't there any code like this
+        {                                              // compensating the 'new' statement?
+            delete this->stones_[i];
+        }//*/
 
     }
 
@@ -88,13 +93,13 @@
     {
         SUPER(Tetris, tick, dt);
 
-        if(this->activeStone_ != NULL)
+        if(this->activeBrick_ != NULL)
         {
-            if(!this->isValidStonePosition(this->activeStone_, this->activeStone_->getPosition()))
+            if(!this->isValidBrickPosition(this->activeBrick_, this->activeBrick_->getPosition()))
             {
-                this->activeStone_->setVelocity(Vector3::ZERO);
-                this->createStone();
-                this->startStone();
+                this->activeBrick_->setVelocity(Vector3::ZERO);
+                this->createBrick();
+                this->startBrick();
             }
         }
     }
@@ -122,6 +127,28 @@
         return true;
     }
 
+    /**
+    @brief
+        Check for each stone in a brick wether it is moved the right way.
+    */
+    bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position)
+    {
+        assert(brick);
+
+        for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
+        {
+            TetrisStone* stone = brick->getStone(i);
+            if(! this->isValidMove(stone, position + stone->getPosition())) // wrong position??
+                return false;
+            orxout()<< "stoneRelativePoistion: " << stone->getPosition() << endl;
+            orxout()<< "stoneTotalPoistion: " << position + stone->getPosition() << endl;
+        }
+        return true;
+
+    }
+
+
+
     bool Tetris::isValidStonePosition(TetrisStone* stone, const Vector3& position)
     {
         assert(stone);
@@ -129,28 +156,42 @@
         // we use a reverse iterator because we have to check for collisions with the topmost stones first
         for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
         {
-            if(stone == *it)
+            if(this->activeBrick_->contains(*it))
                 continue;
 
             const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
 
             if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
             {
-                this->activeStone_->setPosition(Vector3(this->activeStone_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeStone_->getPosition().z));
+                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
         }
 
         // 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
-        {
-            stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0f, stone->getPosition().z));
+        {//TODO: correct positioning !!
+        	this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f, this->activeBrick_->getPosition().z));
             return false;
         }
 
         return true;
     }
 
+    bool Tetris::isValidBrickPosition(TetrisBrick* brick, const Vector3& position)
+    {
+        assert(brick);
+
+        for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
+        {
+            TetrisStone* stone = brick->getStone(i);
+            if(! this->isValidStonePosition(stone, position + stone->getPosition()) ) // wrong position??
+                return false;
+        }
+        return true;
+
+    }
+
     /**
     @brief
         Starts the Tetris minigame.
@@ -160,7 +201,7 @@
         if (this->center_ != NULL) // There needs to be a TetrisCenterpoint, i.e. the area the game takes place.
         {
             // Create the first stone.
-            this->createStone();
+            this->createBrick();
         }
         else // If no centerpoint was specified, an error is thrown and the level is exited.
         {
@@ -224,52 +265,53 @@
         }
     }
 
-    /**
-    @brief
-        Starts the first stone.
-    */
-    void Tetris::startStone(void)
+
+
+    void Tetris::startBrick(void)
     {
         if(this->player_ == NULL)
             return;
 
         unsigned int cameraIndex = 0;
-        if(this->activeStone_ != NULL)
+        if(this->activeBrick_ != NULL)
         {
             // Get camera settings
-            cameraIndex = this->activeStone_->getCurrentCameraIndex();
+            cameraIndex = this->activeBrick_->getCurrentCameraIndex();
+            orxout() << "cameraIndex: " << this->activeBrick_->getCurrentCameraIndex() << endl;
             this->player_->stopControl();
         }
-        
-        // Make the last stone to be created the active stone.
-        this->activeStone_ = this->stones_.back();
-        
-        this->player_->startControl(this->activeStone_);
-        this->activeStone_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
-        this->activeStone_->setCameraPosition(cameraIndex);
+
+        // Make the last brick to be created the active brick.
+        this->activeBrick_ = this->bricks_.back();
+
+        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);
     }
 
-    /**
-    @brief
-        Creates a new stone.
-    */
-    void Tetris::createStone(void)
+    void Tetris::createBrick(void)             //TODO: random rotation offset between 0 and 3 (times 90°)
     {
-        // Create a new stone and add it to the list of stones.
-        TetrisStone* stone = new TetrisStone(this->center_);
-        this->stones_.push_back(stone);
-        
+        // 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++)
+        {
+            this->stones_.push_back(brick->getStone(i));
+        }
+
         // Apply the stone template to the stone.
-        stone->addTemplate(this->center_->getStoneTemplate());
-        
-        // Attach the stone to the Centerpoint and set the position of the stone to be at the top middle.
-        this->center_->attach(stone);
+        brick->addTemplate(this->center_->getStoneTemplate()); // TODO: find error concerning the cameras
+
+        // 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();
-        stone->setPosition(xPos, yPos, 0.0f);
-        stone->setGame(this);
+        brick->setPosition(xPos, yPos, 0.0f);
+        brick->setGame(this);
     }
 
+
     /**
     @brief
         Get the player.
@@ -281,6 +323,11 @@
         return this->player_;
     }
 
+    /*TetrisCenterpoint* Tetris::getCenterpoint(void) const
+    {
+        return this->center_;
+    }*/
+
     /**
     @brief Set the TetrisCenterpoint (the playing field).
     @param center A pointer to the TetrisCenterpoint to be set.

Modified: code/branches/pCuts/src/modules/tetris/Tetris.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/Tetris.h	2012-04-05 09:12:08 UTC (rev 9081)
+++ code/branches/pCuts/src/modules/tetris/Tetris.h	2012-04-11 13:53:43 UTC (rev 9082)
@@ -67,24 +67,29 @@
             void setCenterpoint(TetrisCenterpoint* center);
 
             PlayerInfo* getPlayer(void) const; //!< Get the player.
+            WeakPtr<TetrisCenterpoint> getCenterpoint(void)
+                { return this->center_; }
 
             bool isValidMove(TetrisStone* stone, const Vector3& position);
+            bool isValidMove(TetrisBrick* brick, const Vector3& position);
 
         protected:
             virtual void spawnPlayersIfRequested(); //!< Spawns player.
 
         private:
-            void startStone(void); //!< Starts with the first stone.
-            void createStone(void);
+            void startBrick(void);
+            void createBrick(void);
             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);
             
             PlayerInfo* player_;
 
             WeakPtr<TetrisCenterpoint> center_; //!< The playing field.
+            std::vector<TetrisBrick*> bricks_; //!< A list of all bricks in play.
             std::vector<TetrisStone*> stones_; //!< A list of all stones in play.
             std::vector< std::vector<bool> > grid_;
-            TetrisStone* activeStone_;
+            TetrisBrick* activeBrick_;
             
             Timer starttimer_; //!< A timer to delay the start of the game.
     };

Added: code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisBrick.cc	                        (rev 0)
+++ code/branches/pCuts/src/modules/tetris/TetrisBrick.cc	2012-04-11 13:53:43 UTC (rev 9082)
@@ -0,0 +1,252 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      ...
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file TetrisBrick.cc
+    @brief Implementation of the TetrisBrick class.
+*/
+
+#include "TetrisBrick.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+#include "TetrisCenterpoint.h"
+#include "TetrisStone.h"
+#include "Tetris.h"
+
+namespace orxonox
+{
+    CreateFactory(TetrisBrick);
+
+    /**
+    @brief
+        Constructor. Registers and initializes the object.
+    */
+    TetrisBrick::TetrisBrick(BaseObject* creator): ControllableEntity(creator)
+    {
+        RegisterObject(TetrisBrick);
+
+        this->shapeIndex_ = 6; //<! TODO: 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)));
+        this->lockRotation_ = false;
+        this->tetris_ = this->getTetris();
+        this->size_ = 10.0f; //TODO: fix this via this->tetris_->center_->getStoneSize();
+
+
+        this->createBrick(); //<! create a whole new Brick;
+    }
+
+    /**
+    @brief
+        This function partly initializes a TetrisBrick as an array of TetrisStones
+    */
+    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++)
+        {
+            // Create a new stone and add it to the brick.
+            TetrisStone* stone = new TetrisStone(this);
+            stone->setHealth(1.0f); //TODO: is this value low enough ?
+            this->brickStones_.push_back(stone);
+            this->attach(stone);
+            this->formBrick(stone, i);
+            if(this->tetris_ != NULL)
+            {
+                stone->setGame(this->tetris_);
+                if(this->tetris_->getCenterpoint() != NULL)
+                    stone->addTemplate(this->tetris_->getCenterpoint()->getStoneTemplate());
+                else
+                	orxout()<< "tetris_->getCenterpoint == NULL in TetrisBrick.cc"<< endl;
+            }
+            else
+                orxout()<< "tetris_ == NULL in TetrisBrick.cc"<< endl;
+        }
+    }
+
+    /**
+    @brief
+        This function creates the shape of a TetrisBrick. ! Spaghetti-Code !
+    @param i
+        The stone's number.
+    @param stone
+        The TetrisStone that is placed relative to the brick's position.
+    */
+    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);
+        }
+        else if(i == 1)
+        {
+            stone->setPosition(0.0f, size_, 0.0f);
+        }
+        else if(i == 2)
+        {
+            if(this->shapeIndex_ == 1 || this->shapeIndex_ == 6 || this->shapeIndex_ == 7)
+            {
+            	stone->setPosition(0.0f, 2*size_, 0.0f);
+            }
+            else if(this->shapeIndex_ == 3 || this->shapeIndex_ == 4|| this->shapeIndex_ == 5)
+            {
+            	stone->setPosition(size_, 0, 0.0f);
+            }
+            else if(this->shapeIndex_ == 2)
+            {
+            	stone->setPosition(-size_, 0, 0.0f);
+            }
+        }
+        else if(i == 3)
+        {
+            if(this->shapeIndex_ == 2 || this->shapeIndex_ == 5)
+            {
+            	stone->setPosition(size_, size_, 0.0f);
+            }
+            else if(this->shapeIndex_ == 1)
+            {
+            	stone->setPosition(0, 3*size_, 0.0f);
+            }
+            else if(this->shapeIndex_ == 3 || this->shapeIndex_ == 7)
+            {
+            	stone->setPosition(-size_, 0, 0.0f);
+            }
+            else if(this->shapeIndex_ == 4)
+            {
+            	stone->setPosition(-size_, size_, 0.0f);
+            }
+            else if(this->shapeIndex_ == 6)
+            {
+            	stone->setPosition(size_, 0, 0.0f);
+            }
+        }
+    }
+
+    bool TetrisBrick::isValidMove(Vector3& position)
+    {
+
+        for(unsigned int i = 0; i < this->stonesPerBrick_ ; i++)
+        {//TODO: check if isValidMove works with this function,
+            if(this->tetris_->isValidMove(this->brickStones_[i], position))
+            	continue;
+            else
+            	return false;
+        }
+        return true;
+    }
+
+    TetrisStone* TetrisBrick::getStone(unsigned int i)
+    {
+    	if(i < this->brickStones_.size())
+            return this->brickStones_[i];
+    	else return NULL;
+    }
+
+
+    Tetris* TetrisBrick::getTetris()
+    {
+        if (this->getGametype() != NULL && this->getGametype()->isA(Class(Tetris)))
+        {
+            Tetris* tetrisGametype = orxonox_cast<Tetris*>(this->getGametype().get());
+            return tetrisGametype;
+        }
+        return NULL;
+    }
+
+    bool TetrisBrick::contains(TetrisStone* stone)
+    {
+        for(unsigned int i = 0; i < brickStones_.size(); i++)
+        {
+            if(stone == brickStones_[i])
+                return true;
+        }
+        return false;
+    }
+
+    /**
+    @brief
+        Overloaded the function to rotate the Brick.
+    @param value
+        A vector whose first component is the angle by which to rotate.
+    */
+    void TetrisBrick::moveFrontBack(const Vector2& value)
+    {
+        if(value.x < 0) //speedup on key down
+        {
+            this->setVelocity(this->getVelocity()*1.1);
+        }
+        else if(!this->lockRotation_) //rotate when key up is pressed
+        {
+            orxout() << "The object should be rolled soon." << endl;
+            this->lockRotation_ = true; // multiple calls of this function have to be filtered out.
+            this->rotationTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&TetrisBrick::unlockRotation, this)));
+            Quaternion q(Degree(90), Vector3::UNIT_Z);
+            this->setOrientation(this->getOrientation()*q); //rotation: roll 90°
+
+        }
+    }
+
+    /**
+    @brief
+        Overloaded the function to steer the Brick right and left
+    @param value
+        A vector whose first component is the direction in which we want to steer the Brick.
+    */
+    void TetrisBrick::moveRightLeft(const Vector2& value)
+    {
+        if(!this->delay_)
+        {
+            const Vector3& position = this->getPosition();
+            Vector3 newPos = Vector3(position.x+value.x/abs(value.x)*this->size_, position.y, position.z);
+            if(!this->isValidMove(newPos))
+                return;
+
+            this->setPosition(newPos);
+            this->delay_ = true;
+            this->delayTimer_.startTimer();
+        }
+    }
+
+    /**
+    @brief
+        Is called when the player changed.
+    */
+    void TetrisBrick::changedPlayer()
+    {
+        this->setVelocity(0.0f, 0.0f, 0.0f);
+    }
+
+}

Added: code/branches/pCuts/src/modules/tetris/TetrisBrick.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisBrick.h	                        (rev 0)
+++ code/branches/pCuts/src/modules/tetris/TetrisBrick.h	2012-04-11 13:53:43 UTC (rev 9082)
@@ -0,0 +1,103 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      ...
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file TetrisBrick.h
+    @brief Declaration of the TetrisBrick class.
+    @ingroup Tetris
+*/
+
+#ifndef _TetrisBrick_H__
+#define _TetrisBrick_H__
+
+#include "tetris/TetrisPrereqs.h"
+
+#include "worldentities/ControllableEntity.h"
+#include "tools/Timer.h"
+
+namespace orxonox
+{
+
+    /**
+    @brief
+        ContainerClass in order to create TetrisBricks by combining TetrisStones.
+    @author
+
+    @ingroup Tetris
+    */
+    class _TetrisExport TetrisBrick : public ControllableEntity
+    {
+        public:
+            TetrisBrick(BaseObject* creator); //!< Constructor. Registers and initializes the object.
+            virtual ~TetrisBrick() {}
+
+            virtual void moveFrontBack(const Vector2& value); //!< Overloaded the function to steer the bat up and down.
+            virtual void moveRightLeft(const Vector2& value); //!< Overloaded the function to steer the bat up and down.
+            virtual void changedPlayer(); //!< Is called when the player changed.
+
+            bool isValidMove(Vector3& position);
+            unsigned int getNumberOfStones(void) const
+                { return this->brickStones_.size(); }
+            TetrisStone* getStone(unsigned int i);
+            bool contains(TetrisStone* stone);
+
+            void setGame(Tetris* tetris)
+                { assert(tetris); tetris_ = tetris; }
+
+        protected:
+            void createBrick(void); //!< Create a cluster of TetrisStones
+            void formBrick(TetrisStone* stone, unsigned int i);
+            Tetris* getTetris();
+
+            unsigned int shapeIndex_; //!< My way to represent the different brick shapes.
+            unsigned int stonesPerBrick_; //!< So many stones are contained in this brick.
+            std::vector<TetrisStone*> brickStones_; //!< A list of all stones in a brick.
+
+
+            void enableMovement(void)
+                { this->delay_ = false; }
+            void unlockRotation(void)
+                { this->lockRotation_ = false; }
+
+            float getSize(void) const
+                { return this->size_; }
+
+
+            float size_; //!< The dimensions a stone has in the game world. //TODO: get stone dimensions
+            bool delay_;
+            bool lockRotation_;
+
+            Timer delayTimer_;
+            Timer rotationTimer_; ///!< This timer is used to filter out multiple rotation inputs.
+            Tetris* tetris_; //<! The Tetris class is responsible to initialize this value.
+           // TetrisCenterpoint* center_;
+
+    };
+}
+
+#endif /* _TetrisBrick_H__ */

Modified: code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc	2012-04-05 09:12:08 UTC (rev 9081)
+++ code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc	2012-04-11 13:53:43 UTC (rev 9082)
@@ -54,6 +54,7 @@
         this->height_ = 11;
         this->stoneSize_ = 10.0f;
         this->stoneTemplate_ = "";
+        this->brickTemplate_ = "";
         this->stoneSpeed_ = 20.0f;
         
         this->checkGametype();
@@ -68,9 +69,10 @@
         SUPER(TetrisCenterpoint, XMLPort, xmlelement, mode);
 
         XMLPortParam(TetrisCenterpoint, "width", setWidth, getWidth, xmlelement, mode); // die Breite
-        XMLPortParam(TetrisCenterpoint, "height", setHeight, setWidth, xmlelement, mode); // die Grösse
+        XMLPortParam(TetrisCenterpoint, "height", setHeight, getHeight, xmlelement, mode); // die Grösse //was sollte das mit setWidth??
         XMLPortParam(TetrisCenterpoint, "stoneSize", setStoneSize, getStoneSize, xmlelement, mode); 
         XMLPortParam(TetrisCenterpoint, "stoneTemplate", setStoneTemplate, getStoneTemplate, xmlelement, mode);
+        XMLPortParam(TetrisCenterpoint, "brickTemplate", setBrickTemplate, getBrickTemplate, xmlelement, mode);
         XMLPortParam(TetrisCenterpoint, "stoneSpeed", setStoneSpeed, getStoneSpeed, xmlelement, mode);
     }
 

Modified: code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.h	2012-04-05 09:12:08 UTC (rev 9081)
+++ code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.h	2012-04-11 13:53:43 UTC (rev 9082)
@@ -44,7 +44,8 @@
 #include "worldentities/StaticEntity.h"
 
 namespace orxonox
-{
+{//idea: add 2 triggers to the centerpoint (one to determine when a box would go above the centerpoint;
+//the other to find out when the lowest row is filled totally)
     
     /**
     @brief
@@ -117,6 +118,19 @@
                 { return this->stoneTemplate_; }
             
             /**
+            @brief Set the template for the bricks.
+            @param template The template name to be applied to each brick.
+            */
+            void setBrickTemplate(const std::string& templateName)
+                { this->brickTemplate_ = templateName; }
+            /**
+            @brief Get the template for the bricks.
+            @return Returns the template name to be applied to each brick.
+            */
+            const std::string& getBrickTemplate(void) const
+                { return this->brickTemplate_; }
+
+            /**
             @brief Set the speed of the stones.
             @param speed The speed to be set.
             */
@@ -136,6 +150,7 @@
             unsigned int height_;
             float stoneSize_;
             std::string stoneTemplate_;
+            std::string brickTemplate_;
             float stoneSpeed_;
 
     };

Modified: code/branches/pCuts/src/modules/tetris/TetrisPrereqs.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisPrereqs.h	2012-04-05 09:12:08 UTC (rev 9081)
+++ code/branches/pCuts/src/modules/tetris/TetrisPrereqs.h	2012-04-11 13:53:43 UTC (rev 9082)
@@ -67,6 +67,7 @@
     class Tetris;
     class TetrisCenterpoint;
     class TetrisStone;
+    class TetrisBrick;
 }
 
 #endif /* _TetrisPrereqs_H__ */

Modified: code/branches/pCuts/src/modules/tetris/TetrisStone.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisStone.cc	2012-04-05 09:12:08 UTC (rev 9081)
+++ code/branches/pCuts/src/modules/tetris/TetrisStone.cc	2012-04-11 13:53:43 UTC (rev 9082)
@@ -36,8 +36,6 @@
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
 
-#include <OgreSceneNode.h>
-
 #include "Tetris.h"
 
 namespace orxonox

Modified: code/branches/pCuts/src/modules/tetris/TetrisStone.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisStone.h	2012-04-05 09:12:08 UTC (rev 9081)
+++ code/branches/pCuts/src/modules/tetris/TetrisStone.h	2012-04-11 13:53:43 UTC (rev 9082)
@@ -87,7 +87,7 @@
             bool delay_;
             bool lockRotation_;
             Timer delayTimer_;
-            Timer rotationTimer_;
+            Timer rotationTimer_; ///!< This timer is used to filter out multiple rotation inputs.
 
             Tetris* tetris_;
     };




More information about the Orxonox-commit mailing list