Exemple #1
0
        private void CheckIfPointScored()
        {
            float ballLeftEdge  = _ball._ballPosition.X;
            float ballRightEdge = _ball._ballPosition.X + _ball._ballSprite.Width;

            if (ballRightEdge < 0)
            {
                _rightScore++;
                PlaySoundEffect(_pointScored, _soundEffectsAudible);
                _roundStartTime = 0;
                _ball.Enabled   = false;
                _male1Available = true;
                _male2Available = true;
                _male3Available = true;

                if (_rightScore != _winningScore)
                {
                    _ball.Restart();

                    // This makes the paddle smaller each time a player reaches a multiple of 2.
                    if (_rightScore % 2 == 0)
                    {
                        PlaySoundEffect(_powerUpSound, _soundEffectsAudible);
                        _rightPaddle.ChangePaddleSize();
                        _rightPaddleEffect.Trigger(new Vector2(_rightPaddle._paddlePosition.X + _rightPaddle._paddleSprite.Width / 2, _rightPaddle._paddlePosition.Y + _rightPaddle._paddleSprite.Height / 2));
                    }
                }
                else
                {
                    _currentScreen = Screen.endMenu;
                }
            }
            else if (ballLeftEdge > GraphicsDevice.Viewport.Width)
            {
                _leftScore++;
                PlaySoundEffect(_pointScored, _soundEffectsAudible);
                _roundStartTime = 0;
                _ball.Enabled   = false;
                _male1Available = true;
                _male2Available = true;
                _male3Available = true;

                if (_leftScore != 10)
                {
                    _ball.Restart();

                    // This makes the paddle smaller each time a player reaches a multiple of 2.
                    if (_leftScore % 2 == 0)
                    {
                        PlaySoundEffect(_powerUpSound, _soundEffectsAudible);
                        _leftPaddle.ChangePaddleSize();
                        _leftPaddleEffect.Trigger(new Vector2(_leftPaddle._paddlePosition.X + _leftPaddle._paddleSprite.Width / 2, _leftPaddle._paddlePosition.Y + _leftPaddle._paddleSprite.Height / 2));
                    }
                }
                else
                {
                    _currentScreen = Screen.endMenu;
                }
            }
        }