Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8488 for code/branches/tetris


Ignore:
Timestamp:
May 16, 2011, 3:13:56 PM (14 years ago)
Author:
youngk
Message:

Created a skeleton for the position validation of a stone.

Location:
code/branches/tetris/src/modules/tetris
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tetris/src/modules/tetris/Tetris.cc

    r8249 r8488  
    9090        if(stone != NULL)
    9191        {
     92            // Get the current position of the active stone
    9293            Vector3 position = stone->getPosition();
    93             if(position.x < this->center_->getStoneSize()/2.0)
     94           
     95            if(position.x < this->center_->getStoneSize()/2.0)  //!< If the stone touches the left edge of the level
    9496                position.x = this->center_->getStoneSize()/2.0;
    95             else if(position.x > (this->center_->getWidth()-0.5)*this->center_->getStoneSize())
     97            else if(position.x > (this->center_->getWidth()-0.5)*this->center_->getStoneSize()) //!< If the stone touches the right edge of the level
    9698                position.x = (this->center_->getWidth()-0.5)*this->center_->getStoneSize();
    97            
    98             if(position.y < this->center_->getStoneSize()/2.0)
     99
     100            if(!this->correctStonePos(stone)) //!< If the stone touches another stone
     101            {
     102                stone->setVelocity(Vector3::ZERO);
     103                this->createStone();
     104                this->startStone();
     105            }
     106
     107            if(position.y < this->center_->getStoneSize()/2.0) //!< If the stone has reached the bottom of the level
    99108            {
    100109                position.y = this->center_->getStoneSize()/2.0;
     
    222231    /**
    223232    @brief
     233        Validate the stone position.
     234    @return
     235        Returns whether the supplied stone is in the correct position.
     236    */
     237    bool Tetris::correctStonePos(TetrisStone* stone)
     238    {
     239        for(std::vector<TetrisStone*>::const_iterator it = this->stones_.begin(); it != this->stones_.end(); ++it)
     240        {
     241            TetrisStone* currentStone = it->_Ptr(); //!< Gives access to the current stone in the list
     242            Vector3 currentStonePosition = it->_Ptr()->getPosition(); //!< Saves the position of the currentStone
     243            Vector3 stonePosition = stone->getPosition(); //!< Saves the position of the supplied stone
     244           
     245            // @TODO:   Use the TetrisStone member functions to check both stones for an overlap.
     246            //          Also make sure to correct the stone position accordingly.
     247            //
     248            // This case applies if the stones overlap completely
     249            //if((stonePosition.x == currentStonePosition.x) && (stonePosition.y == currentStonePosition.y))
     250            // This case applies if the stones overlap partially vertically
     251            //if(stonePosition.y - stone->getHeight()/2 < currentStonePosition.y + currentStone->getHeight()/2)
     252
     253           
     254        }
     255    }
     256
     257    /**
     258    @brief
    224259        Get the player.
    225260    @return
  • code/branches/tetris/src/modules/tetris/Tetris.h

    r8249 r8488  
    8080            void createStone(void);
    8181            void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
     82            bool correctStonePos(TetrisStone* stone); //!< Check whether the supplied stone is in an allowed position
    8283           
    8384            PlayerInfo* player_;
Note: See TracChangeset for help on using the changeset viewer.