Simple solution:
use Rectangle.Intersects:
Rectangle x = new Rectangle(ball.x, ball.y, ball.width, ball.height);
Rectangle y = new Rectangle(x,y, width, height);
return x.Intersects(y);
Thats really simple answer, becouse ball is more like ellipse... :)
Better solution
Finding intersection between Rectangle and Ellipse:
System.Drawing.Rectangle brick = new Rectangle();
int ballX, ballY, radiusX, radiusY;
brick.Width = // dont see it in your code
brick.Height = // dont see it in your code
brick.X = blocksPosition[BoxNum].X;
brick.Y = blocksPosition[BoxNum].Y;
ballX = ballPosition.X;
ballY = ballPosition.Y;
radiusX = ball.Width;
radiusY = ball.Height;
// find closest point:
var closestX = Math.Min(brick.Width + brick.X, Math.Max(ballX, brick.X));
var closestY = Math.Min(brick.Height + brick.Height, Math.Max(ballY, brick.Y));
// find distance:
var distanceX = ballX - closestX;
var distanceY = ballY - closestY;
// if distance is lesser then circle radius, then we have intersaction:
var dSq = ((distanceX * distanceX) + (distanceY * distanceY))
if (dSq < (radiusX*radiusX))
{
return dSq < (radiusY*radiusY);
}
return false;
The Best solution (©®™):
Use any 2d physics engine, like, lets say Farseer. Its more to learn from start, but in end, it will be much better and easier for you.
Quick and Dirty example of Ball hitting brick will looks like this:
World world = new World(new Vector2(0f, 0f)); // no gravity
Body myBall = world.CreateBody();
myBall.BodyType = BodyType.Dynamic;
CircleShape circleShape = new CircleShape(0.5f);
Fixture fixture = myBall.CreateFixture(circleShape);
Fixture brick = FixtureFactory.CreateRectangle();
// etc... Setting Position and so on.
// Its big topic to discuss here whole project.
and every frame:
world.Step(0.033333f); // 60 fps
In final project, you will have two "spaces" - one physical (where you/farseer will count collisions, forces etc) and second one, where you draw your bodies from physic world (btw - Body is only point in space, Shape is any shape / polygon and Fixture is what is holding Body and Shape together... As i say, its really big topic. Feel free to ask any other question about Farseer :) )