title: Pong - Collisions with paddles not working and score
body: <p>I am trying to make a simple pong game and i am stuck on the collisions with the paddles and the adding onto the score. Here is my code for the ball class:</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace Pong
  {
  class Ball
  {
      Game1 game;
      Player player;
      Computer computer;
  
      public Texture2D Texture;
      public Vector2 Position;
  
      public Vector2 Motion;
      float Speed;
  
      Rectangle ballRectangle;
      Rectangle playerPaddle;
      Rectangle computerPaddle;
  
      Random random = new Random();
  
      public void Initialize()
      {
          game = new Game1();
          player = new Player();
          computer = new Computer();
  
          Start();
      }
  
      public void Start()
      {
          Motion = Vector2.Zero;
          Position = new Vector2(391, 215);
  
          Speed = 0.8f;
  
          Motion = new Vector2(random.Next(-1, 1), random.Next(-1, 1));
      }
  
      public void Update()
      {
          Position += Motion * Speed;
  
          CheckForCollision();
      }
  
      public void CheckForCollision()
      {
          ballRectangle = new Rectangle((int)Position.X, (int)Position.Y, 20, 20);
          playerPaddle = new Rectangle((int)player.Position.X, (int)player.Position.Y, 25, 105);
          computerPaddle = new Rectangle((int)computer.Position.X, (int)computer.Position.Y, 25, 105);
  
          if (ballRectangle.Intersects(playerPaddle))
          {
              Motion.X *= -1;
          }
          if (ballRectangle.Intersects(computerPaddle))
          {
              Motion.X *= -1;
          }
          if (Position.Y &lt; 0)
          {
              Motion.Y *= -1;
          }
          if (Position.Y &gt; 450)
          {
              Motion.Y *= -1;
          }
          if (Position.X &lt; 0)
          {
              game.computerScore += 1;
              Start();
          }
          if (Position.X &gt; 800)
          {
              game.playerScore += 1;
              Start();
          }
      }
  
      public void LoadContent(ContentManager Content)
      {
          Texture = Content.Load&lt;Texture2D&gt;("ball");
      }
  
      public void Draw(SpriteBatch spriteBatch)
      {
          spriteBatch.Draw(Texture, Position,Color.White);
      }
  }
  }
  </code></pre>
  
  <p>In the rectangle I have used the actual pixels of the image instead of player.texture.width</p>
  
  <p>and here is my game class:</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace Pong
  {
  /// &lt;summary&gt;
  /// This is the main type for your game
  /// &lt;/summary&gt;
  public class Game1 : Microsoft.Xna.Framework.Game
  {
      GraphicsDeviceManager graphics;
      SpriteBatch spriteBatch;
  
      Texture2D bgtexture;
      Vector2 BGpos = new Vector2(0, 0);
  
      Ball ball;
      Player player;
      Computer computer;
  
      SpriteFont Score;
      Vector2 scorePosition = new Vector2(375, 5);
      public int playerScore;
      public int computerScore;
      string scoreOutput;
  
      public Game1()
      {
          graphics = new GraphicsDeviceManager(this);
          Content.RootDirectory = "Content";
      }
  
      /// &lt;summary&gt;
      /// 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.
      /// &lt;/summary&gt;
      protected override void Initialize()
      {
          ball = new Ball();
          player = new Player();
          computer = new Computer();
  
          ball.Initialize();
          player.Initialze();
          computer.Initialize();
  
          this.graphics.PreferredBackBufferHeight = 450;
          this.graphics.PreferredBackBufferWidth = 800;
          this.graphics.ApplyChanges();
  
          base.Initialize();
      }
  
      /// &lt;summary&gt;
      /// LoadContent will be called once per game and is the place to load
      /// all of your content.
      /// &lt;/summary&gt;
      protected override void LoadContent()
      {
          // Create a new SpriteBatch, which can be used to draw textures.
          spriteBatch = new SpriteBatch(GraphicsDevice);
  
          bgtexture = Content.Load&lt;Texture2D&gt;("PongBG");
          Score = Content.Load&lt;SpriteFont&gt;("Score");
  
          ball.LoadContent(this.Content);
          player.LoadContent(this.Content);
          computer.LoadContent(this.Content);
      }
  
      /// &lt;summary&gt;
      /// UnloadContent will be called once per game and is the place to unload
      /// all content.
      /// &lt;/summary&gt;
      protected override void UnloadContent()
      {
          // TODO: Unload any non ContentManager content here
      }
  
      /// &lt;summary&gt;
      /// Allows the game to run logic such as updating the world,
      /// checking for collisions, gathering input, and playing audio.
      /// &lt;/summary&gt;
      /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt;
      protected override void Update(GameTime gameTime)
      {
          // Allows the game to exit
          if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
              this.Exit();
  
          scoreOutput = playerScore + " " + computerScore;
  
          ball.Update();
          player.Update();
          computer.Update();
  
          base.Update(gameTime);
      }
  
      /// &lt;summary&gt;
      /// This is called when the game should draw itself.
      /// &lt;/summary&gt;
      /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt;
      protected override void Draw(GameTime gameTime)
      {
          GraphicsDevice.Clear(Color.Black);
  
          spriteBatch.Begin();
  
          spriteBatch.Draw(bgtexture, BGpos, Color.White);
  
          ball.Draw(this.spriteBatch);
          player.Draw(this.spriteBatch);
          computer.Draw(this.spriteBatch);
  
          spriteBatch.DrawString(Score, scoreOutput, scorePosition, Color.AntiqueWhite);
  
          spriteBatch.End();
  
          base.Draw(gameTime);
      }
  }
  }
  </code></pre>
  
  <p>The ball bounces off the edge of the screen at the top and bottom fine but it just goes straight through the paddles. Also once it has hit the the edge behind the paddle it goes to the beginning like it should but it doesn't add the points onto the score for the player and the computer.</p>