- #1
finchie_88
Hello everyone. I have got quite far with a game of tetris that I am making (I'm writting in C++, and on windows, using Dev-C++ IDE and windows API). I am just touching it up, and then it will be done. One of the problems which I am having, is that when the blocks hit the bottom of the window (or they hit the blocks that should have hit the bottom of the window), the blocks disappear, so after a while, you get areas where the blocks just disappear as they come down. I think that it is something to do with my collision function, but can't spot the error.
I will explain the variables below.
MAPHEIGHT and MAPWIDTH are pretty obvious, they are constant integers. sPiece is a structure containing (integers) x & y (these refer to the current position). nx, and ny are the distances in the x and y-axis respectively that the blocks have moved. Things like TILEBLACK and TILENODRAW are defined in a header file, and refer to a bitmap that I am using. There are a few other improvements I would like to make, but I think I can sort those out on my own, if I can't - I'll be back!
I will explain the variables below.
Code:
int newx=sPiece.x+nx;
int newy=sPiece.y+ny;
int i,j,x,y;
for(i=0; i< 4; i++)
for(j=0; j< 4; j++)
if(sPiece.size[ i ][j] != TILENODRAW)
if((newx + i) < 0 || (newx + i) > (MAPWIDTH - 1) ||
(newy + j) < 0 || (newy + j) > (MAPHEIGHT - 1))
return 1;
for(x=0; x< MAPWIDTH; x++)
for(y=0; y< MAPHEIGHT; y++)
if(x >= newx && x < newx + 4)
if(y >= newy && y < newy +4)
if(Map[x][y] != TILEBLACK)
if(sPiece.size[x - newx][y - newy] != TILENODRAW)
return 1;
return 0;