Exemplo n.º 1
0
 /// <summary>
 /// Handles colitions with the ball, causes the ball to start strobing
 /// </summary>
 /// <param name="ball">the game ball</param>
 public void Collide(Ball ball)
 {
     if (Active)
     {
         ball.StrobeStart();
         Active = false;
         Timer += TimerDown;
         StrobeSound.Play();
     }
 }
Exemplo n.º 2
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.º 3
0
 /// <summary>
 /// Handles the collision with the ball.  it chooses a random angle in the same direction the ball was previously going
 /// and increase th eballs speed
 /// </summary>
 /// <param name="ball"></param>
 /// <param name="rand"></param>
 public void Collide(Ball ball, Random rand)
 {
     if (Active)
     {
         float direction = rand.Next(2) * 2 - 1; ;
         if (ball.Direction.X > 0)
         {
             direction = 1.0f;
         }
         else
         {
             direction = -1.0f;
         }
         Vector2 ballDirection = new Vector2(direction, (float)(rand.NextDouble() * 1.5 - 1));
         ball.Boost(ballDirection, boostSpeed);
         Active = false;
         Timer += TimerDown;
         SpeedSound.Play();
     }
 }
Exemplo n.º 4
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();
        }