Exemple #1
0
        public void Update(float delta)
        {
            if (Keyboard.IsKeyDown(KeyCode.Space))
            {
                _ball.CanMove = true;
            }

            _leftPaddle.Update(delta);
            _rightPaddle.Update(delta);
            _ball.Update(delta);

            if (_ball.CollidesWithPaddle(_leftPaddle))
            {
                _ball.BounceFromPaddle(_leftPaddle);
                Assets.PaddleHit.Play();
            }
            else if (_ball.CollidesWithPaddle(_rightPaddle))
            {
                _ball.BounceFromPaddle(_rightPaddle);
                Assets.PaddleHit.Play();
            }
            else if (_ball.CollidesWithBoardSide())
            {
                _ball.BounceFromSide();
                Assets.WallHit.Play();
            }

            if (_ball.CollidesWithEndOfPlayfield(out var left))
            {
                if (left)
                {
                    RightScore++;
                }
                else
                {
                    LeftScore++;
                }

                _ball.Center();
                Assets.OutsidePlayfield.Play();

                _ball.CanMove = false;
            }
        }