private List<Ball> GetHitsWithBalls(Laser laser) { List<Ball> hits = new List<Ball>(); foreach (var ball in balls) { if(CheckCollision(ball, laser)) { hits.Add(ball); } } return hits; }
private bool CheckCollision(Ball ball, Laser laser) { bool horizontal = IsBetween((int)ball.Position.X, laser.CollisionRect.Left - (int)ball.Radius, laser.CollisionRect.Right + (int)ball.Radius); bool vertical = IsBetween((int)ball.Position.Y, laser.CollisionRect.Top - (int)ball.Radius, laser.CollisionRect.Bottom + (int)ball.Radius); return horizontal && vertical; }