Exemplo n.º 1
0
        /// <summary>
        /// This aglorithm determines where the computer player should move the paddle.
        /// It predicts the next position of the ball, but intentionally does not detect when the ball bounces
        /// off of the walls of the level, additionally it doesn't adequately detect large amounts of spin
        /// </summary>
        /// <param name="ball">The ball in the game</param>
        /// <param name="paddle">the paddle to be moved</param>
        /// <returns>the control value for the paddle</returns>
        public float Move(Ball ball, Paddle paddle)
        {
            float ballY = ball.Position.Y + ball.Direction.Y * ball.CurrentSpeed;

            if (ball.Position.Y + ball.Height / 2   < paddle.Position.Y + paddle.Height / 2 - ball.Height / 2)
            {
                return maxSpin;
            }
            else if (ball.Position.Y + ball.Height / 2 > paddle.Position.Y + paddle.Height / 2 + ball.Height / 2)
            {
                return - maxSpin;
            }

            return 0f;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Initialize paddles
            paddle1 = new Paddle();
            paddle2 = new Paddle();

            // Initialize ball
            ball = new Ball();

            // Initialize the computer
            computer = new Computer();

            // Initialize the powerUps
            speedPower = new SpeedPower();
            strobePower = new StrobePower();

            Rand = new Random();

            base.Initialize();
        }