/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.Left)) { paddle.MoveLeft(); } if (Keyboard.GetState().IsKeyDown(Keys.Right)) { paddle.MoveRight(); } if (ball.BallRect.Top < 0 || ball.BallRect.Intersects(paddle.PaddleRect)) { ball.CollisionY(); } if (ball.BallRect.Left < 0 || ball.BallRect.Right > Window.ClientBounds.Width) { ball.CollisionX(); } for (int i = 0; i < blocks.Count; i++) { if (ball.BallRect.Intersects(blocks[i].BlockRect) && blocks[i].Visibility) { blocks[i].Collision(); ball.CollisionY(); } } ball.Move(); // TODO: Add your update logic here base.Update(gameTime); }