void Start()
 {
     if (instance == null)
     {
         instance = this;
     }
     rigidBody = GetComponent <Rigidbody>();
 }
Beispiel #2
0
 public void GenerationBounces()
 {
     int MaxN, m = 0;
     MaxN = Convert.ToInt32(400.0 / r) / 2;
     label5.Text = Convert.ToString(MaxN * MaxN);
     SpawnCoordinateX = new int[MaxN * MaxN];
     SpawnCoordinateY = new int[MaxN * MaxN];
     double vx, vy, x, y;
     int[] L = new int[MaxN * MaxN];
     Random rnd = new Random();
     for (int i = 0; i < MaxN; i++)
     {
         for (int j = 0; j < MaxN; j++)
         {
             SpawnCoordinateX[m] = Convert.ToInt32(i * r * 2);
             SpawnCoordinateY[m] = Convert.ToInt32(j * r * 2);
             m++;
         }
     }
     for (int i = 0; i < MaxN * MaxN; i++)
     {
         L[i] = i;
     }
     for (int i = MaxN * MaxN - 1; i >= 0; i--)
     {
         int j = rnd.Next(i);
         var temp = L[i];
         L[i] = L[j];
         L[j] = temp;
     }
     for (int i = 0; i < n; i++)
     {
         x = SpawnCoordinateX[L[i]];
         y = SpawnCoordinateY[L[i]];
         vx = Vmax - rnd.NextDouble() * (Vmax - Vmin);
         vy = Vmax - rnd.NextDouble() * (Vmax - Vmin);
         bounces[i] = new Bouncing(vx, vy, x, y);
     }
     pictureBox1.Image = bitmap;
 }
Beispiel #3
0
            public void Hit(Bouncing ball2)
            {
                double R = r / 2;
                double lx = (2 * R * (X - ball2.X) / Math.Sqrt((X - ball2.X) * (X - ball2.X) + (Y - ball2.Y) * (Y - ball2.Y)));
                double ly = (2 * R * (Y - ball2.Y) / Math.Sqrt((X - ball2.X) * (X - ball2.X) + (Y - ball2.Y) * (Y - ball2.Y)));
                X = ball2.X + lx;
                Y = ball2.Y + ly;

                double v1x, v1y, v2x, v2y;
                v1x = Vx - ball2.Vx;
                v1y = Vy - ball2.Vy;
                v2x = X - ball2.X;
                v2y = Y - ball2.Y;
                double koef = (v1x * v2x + v1y * v2y);
                koef /= 4 * R * R;
                Vx = Vx - (X - ball2.X) * koef;
                Vy = Vy - (Y - ball2.Y) * koef;
                ball2.Vx = ball2.Vx + (X - ball2.X) * koef;
                ball2.Vy = ball2.Vy + (Y - ball2.Y) * koef;
            }