y_ref = (!bounce_y & (ball.y_pos + BALL_SIZE/2 >= GRID_Y + i * BLOCK_HEIGHT) & ball.y_pos <= (GRID_Y + i * BLOCK_HEIGHT));
							y_ref |= (!bounce_y & (ball.y_pos <= GRID_Y + (i+1) * BLOCK_HEIGHT) & ball.y_pos+BALL_SIZE/2 >= (GRID_Y + (i+1) * BLOCK_HEIGHT));
							x_ref = (!bounce_x & (ball.x_pos + BALL_SIZE/2 >= j * BLOCK_LEN) & (ball.x_pos <= j * BLOCK_LEN));
							x_ref |= (!bounce_x & (ball.x_pos + BALL_SIZE/2 >= (j+1) * BLOCK_LEN) & (ball.x_pos <= (j+1) * BLOCK_LEN));
							if( x_ref xor y_ref )  //Easy case, only 1 hit
							{
								if(y_ref)
								{
									bounce_y = true;
									ball.y_vel = -ball.y_vel;
								}
								else
								{
									bounce_x = true;
									ball.x_vel = -ball.x_vel;
								}
							}// end if
							int y = GRID_Y + (i+1) * BLOCK_HEIGHT - ball.y_pos;
							int x = ball.x_pos + BALL_SIZE - (j * BLOCK_LEN);
							if(y > 0) //hit from bottom
							{
								cout << "if" << endl;
								if( x < 0 )
									x = (j+1) * BLOCK_LEN - ball.x_pos;
								if( x >= y )
								{
									cout << "X" << endl;
									bounce_x = true;
									ball.x_vel = -ball.x_vel;
								}
								else if( y > x )
								{
									cout << "Y" << endl;
									bounce_y = true;
									ball.y_vel = -ball.y_vel;
								}
								else
								{
									cout << "Fuckage" << endl;
									bounce_y = true;
									bounce_x = true;
									ball.y_vel = -ball.y_vel;
									ball.x_vel = -ball.x_vel;
								}
							}
							else //hit from top
							{
								cout << "else" << endl;
								y = ball.y_pos + BALL_SIZE - (GRID_Y + i * BLOCK_HEIGHT);
								if( x < 0 )
									x = (j+1) * BLOCK_LEN - ball.x_pos;
								if( x > y )
								{
									bounce_x = true;
									ball.x_vel = -ball.x_vel;
								}
								else if( y > x )
								{
									bounce_y = true;
									ball.y_vel = -ball.y_vel;
								}
								else
								{
									bounce_y = true;
									bounce_x = true;
									ball.y_vel = -ball.y_vel;
									ball.x_vel = -ball.x_vel;
								}
							}