示例#1
0
        private void CheckCollision(Paddle paddle)
        {
            if (paddle._boundingBox.Intersects(_ball._boundingBox))
            {
                // This makes the tops and bottoms of the paddles do interesting things.
                if (_ball._ballDirection.Y < 0)
                {
                    float paddleBottom = paddle._paddlePosition.Y + paddle._paddleSprite.Height;
                    if (_ball._ballPosition.Y - paddleBottom > -20)
                    {
                        _ball.ChangeYDirection();
                    }
                }
                else
                {
                    float paddleTop = paddle._paddlePosition.Y;
                    if (paddleTop - (_ball._ballPosition.Y + _ball._ballSprite.Height) > -20)
                    {
                        _ball.ChangeYDirection();
                    }
                }

                PlaySoundEffect(_paddleHit, _soundEffectsAudible);
                _ball.ChangeXDirection();
                _ball.SpeedUp();
                if (paddle == _leftPaddle)
                {
                    _pinkSunEffect.Trigger(new Vector2(_ball._ballPosition.X + _ball._ballSprite.Width / 2, _ball._ballPosition.Y + _ball._ballSprite.Height / 2));
                }
                else
                {
                    _blueSunEffect.Trigger(new Vector2(_ball._ballPosition.X + _ball._ballSprite.Width / 2, _ball._ballPosition.Y + _ball._ballSprite.Height / 2));
                }
            }
        }