FruitTetris.cpp
// Rotates the current tile, if there is room.
Rotates the current tile, if there is room.
Rotates the current tile if there is room .
void rotate()
{
	for (int i = 0; i<4; i++)
		tile[i] = currentTileType[(currentRotation + 1) % 4][i];
	currentRotation = (currentRotation + 1) % 4;
	int min_x = 0;
	int max_x = 0;
	int min_y = 0;
	int max_y = 0;
	for (int i = 0; i < 4; i++)
	{
		int x, y;
		x = tilepos.x + tile[i].x;
		y = tilepos.y + tile[i].y;
		if (x < min_x)
			min_x = x;
		if (x > max_x)
			max_x = x;
		if (y < min_y)
			min_y = y;
		if (y > max_y)
			max_y = y;
	}
	tilepos.x = tilepos.x - min_x;
	tilepos.y = tilepos.y - min_y;
	if (max_y > 19)
		tilepos.y = 2 * tilepos.y - max_y;
	if (max_x > 9)
		tilepos.x = 2 * tilepos.x - max_x;
	if (collidingWithExisitingTile()) 
	{
		for (int i = 0; i<4; i++) 
			tile[i] = currentTileType[(currentRotation - 1) % 4][i];
		currentRotation = (currentRotation - 1) % 4;
	}
	updatetile();
}
void rotate ( ) { for ( int i = 0 ; i < 4 ; i ++ ) tile [ i ] = currentTileType [ ( currentRotation + 1 ) % 4 ] [ i ] ; currentRotation = ( currentRotation + 1 ) % 4 ; int min_x = 0 ; int max_x = 0 ; int min_y = 0 ; int max_y = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { int x , y ; x = tilepos . x + tile [ i ] . x ; y = tilepos . y + tile [ i ] . y ; if ( x < min_x ) min_x = x ; if ( x > max_x ) max_x = x ; if ( y < min_y ) min_y = y ; if ( y > max_y ) max_y = y ; } tilepos . x = tilepos . x - min_x ; tilepos . y = tilepos . y - min_y ; if ( max_y > 19 ) tilepos . y = 2 * tilepos . y - max_y ; if ( max_x > 9 ) tilepos . x = 2 * tilepos . x - max_x ; if ( collidingWithExisitingTile ( ) ) { for ( int i = 0 ; i < 4 ; i ++ ) tile [ i ] = currentTileType [ ( currentRotation - 1 ) % 4 ] [ i ] ; currentRotation = ( currentRotation - 1 ) % 4 ; } updatetile ( ) ; }
Rotates the current tile, if there is room.
Rotates the current tile if there is room .