I am currently at the last stage of the Tetris Clone using SDL library, the only thing left is rotation. For each piece I have a separate class, and in order to move the pieces down I use a method:
void PieceZ::movePieceDown()
{
drawBlock(x1,y1++);
drawBlock(x2,y3++);
drawBlock(x3,y3++);
drawBlock(x4,y4++);
}
This method is called like that: current->movePieceDown();
where current
represents a pointer to the current piece. Now to rotate the piece I have another method:
void PieceZ::rotatePiece()
{
drawBlock(newX1,newY2++);
drawBlock(x2,y2);
drawBlock(newX3,newY3++);
drawBlock(newX4,newY4++);
}
New X and Y coordinates are calculated elsewhere, with x2 and y2 taken as the origin.
My question is how do I swap current->movePieceDown()
with current->rotatePiece()
while the piece is moving? Taking into acount that I am handling keyboard events in another method.