2

I'm currently developing a similar game to "Breakout". The problem im having is that whenever the ball goes over the edges of a brick, it neither removes the brick or change the direction of the ball.

if (ball.Left > l.Left && (ball.Left + ball.Width) < l.Left-margin + l.Width)
{
    if (ball.Top > l.Height && ball.Top < l.Top)
    {
        this.Controls.Remove(l);
        ballDX *= -1;
        ballDY *= -1;
    }

    else if (ball.Top < l.Height && ball.Top > l.Bottom)
    {
        this.Controls.Remove(l);
        ballDX *= +1;
        ballDY *= +1;
    }
}
Lews Therin
  • 3,707
  • 2
  • 27
  • 53
Chanter
  • 99
  • 1
  • 12
  • 1
    I would look at the first part of both those inner ifs - you're comparing ball's position with control's dimension (height) - probably not what you wanted in the first place. – decPL May 25 '16 at 14:52

1 Answers1

0

Looking at your code, you are testing

if (ball.Top > l.Height && ball.Top < l.Top)

But this appears to be checking whether the top of your ball is greater than the height of your brick, rather than the position of the brick. Could be a problem there?

If that is not the issue, my suggestion would be to add some debug code to output the values of the ball and brick positions and heights, so that you can get an idea of what is wrong in your calculation.

Toby
  • 1,537
  • 10
  • 19