Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9082


Ignore:
Timestamp:
Apr 11, 2012, 3:53:43 PM (12 years ago)
Author:
jo
Message:

Trying to create tetris bricks. Rough implementation done. Still having a nasty camera bug. (see the debug output concerning the cameraIndex)

Location:
code/branches/pCuts
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pCuts/data/levels/tetris.oxw

    r9016 r9082  
    1212?>
    1313
    14 <Template name=tetrisstonecameras defaults=0>
    15   <TetrisStone>
     14<Template name=tetrisbrickcameras defaults=0>
     15  <TetrisBrick>
    1616    <camerapositions>
    1717      <CameraPosition position="55,75,200" absolute=true />
     
    1919      <CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true />
    2020    </camerapositions>
    21   </TetrisStone>
     21  </TetrisBrick>
    2222</Template>
    2323
    2424<Template name=tetrisstone>
    25   <TetrisStone camerapositiontemplate=tetrisstonecameras>
     25  <TetrisStone>
    2626    <attached>
    2727      <Model position="0,0,0" mesh="crate.mesh" scale=1 />
     
    2929  </TetrisStone>
    3030</Template>
     31
     32<Template name=tetrisbrick>
     33  <TetrisBrick camerapositiontemplate=tetrisbrickcameras>
     34  </TetrisBrick>
     35</Template>
     36
    3137
    3238<Level
     
    5056    <?lua end ?>
    5157
    52     <TetrisCenterpoint name=tetriscenter width=11 height=15 stoneSize=10 stoneTemplate=tetrisstone stoneSpeed=10 position="-55,-75,0">
     58    <TetrisCenterpoint name=tetriscenter width=11 height=15 stoneSize=10 stoneTemplate=tetrisstone brickTemplate=tetrisbrick stoneSpeed=10 position="-55,-75,0">
    5359        <attached>
    5460            <Model position="55,-1,0" mesh="cube.mesh" scale3D="57,1,11" />
  • code/branches/pCuts/src/modules/tetris/CMakeLists.txt

    r8706 r9082  
    33  TetrisCenterpoint.cc
    44  TetrisStone.cc
     5  TetrisBrick.cc
    56)
    67
  • code/branches/pCuts/src/modules/tetris/Tetris.cc

    r8858 r9082  
    4242#include "TetrisCenterpoint.h"
    4343#include "TetrisStone.h"
     44#include "TetrisBrick.h"
    4445#include "infos/PlayerInfo.h"
    4546
     
    5758        RegisterObject(Tetris);
    5859
    59         this->activeStone_ = NULL;
     60        this->activeBrick_ = NULL;
    6061
    6162        // Pre-set the timer, but don't start it yet.
    62         this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::startStone, this)));
     63        this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Tetris::startBrick, this)));
    6364        this->starttimer_.stopTimer();
    6465
     
    8283    void Tetris::cleanup()
    8384    {
     85        /*for(int i = 0;i < this->stones_.size(); i++) //TODO: Why isn't there any code like this
     86        {                                              // compensating the 'new' statement?
     87            delete this->stones_[i];
     88        }//*/
    8489
    8590    }
     
    8994        SUPER(Tetris, tick, dt);
    9095
    91         if(this->activeStone_ != NULL)
    92         {
    93             if(!this->isValidStonePosition(this->activeStone_, this->activeStone_->getPosition()))
     96        if(this->activeBrick_ != NULL)
     97        {
     98            if(!this->isValidBrickPosition(this->activeBrick_, this->activeBrick_->getPosition()))
    9499            {
    95                 this->activeStone_->setVelocity(Vector3::ZERO);
    96                 this->createStone();
    97                 this->startStone();
     100                this->activeBrick_->setVelocity(Vector3::ZERO);
     101                this->createBrick();
     102                this->startBrick();
    98103            }
    99104        }
     
    123128    }
    124129
     130    /**
     131    @brief
     132        Check for each stone in a brick wether it is moved the right way.
     133    */
     134    bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position)
     135    {
     136        assert(brick);
     137
     138        for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
     139        {
     140            TetrisStone* stone = brick->getStone(i);
     141            if(! this->isValidMove(stone, position + stone->getPosition())) // wrong position??
     142                return false;
     143            orxout()<< "stoneRelativePoistion: " << stone->getPosition() << endl;
     144            orxout()<< "stoneTotalPoistion: " << position + stone->getPosition() << endl;
     145        }
     146        return true;
     147
     148    }
     149
     150
     151
    125152    bool Tetris::isValidStonePosition(TetrisStone* stone, const Vector3& position)
    126153    {
     
    130157        for(std::vector<TetrisStone*>::const_reverse_iterator it = this->stones_.rbegin(); it != this->stones_.rend(); ++it)
    131158        {
    132             if(stone == *it)
     159            if(this->activeBrick_->contains(*it))
    133160                continue;
    134161
     
    137164            if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
    138165            {
    139                 this->activeStone_->setPosition(Vector3(this->activeStone_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeStone_->getPosition().z));
     166                this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->getPosition().z));
    140167                return false;
    141168            }// This case applies if the stones overlap partially vertically
     
    144171        // after we checked for collision with all stones, we also check for collision with the bottom
    145172        if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
    146         {
    147             stone->setPosition(Vector3(stone->getPosition().x, this->center_->getStoneSize()/2.0f, stone->getPosition().z));
     173        {//TODO: correct positioning !!
     174                this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f, this->activeBrick_->getPosition().z));
    148175            return false;
    149176        }
     
    152179    }
    153180
     181    bool Tetris::isValidBrickPosition(TetrisBrick* brick, const Vector3& position)
     182    {
     183        assert(brick);
     184
     185        for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
     186        {
     187            TetrisStone* stone = brick->getStone(i);
     188            if(! this->isValidStonePosition(stone, position + stone->getPosition()) ) // wrong position??
     189                return false;
     190        }
     191        return true;
     192
     193    }
     194
    154195    /**
    155196    @brief
     
    161202        {
    162203            // Create the first stone.
    163             this->createStone();
     204            this->createBrick();
    164205        }
    165206        else // If no centerpoint was specified, an error is thrown and the level is exited.
     
    225266    }
    226267
    227     /**
    228     @brief
    229         Starts the first stone.
    230     */
    231     void Tetris::startStone(void)
     268
     269
     270    void Tetris::startBrick(void)
    232271    {
    233272        if(this->player_ == NULL)
     
    235274
    236275        unsigned int cameraIndex = 0;
    237         if(this->activeStone_ != NULL)
     276        if(this->activeBrick_ != NULL)
    238277        {
    239278            // Get camera settings
    240             cameraIndex = this->activeStone_->getCurrentCameraIndex();
     279            cameraIndex = this->activeBrick_->getCurrentCameraIndex();
     280            orxout() << "cameraIndex: " << this->activeBrick_->getCurrentCameraIndex() << endl;
    241281            this->player_->stopControl();
    242282        }
    243        
    244         // Make the last stone to be created the active stone.
    245         this->activeStone_ = this->stones_.back();
    246        
    247         this->player_->startControl(this->activeStone_);
    248         this->activeStone_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
    249         this->activeStone_->setCameraPosition(cameraIndex);
    250     }
    251 
    252     /**
    253     @brief
    254         Creates a new stone.
    255     */
    256     void Tetris::createStone(void)
    257     {
    258         // Create a new stone and add it to the list of stones.
    259         TetrisStone* stone = new TetrisStone(this->center_);
    260         this->stones_.push_back(stone);
    261        
     283
     284        // Make the last brick to be created the active brick.
     285        this->activeBrick_ = this->bricks_.back();
     286
     287        this->player_->startControl(this->activeBrick_);
     288        this->activeBrick_->setVelocity(0.0f, -this->center_->getStoneSpeed(), 0.0f);
     289        orxout() << "velocity: " << this->center_->getStoneSpeed() << endl;
     290        this->activeBrick_->setCameraPosition(cameraIndex);
     291    }
     292
     293    void Tetris::createBrick(void)             //TODO: random rotation offset between 0 and 3 (times 90°)
     294    {
     295        // Create a new brick and add it to the list of bricks && to the list of stones.
     296        TetrisBrick* brick = new TetrisBrick(this->center_);
     297        this->bricks_.push_back(brick);
     298        for (unsigned int i = 0; i < brick->getNumberOfStones(); i++)
     299        {
     300            this->stones_.push_back(brick->getStone(i));
     301        }
     302
    262303        // Apply the stone template to the stone.
    263         stone->addTemplate(this->center_->getStoneTemplate());
    264        
    265         // Attach the stone to the Centerpoint and set the position of the stone to be at the top middle.
    266         this->center_->attach(stone);
     304        brick->addTemplate(this->center_->getStoneTemplate()); // TODO: find error concerning the cameras
     305
     306        // Attach the brick to the Centerpoint and set the position of the brick to be at the top middle.
     307        this->center_->attach(brick);
    267308        float xPos = (this->center_->getWidth()/2 + ((this->center_->getWidth() % 2)*2-1)/2.0f)*this->center_->getStoneSize();
    268309        float yPos = (this->center_->getHeight()-0.5f)*this->center_->getStoneSize();
    269         stone->setPosition(xPos, yPos, 0.0f);
    270         stone->setGame(this);
    271     }
     310        brick->setPosition(xPos, yPos, 0.0f);
     311        brick->setGame(this);
     312    }
     313
    272314
    273315    /**
     
    282324    }
    283325
     326    /*TetrisCenterpoint* Tetris::getCenterpoint(void) const
     327    {
     328        return this->center_;
     329    }*/
     330
    284331    /**
    285332    @brief Set the TetrisCenterpoint (the playing field).
  • code/branches/pCuts/src/modules/tetris/Tetris.h

    r8706 r9082  
    6868
    6969            PlayerInfo* getPlayer(void) const; //!< Get the player.
     70            WeakPtr<TetrisCenterpoint> getCenterpoint(void)
     71                { return this->center_; }
    7072
    7173            bool isValidMove(TetrisStone* stone, const Vector3& position);
     74            bool isValidMove(TetrisBrick* brick, const Vector3& position);
    7275
    7376        protected:
     
    7578
    7679        private:
    77             void startStone(void); //!< Starts with the first stone.
    78             void createStone(void);
     80            void startBrick(void);
     81            void createBrick(void);
    7982            void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
    8083            bool isValidStonePosition(TetrisStone* stone, const Vector3& position);
     84            bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position);
    8185           
    8286            PlayerInfo* player_;
    8387
    8488            WeakPtr<TetrisCenterpoint> center_; //!< The playing field.
     89            std::vector<TetrisBrick*> bricks_; //!< A list of all bricks in play.
    8590            std::vector<TetrisStone*> stones_; //!< A list of all stones in play.
    8691            std::vector< std::vector<bool> > grid_;
    87             TetrisStone* activeStone_;
     92            TetrisBrick* activeBrick_;
    8893           
    8994            Timer starttimer_; //!< A timer to delay the start of the game.
  • code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.cc

    r8706 r9082  
    5555        this->stoneSize_ = 10.0f;
    5656        this->stoneTemplate_ = "";
     57        this->brickTemplate_ = "";
    5758        this->stoneSpeed_ = 20.0f;
    5859       
     
    6970
    7071        XMLPortParam(TetrisCenterpoint, "width", setWidth, getWidth, xmlelement, mode); // die Breite
    71         XMLPortParam(TetrisCenterpoint, "height", setHeight, setWidth, xmlelement, mode); // die Grösse
     72        XMLPortParam(TetrisCenterpoint, "height", setHeight, getHeight, xmlelement, mode); // die Grösse //was sollte das mit setWidth??
    7273        XMLPortParam(TetrisCenterpoint, "stoneSize", setStoneSize, getStoneSize, xmlelement, mode);
    7374        XMLPortParam(TetrisCenterpoint, "stoneTemplate", setStoneTemplate, getStoneTemplate, xmlelement, mode);
     75        XMLPortParam(TetrisCenterpoint, "brickTemplate", setBrickTemplate, getBrickTemplate, xmlelement, mode);
    7476        XMLPortParam(TetrisCenterpoint, "stoneSpeed", setStoneSpeed, getStoneSpeed, xmlelement, mode);
    7577    }
  • code/branches/pCuts/src/modules/tetris/TetrisCenterpoint.h

    r8706 r9082  
    4545
    4646namespace orxonox
    47 {
     47{//idea: add 2 triggers to the centerpoint (one to determine when a box would go above the centerpoint;
     48//the other to find out when the lowest row is filled totally)
    4849   
    4950    /**
     
    118119           
    119120            /**
     121            @brief Set the template for the bricks.
     122            @param template The template name to be applied to each brick.
     123            */
     124            void setBrickTemplate(const std::string& templateName)
     125                { this->brickTemplate_ = templateName; }
     126            /**
     127            @brief Get the template for the bricks.
     128            @return Returns the template name to be applied to each brick.
     129            */
     130            const std::string& getBrickTemplate(void) const
     131                { return this->brickTemplate_; }
     132
     133            /**
    120134            @brief Set the speed of the stones.
    121135            @param speed The speed to be set.
     
    137151            float stoneSize_;
    138152            std::string stoneTemplate_;
     153            std::string brickTemplate_;
    139154            float stoneSpeed_;
    140155
  • code/branches/pCuts/src/modules/tetris/TetrisPrereqs.h

    r8706 r9082  
    6868    class TetrisCenterpoint;
    6969    class TetrisStone;
     70    class TetrisBrick;
    7071}
    7172
  • code/branches/pCuts/src/modules/tetris/TetrisStone.cc

    r9081 r9082  
    3636#include "core/CoreIncludes.h"
    3737#include "core/XMLPort.h"
    38 
    39 #include <OgreSceneNode.h>
    4038
    4139#include "Tetris.h"
  • code/branches/pCuts/src/modules/tetris/TetrisStone.h

    r9081 r9082  
    8888            bool lockRotation_;
    8989            Timer delayTimer_;
    90             Timer rotationTimer_;
     90            Timer rotationTimer_; ///!< This timer is used to filter out multiple rotation inputs.
    9191
    9292            Tetris* tetris_;
Note: See TracChangeset for help on using the changeset viewer.