/// <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) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } // Updates the sprites in the sprite list paddleLeft.Update(gameTime); if (isPvp) { paddleRightPlayer.Update(gameTime); } else { paddleRight.Update(gameTime); } pong.Update(gameTime); pKeyboardState = keyboardState; keyboardState = Keyboard.GetState(); elapsedTime += gameTime.ElapsedGameTime.Milliseconds; if (menu == 1) { if (keyboardState.IsKeyDown(Keys.Escape)) { if (paused && elapsedTime >= testTime) { paused = false; elapsedTime = 0; } else if (!paused && elapsedTime >= testTime) { paused = true; elapsedTime = 0; } } } // Updates the score score.Text = scoreLeft.ToString() + " " + scoreRight.ToString(); score.Update(gameTime); bloom.Update(gameTime); dummyPaddleLeft.Update(gameTime); dummyPaddleRight.Update(gameTime); dummyPong.Update(gameTime); dummyPongposition = dummyPong.position; debugLabel.Update(gameTime, paddleRightPlayer.ai.ToString() + " " + paddleRightPlayer.dummy.ToString() + " " + paddleRightPlayer.move.ToString() + " " + isPvp.ToString()); // Sees if the game is ended if (gameOver == true) { ableStart = false; if (playerWon == true) { endText.Text = "You Won!!!"; endText.Update(gameTime); } else { if (isPvp) { endText.Text = "Player 2 Won!!!"; endText.Update(gameTime); } else { endText.Text = "CPU Won!!!"; endText.Update(gameTime); } } } resetButton.Update(gameTime); playButton.Update(gameTime); optionsButton.Update(gameTime); exitButton.Update(gameTime); pauseButton.Update(gameTime); mainMenuButton.Update(gameTime); pvpPlayButton.Update(gameTime); mainMenuButton2.Update(gameTime); bgColorRedUp.Update(gameTime); bgColorRedDown.Update(gameTime); bgColorGreenUp.Update(gameTime); bgColorGreenDown.Update(gameTime); bgColorBlueUp.Update(gameTime); bgColorBlueDown.Update(gameTime); pLColorRedUp.Update(gameTime); pLColorRedDown.Update(gameTime); pLColorGreenUp.Update(gameTime); pLColorGreenDown.Update(gameTime); pLColorBlueUp.Update(gameTime); pLColorBlueDown.Update(gameTime); pRColorRedUp.Update(gameTime); pRColorRedDown.Update(gameTime); pRColorGreenUp.Update(gameTime); pRColorGreenDown.Update(gameTime); pRColorBlueUp.Update(gameTime); pRColorBlueDown.Update(gameTime); pColorRedUp.Update(gameTime); pColorRedDown.Update(gameTime); pColorGreenUp.Update(gameTime); pColorGreenDown.Update(gameTime); pColorBlueUp.Update(gameTime); pColorBlueDown.Update(gameTime); applyButton.Update(gameTime); cancelButton.Update(gameTime); if (resetButton.Clicked() && menu == 1 && !paused && gameOver) { Reset(); } else if (mainMenuButton2.Clicked() && menu == 1 && !paused && gameOver) { menu = 0; } if (pvpPlayButton.Clicked() && menu == 0) { menu = 1; isPvp = true; Reset(); } else if (playButton.Clicked() && menu == 0) { menu = 1; isPvp = false; Reset(); } else if (optionsButton.Clicked() && menu == 0) { menu = 2; } else if (exitButton.Clicked() && menu == 0) { this.Exit(); } if (pauseButton.Clicked() && menu == 1 && paused) { paused = false; } else if (mainMenuButton.Clicked() && menu == 1 && paused) { menu = 0; } if (bgColorRedUp.Clicked() && menu == 2) { bgColorR += 0.1f; } else if (bgColorRedDown.Clicked() && menu == 2) { bgColorR -= 0.1f; } else if (bgColorGreenUp.Clicked() && menu == 2) { bgColorG += 0.1f; } else if (bgColorGreenDown.Clicked() && menu == 2) { bgColorG -= 0.1f; } else if (bgColorBlueUp.Clicked() && menu == 2) { bgColorB += 0.1f; } else if (bgColorBlueDown.Clicked() && menu == 2) { bgColorB -= 0.1f; } if (pLColorRedUp.Clicked() && menu == 2) { pLColorR += 0.1f; } else if (pLColorRedDown.Clicked() && menu == 2) { pLColorR -= 0.1f; } else if (pLColorGreenUp.Clicked() && menu == 2) { pLColorG += 0.1f; } else if (pLColorGreenDown.Clicked() && menu == 2) { pLColorG -= 0.1f; } else if (pLColorBlueUp.Clicked() && menu == 2) { pLColorB += 0.1f; } else if (pLColorBlueDown.Clicked() && menu == 2) { pLColorB -= 0.1f; } if (pRColorRedUp.Clicked() && menu == 2) { pRColorR += 0.1f; } else if (pRColorRedDown.Clicked() && menu == 2) { pRColorR -= 0.1f; } else if (pRColorGreenUp.Clicked() && menu == 2) { pRColorG += 0.1f; } else if (pRColorGreenDown.Clicked() && menu == 2) { pRColorG -= 0.1f; } else if (pRColorBlueUp.Clicked() && menu == 2) { pRColorB += 0.1f; } else if (pRColorBlueDown.Clicked() && menu == 2) { pRColorB -= 0.1f; } if (pColorRedUp.Clicked() && menu == 2) { pColorR += 0.1f; } else if (pColorRedDown.Clicked() && menu == 2) { pColorR -= 0.1f; } else if (pColorGreenUp.Clicked() && menu == 2) { pColorG += 0.1f; } else if (pColorGreenDown.Clicked() && menu == 2) { pColorG -= 0.1f; } else if (pColorBlueUp.Clicked() && menu == 2) { pColorB += 0.1f; } else if (pColorBlueDown.Clicked() && menu == 2) { pColorB -= 0.1f; } if (applyButton.Clicked() && menu == 2) { backgroundColor = new Color(bgColorR, bgColorG, bgColorB); paddleLeftColor = new Color(pLColorR, pLColorG, pLColorB); paddleRightColor = new Color(pRColorR, pRColorG, pRColorB); pongColor = new Color(pColorR, pColorG, pColorB); pong.color = pongColor; paddleLeft.color = paddleLeftColor; paddleRight.color = paddleRightColor; menu = 0; } else if (cancelButton.Clicked() && menu == 2) { backgroundColor = new Color(0, 1f, 1f); paddleLeftColor = new Color(0, 1f, 0); paddleRightColor = new Color(1f, 0, 0); pongColor = new Color(1f, 0.80f, 0); pong.color = pongColor; paddleLeft.color = paddleLeftColor; paddleRight.color = paddleRightColor; menu = 0; } base.Update(gameTime); // TODO: Add your update logic here }