Esempio n. 1
0
 /// <summary>
 /// Checks if the ball hits one of the walls
 /// </summary>
 /// <param name="ball">Ball</param>
 private void WallCollision(Ball ball)
 {
     if (ball.CollisionBox.Y <= 0 ||
         ball.CollisionBox.Y >= graphics.PreferredBackBufferHeight)
     {
         float y = ball.CollisionBox.Y > 0 ? graphics.PreferredBackBufferHeight - ball.CollisionBox.Height : 0;
         ball.ChangeMoveVector(new Vector2(ball.MoveVector.X, ball.MoveVector.Y * -1));
         ball.Position = new Vector2(ball.Position.X, y);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Checks Collision between ball and player slider
        /// </summary>
        /// <param name="ball">Ball ball</param>
        public void Collision(Ball ball)
        {
            if (ball.CollisionBox.Intersects(slider.CollisionBox))
            {
                float width = ball.MoveVector.X > 0 ? -ball.CollisionBox.Width : ball.CollisionBox.Width; //prevents the ball from stucking in a slider

                ball.Position = new Vector2(slider.CollisionBox.X + width, ball.Position.Y);
                Vector2 sideVec = slider.GetSideVector(ball.CollisionBox);
                ball.ChangeMoveVector((ball.MoveVector * -1) + (slider.MoveVector / 2) + sideVec);
            }

            if (ball.CollisionBox.Intersects(endZone)) //ball out of field
            {
                OnLeft?.Invoke(this, EventArgs.Empty);
            }
        }