コード例 #1
0
ファイル: Form1.cs プロジェクト: IshanP1/PoolTable
        private void CheckCollisions(MovingBall ball)
        {
            // Make list of balls to check collisions against
            List <MovingBall> collisionList = new List <MovingBall>();

            foreach (ColourPoolBall b in balls)
            {
                collisionList.Add(b);
            }

            // Remove ball as we don't need to see if ball collides with itself
            collisionList.Remove(ball);

            // Check for collision with every other ball
            foreach (ColourPoolBall b2 in collisionList)
            {
                if (ball.CollidesWith(b2))
                {
                    ball.Touching(b2);
                    //bounce both balls - this is not very accurate :-(
                    ball.XSpeed *= -1;
                    ball.YSpeed *= -1;

                    b2.XSpeed *= -1;
                    b2.YSpeed *= -1;
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: IshanP1/PoolTable
 private bool CheckOverlaps(MovingBall ball)
 {
     //check if overlaps any existing balls
     foreach (ColourPoolBall b in balls)
     {
         if (ball.CollidesWith(b))
         {
             ball.Touching(b);
             return(true); //found an overlap
         }
     }
     return(false); //got to end of loop, so no overlaps
 }