title: Trying to make a ball bounce back off of an arrays component? (cant think of a better word) C#
body: <p>I have a ball bouncing off of paddles and walls as desired, i have then added a singular brick via the draw.Rectangle tool and had the ball bounce off of this and then change its colour but could not make it invisible to stop any further collisions.
  I am using an array for my bricks as i can have many and can turn them true or false after being hit</p>
  
  <p>My issue is that i am trying to get the ball to collide with said array bricks, but cannot for the life of me figure it out even with as much googling as possible. here is the snippet of my code i think 'should' work for the collision</p>
  
  <pre><code> for (int i = 0; 1 &lt; brickLive.Length; i++)
                  if ((y == brickLocation[i, 0]) &amp;&amp; (x &gt;= brickLocation[0, i]) &amp;&amp; (x &lt;= (brickLocation[0, i] + 60)))
                      yChange = -yChange;
  </code></pre>
  
  <p>to my understanding this code is saying for the value of i check if ball coords are in the parameters of a bricks location. if it is then change direction.
  with the current code it runs fine until i start the game (i click the insert button and that enables the bounce button to work)</p>
  
  <p>here is my full code</p>
  
  <pre><code>    using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace Breakout
  {
      public partial class Form1 : Form
      {
  
          private int x, y, x2, y2;
          private int xChange, yChange;
  
          int bat, batX, batXX, mouseX;
  
          private Graphics paper;
          private Pen pen, pen2, pen3;
  
          private Pen brkpen;
  
          private Random ranNum;
  
          int brkLength = 60;
          int brkHeight = 20;
      int[,] brickLocation = { { 0, 100 }, { 61, 100 }, { 122, 100 } };
      bool[] brickLive = { true, true, true };
  
  
      public Form1()
      {
          InitializeComponent();
  
          paper = picDisplayBat.CreateGraphics();
          pen = new Pen(Color.Red);
          pen.Width = 10;
          ranNum = new Random();
  
          paper = picDisplayBat.CreateGraphics();
          pen = new Pen(Color.Blue);
          pen.Width = 3;
  
          paper = picDisplayBat.CreateGraphics();
          pen2 = new Pen(Color.Red);
          pen.Width = 3;
  
          picDisplayBat.MouseMove += new
          System.Windows.Forms.MouseEventHandler(picDraw_MouseMove);
  
          paper = picDisplayBat.CreateGraphics();
          brkpen = new Pen(Color.Black);
          brkpen.Width = 3;
  
  
          //paper = picDisplayBat.CreateGraphics();
          //pen3 = new Pen(Color.Green);
          //pen3.Width = 5;
   }
  
  
      private void picDraw_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)                         //DRAWING THE BAT TO MOVE WITH MOUSE
      {
          //paper.Clear(Color.White);
          mouseX = e.X;
      }
  
  
      private void btnInsert_Click_1(object sender, EventArgs e)
      {
          {
              btnBounce.Visible = true;
          }
      }
  
      private void btnBounce_Click_1(object sender, EventArgs e)
      {
          {
  
              timer1.Interval = 25;
              timer1.Enabled = true;
  
              x = ranNum.Next(1, picDisplayBat.Height);
              y = ranNum.Next(1, picDisplayBat.Width);
              xChange = ranNum.Next(1, 10); yChange = ranNum.Next(1, 10);
  
  
              for (int i = 0; i &lt; brickLive.Length; i++)
              {
                  paper.DrawRectangle(brkpen, brickLocation[i, 0], brickLocation[i, 1], brkLength, brkHeight);
  
  
              }
  
          }
      }
  
      private void timer1_Tick(object sender, EventArgs e)
      {
          {
  
              x = x + xChange;
              y = y + yChange;
              if (x &gt;= picDisplayBat.Width)
                  xChange = -xChange;
  
              if (y &gt;= picDisplayBat.Height)
                  yChange = -yChange;
  
              if (x &lt;= 0)
                  xChange = -xChange;
  
              if (y &lt;= 0)
                  yChange = -yChange;
  
              if ((y &gt; picDisplayBat.Height - 20) &amp;&amp; (x &gt;= batX + 10) &amp;&amp; (x &lt;= batX + 50))
                  yChange = -yChange;
  
              if ((y &lt; picDisplayBat.Height - 295) &amp;&amp; (x &gt;= batX + 10) &amp;&amp; (x &lt;= batX + 50))
                  yChange = -yChange;
  
              for (int i = 0; 1 &lt; brickLive.Length; i++)
                  if ((y == brickLocation[i, 0]) &amp;&amp; (x &gt;= brickLocation[0, i]) &amp;&amp; (x &lt;= (brickLocation[0, i] + 60)))
                      yChange = -yChange;
  
  
  
                  paper.Clear(Color.White);
              paper.DrawRectangle(pen, mouseX + 10, picDisplayBat.Height - 20, 50, 10);          //bat 1
              paper.DrawEllipse(pen, x, y, 10, 10);                                              //ball
              paper.DrawRectangle(pen2, mouseX + 10, picDisplayBat.Height - 295, 50, 10);        //bat2
              //paper.DrawRectangle(pen3, x2, y2, 60, 10);
              bat = mouseX;
              batX = mouseX;
              batXX = mouseX;
  
              for (int i = 0; i &lt; brickLive.Length; i++)
              {
                  paper.DrawRectangle(brkpen, brickLocation[i, 0], brickLocation[i, 1], brkLength, brkHeight);
  
  
              }
          }
      }
  
      private void btnExit_Click(object sender, EventArgs e)
      {
  
       Environment.Exit(0);
  
      }
  
      private void btnStop_Click(object sender, EventArgs e)
      {
  
  
              timer1.Enabled = false;
              paper.Clear(Color.White);
  
          }
  
  }
  </code></pre>
  
  <p>}</p>