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/TetrisBrick.cc

    r9083 r9084  
    5353        RegisterObject(TetrisBrick);
    5454
    55         this->shapeIndex_ = 3; //<! TODO: random number between 0 and 7
     55        this->shapeIndex_ = 1; //<! TODO: random number between 0 and 7
    5656        this->stonesPerBrick_ = 4; //<! most tetris bricks is formed by 4 stones
    5757        this->delay_ = false;
     
    6060        this->tetris_ = this->getTetris();
    6161        this->size_ = 10.0f; //TODO: fix this via this->tetris_->center_->getStoneSize();
    62 
    63 
     62        this->rotationCount_ = 0;
    6463        this->createBrick(); //<! create a whole new Brick;
    6564    }
     
    7978            // Create a new stone and add it to the brick.
    8079            TetrisStone* stone = new TetrisStone(this);
    81             stone->setHealth(1.0f); //TODO: is this value low enough ?
     80            stone->setHealth(1.0f);
    8281            this->brickStones_.push_back(stone);
    8382            this->attach(stone);
     
    156155    }
    157156
    158     bool TetrisBrick::isValidMove(Vector3& position)
    159     {
    160 
    161         for(unsigned int i = 0; i < this->stonesPerBrick_ ; i++)
    162         {//TODO: check if isValidMove works with this function,
    163             if(this->tetris_->isValidMove(this->brickStones_[i], position))
    164                 continue;
    165             else
    166                 return false;
    167         }
    168         return true;
     157    bool TetrisBrick::isValidMove(const Vector3& position, bool isRotation = false)
     158    {
     159        return this->tetris_->isValidMove(this,position, isRotation);
    169160    }
    170161
     
    211202        else if(!this->lockRotation_) //rotate when key up is pressed
    212203        {
    213             orxout() << "The object should be rolled soon." << endl;
     204                if(!isValidMove(this->getPosition(), true)) //catch illegal rotations
     205                    return;
    214206            this->lockRotation_ = true; // multiple calls of this function have to be filtered out.
    215207            this->rotationTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&TetrisBrick::unlockRotation, this)));
    216208            Quaternion q(Degree(90), Vector3::UNIT_Z);
    217209            this->setOrientation(this->getOrientation()*q); //rotation: roll 90°
    218 
     210            this->rotationCount_ = (this->rotationCount_ + 1) % 4;
    219211        }
    220212    }
Note: See TracChangeset for help on using the changeset viewer.