Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 12, 2012, 7:05:57 PM (12 years ago)
Author:
jo
Message:

Rotating bricks works. Next step: repairing the collision detection.

File:
1 edited

Legend:

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

    r9082 r9084  
    130130    /**
    131131    @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)
     132        Check for each stone in a brick if it is moved the right way.
     133    */
     134    bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation = false)
    135135    {
    136136        assert(brick);
     
    139139        {
    140140            TetrisStone* stone = brick->getStone(i);
    141             if(! this->isValidMove(stone, position + stone->getPosition())) // wrong position??
     141            Vector3 stonePosition;
     142            if(isRotation)
     143                stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()+1);
     144            else
     145                stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
     146
     147            /*orxout()<< "stoneRelativePoistion: " << stonePosition << endl;
     148            orxout()<< "stoneTotalPoistion   : " << position + stonePosition << endl;*/
     149
     150            if(! this->isValidMove(stone, position + stonePosition )) // wrong position??
     151            {
    142152                return false;
    143             orxout()<< "stoneRelativePoistion: " << stone->getPosition() << endl;
    144             orxout()<< "stoneTotalPoistion: " << position + stone->getPosition() << endl;
     153            }
    145154        }
    146155        return true;
     
    159168            if(this->activeBrick_->contains(*it))
    160169                continue;
    161 
    162             const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
     170//TODO: is this rotation correct ??
     171            Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount());
     172            //!< Saves the position of the currentStone
    163173
    164174            if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
    165             {
     175            {//TODO: Why are such events not detected ??
     176                orxout()<< "YEAY !!"<<endl;
    166177                this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->getPosition().z));
    167178                return false;
     
    171182        // after we checked for collision with all stones, we also check for collision with the bottom
    172183        if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
    173         {//TODO: correct positioning !!
    174                 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f, this->activeBrick_->getPosition().z));
     184        {
     185                int yOffset = stone->getPosition().y;//calculate offset
     186                this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f+yOffset, this->activeBrick_->getPosition().z));
    175187            return false;
    176188        }
     
    186198        {
    187199            TetrisStone* stone = brick->getStone(i);
    188             if(! this->isValidStonePosition(stone, position + stone->getPosition()) ) // wrong position??
     200            Vector3 stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
     201            if(! this->isValidStonePosition(stone, position + stonePosition) )
    189202                return false;
    190203        }
    191204        return true;
    192 
     205    }
     206
     207    /**
     208    @brief
     209        Nasty function that allocates memory!! it rolls a vector 90° * amount
     210    */
     211    Vector3 Tetris::rotateVector(Vector3 position, unsigned int amount)
     212    {
     213
     214        int temp = 0;
     215        for(unsigned int i = 0; i < amount; i++)
     216        {
     217            temp = position.x;
     218            position.x = -position.y;
     219            position.y = temp;
     220        }
     221        return position;
    193222    }
    194223
Note: See TracChangeset for help on using the changeset viewer.