Reputation: 23
I am trying to make a copy for the breakout in C#. I am almost done with my work but I discovered something that is working wrong.
What the game is based on: the ball needs to hit the brick twice to destroy it.
And there is the problem: sometimes my ball hits the brick in the corner and destroys it instantly (the brick is untouched). Any suggestions for solving this?
I will attach a video and the code where the ball and the brick collide.
Ball, brick = pictureBox
My problem illustrated: https://youtu.be/73iaDUxo4AE
if (pt.Y < 0 || ball1.Bounds.IntersectsWith(Player.Bounds))
bally = -bally;
foreach(Control x in this.Controls)
{
if (x is PictureBox && x.Tag == "block")
{
if (ball1.Bounds.IntersectsWith(x.Bounds))
{
x.Tag = "Hit";
Image myimage = new Bitmap("blue_block.png");
x.BackgroundImage = myimage;
x.BackgroundImageLayout = ImageLayout.Stretch;
bally = -bally;
}
}
else
{
if (x is PictureBox && x.Tag == "Hit")
if (ball1.Bounds.IntersectsWith(x.Bounds))
{
score = score + 1;
bally = -bally;
this.Controls.Remove(x);
if(score<=5)
speed = speed + 1;
}
}
}
Many thanks in advance and I hope I was specific enough. Have a nice day !
Upvotes: 0
Views: 206