Im trying to use arrow keys to move tetris block left & right and rotate, but its not working while the block falls down the gameGrid. Here is my code.
//Here is my Game cycle in the timer handler
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
mainGameBoard->drawGrid();
newBlock->draw();
newBlock->moveDown();
if(newBlock->canMoveDown()==false)
{
//If block hits bottom or block, add block to grid
newBlock->addMySelfToGameBoard();
//Update the grid by deleting full rows & move
//the game grid down
mainGameBoard->updateGrid();
//Create new block
//Havnt sorted yet
}
}
Here is my code for using the arrow keys to move & rotate the block, the move methods and rotate method are in the TTetrisBlock class.
private: System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
if(e->KeyData == Keys::Left)
{
newBlock->moveLeft();
}
if(e->KeyData == Keys::Right)
{
newBlock->moveRight();
}
if(e->KeyData == Keys::Up)
{
newBlock->rotate();
}
}
//Now when the block is moving down the game grid on timer tick the arrow keys when pressed are not moving the object. but if i put newBlock->moveLeft() in the timer the block will start moving left. So my moveLeft() method is working. Can some on help please - im a student studying C++.Here is my moveLeft() method:
void TTetrisBlock::moveLeft()
{
array<Point>^ temporaryCopy = gcnew array<Point>(4);
for(int i=0;i<mySquares->Length;i++)
{
//Set future move
temporaryCopy[i].X = mySquares[i].X-1;
temporaryCopy[i].Y = mySquares[i].Y;
}
if(checkBounds(temporaryCopy) == true)
{
for(int i=0;i<temporaryCopy->Length;i++)
{
mySquares[i].X = temporaryCopy[i].X;
mySquares[i].Y = temporaryCopy[i].Y;
}
}
}