Hello. I am trying to create a "Tetris" game.
I am drawing a rectangle which is moving on the console. The rectangle is refreshed with "InvalidateRect" At the present moment I am testing it only with key RIGHT. So when I am pressing the key RIGHT it is moving to the right
When the rectangle is reaching a certain point, then we have another rectangle falling. As soon as I start using the "LEFT" key it is refreshing the second rectangle, BUT it is erasing the previous rectangle. How can I deal with it- I mean, how can I refresh the second rectangle, but at the same time leave first rerectangle on the field without erasing?
Great thanx in advance!
Here I am showing a piece of code which is related to the game function
Code:
void Game()
{
int i;
int xcoord;
int xcoord2 = 0;
clrscr();
system("color 0a");
for (; ;) {
const int width = 100;
xcoord = 50;
HWND hwnd = GetConsoleWindow();
HDC hdc = GetDC(hwnd);
RECT rect;
GetClientRect(hwnd, &rect);
for ( i = 10; i<80; i++)
{
Rectangle(hdc, xcoord, i, xcoord + 40, i + width);
int cd;
if (_kbhit()) {
char keyp;
keyp = _getch();
switch (keyp)
{
case UP: printf("ok");
break;
case RIGHT:
xcoord = xcoord + 20;
InvalidateRect(hwnd, NULL, FALSE);
break;
}
_getch());
}
}
}
}
}