Пример #1
0
        private void HandleCollision()
        {
            Rectangle current = this.Rectangle();

            Ballz[] selected = new Ballz[Ballz.All.Count];
            Ballz.All.CopyTo(selected);

            foreach (Ballz circle in selected)
            {
                if (circle.id != this.id && current.IntersectsWith(circle.Rectangle()))
                {
                    // Prevent inside looping
                    // if (!(circle.GoX != this.GoX && circle.GoY != this.GoY)) continue;;

                    // Manually handle all cases... yes I know this is probably the worst way to handle this!
                    this.GoX = -this.GoX;
                    this.GoY = -this.GoY;

                    Console.WriteLine(@"collision detected");
                    Console.WriteLine($@"Circle: {circle.Location.X}-{circle.Location.Y}");
                    Console.WriteLine($@"Circle: {circle.GoX}-{circle.GoY}");
                    Console.WriteLine($@"Current: {this.Location.X}-{this.Location.Y}");
                    Console.WriteLine($@"Current: {this.GoX}-{this.GoY}");
                    Console.WriteLine(@"------------------");

                    if (Ballz.lastId >= 300)
                    {
                        continue;
                    }
                    Ballz.collisionDetected();
                }
            }
        }
Пример #2
0
 private void drawer_Tick(object sender, EventArgs e)
 {
     Ballz[] selected = new Ballz[Ballz.All.Count];
     Ballz.All.CopyTo(selected);
     foreach (Ballz circle in selected)
     {
         circle.PerformStep();
     }
     panel.Invalidate();
 }