Exemplo n.º 1
0
        /// <summary>
        /// Processes possible the-ball-to-a-brick collisions, and does appropriate velocity changes if they occur.
        /// </summary>
        private void ProcessPossibleBrickCollisions()
        {
            for (int i = 0; i < bricks.Length; i++)
            {
                if (bricks[i] != null)
                {
                    Position currentCollisionPosition = CollisionDetector.BrickToCircleIntersection(ball, bricks[i]);

                    if (currentCollisionPosition != Position.None)
                    {
                        PositionRelationBallVelocityManager
                        .ChangeVelocityAccordingToCollisionPosition(ball, currentCollisionPosition);

                        bricks[i].Dispose();
                        bricks[i] = null;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes possible the-ball-to-the-plate collision, and if it occurs, changes velocity of the ball.
        /// </summary>
        private void ProcessPossiblePlateCollision()
        {
            // Checks whether the ball hits the plate or not. 1)
            // If not, then if its Y coord is <= plate's one, exits the game. 2)
            // If yes, it reverses Vy Velocity and Gets the X speed of the ball depending on what part 3)
            //                                                                  of the plate has been hit

            if (ball.Y + (ball.Radius * 2) >= plate.Y)
            {
                if (CollisionDetector.BrickToCircleIntersection(ball, plate) != Position.None)
                {
                    double scale = ball.X + ball.Radius - (plate.X + plate.Width / 2);
                    ball.Vx  = (scale / Math.Sqrt(Math.Abs(scale))) / 4.5;
                    ball.Vy *= -1;
                }
                else if (ball.Y >= graphics.PreferredBackBufferHeight)
                {
                    EndGame();
                }
            }
        }