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; } } }
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 }