protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } switch (gameStatus) { case GameStatus.BootMenu: //Quickly setting Mouse button visibility after startup/restart while (this.IsMouseVisible == false) { this.IsMouseVisible = true; } //Button to start the game (Copy Players list to ActivePlayers, changing Game Status from BootMenu to PlayerSelect) #region StartBtn if (Mouse.GetState().LeftButton == ButtonState.Pressed & Mouse.GetState().X >= (graphics.GraphicsDevice.Viewport.Width - StartBtn.Width) / 2 & Mouse.GetState().X <= (graphics.GraphicsDevice.Viewport.Width + StartBtn.Width) / 2) { if (Mouse.GetState().Y >= (graphics.GraphicsDevice.Viewport.Height - StartBtn.Height) / 5 * 3 & Mouse.GetState().Y <= (graphics.GraphicsDevice.Viewport.Height + StartBtn.Height) / 5 * 3) { ActivePlayers.AddRange(Players); gameStatus = GameStatus.PlayerSelect; } if (Mouse.GetState().Y >= (graphics.GraphicsDevice.Viewport.Height - StartBtn.Height) / 5 * 4 & Mouse.GetState().Y <= (graphics.GraphicsDevice.Viewport.Height + StartBtn.Height) / 5 * 4) { //Controls } } #endregion break; case GameStatus.PlayerSelect: // Selecting the desired amount of players (Remove unnecessary players with RemoveRange() and setting Game Status to GamePlay) #region SelectBtns if (Mouse.GetState().LeftButton == ButtonState.Pressed & Mouse.GetState().X >= (graphics.GraphicsDevice.Viewport.Width - StartBtn.Width) / 2 & Mouse.GetState().X <= (graphics.GraphicsDevice.Viewport.Width + StartBtn.Width) / 2) { if (Mouse.GetState().Y >= (graphics.GraphicsDevice.Viewport.Height - StartBtn.Height) / 4 & Mouse.GetState().Y <= (graphics.GraphicsDevice.Viewport.Height + StartBtn.Height) / 4) { ActivePlayers.RemoveRange(2, 2); gameStatus = GameStatus.GamePlay; } else if (Mouse.GetState().Y >= (graphics.GraphicsDevice.Viewport.Height - StartBtn.Height) / 2 & Mouse.GetState().Y <= (graphics.GraphicsDevice.Viewport.Height + StartBtn.Height) / 2) { ActivePlayers.RemoveRange(3, 1); gameStatus = GameStatus.GamePlay; } else if (Mouse.GetState().Y >= (graphics.GraphicsDevice.Viewport.Height - StartBtn.Height) / 4 * 3 & Mouse.GetState().Y <= (graphics.GraphicsDevice.Viewport.Height + StartBtn.Height) / 4 * 3) { gameStatus = GameStatus.GamePlay; } } #endregion break; case GameStatus.GamePlay: #region GamePlay if (wantedPlayer != null) { // If A wanted player is set in the callPlayer() method, the LoseLives() function is started for this player. LoseLives(wantedPlayer); wantedPlayer = null; } this.IsMouseVisible = false; for (int i = 0; i < Balls.Count; i++) { for (int j = 0; j < ActivePlayers.Count; j++) { Balls[i].CheckCollisionPlayer(ActivePlayers[j]); } } foreach (Player p in Players) { p.Move(gameTime); } foreach (Ball b in Balls) { b.Move(gameTime); } PowerUps.Update(gameTime); PowerUps.CheckBallCollision(Balls); #endregion break; case GameStatus.GameOver: //Reset button for resetting the game to the Boot Menu and resetting all player lives to 3 #region GameOver while (this.IsMouseVisible == false) { this.IsMouseVisible = true; } if (Mouse.GetState().LeftButton == ButtonState.Pressed & Mouse.GetState().X >= (graphics.GraphicsDevice.Viewport.Width - StartBtn.Width) / 2 & Mouse.GetState().X <= (graphics.GraphicsDevice.Viewport.Width + StartBtn.Width) / 2 & Mouse.GetState().Y >= (graphics.GraphicsDevice.Viewport.Height - StartBtn.Height) / 2 & Mouse.GetState().Y <= (graphics.GraphicsDevice.Viewport.Height + StartBtn.Height) / 2) { ActivePlayers.AddRange(Players); for (int i = ActivePlayers.Count; i-- > 0;) { ActivePlayers[i].lives = 3; } gameStatus = GameStatus.BootMenu; } break; #endregion } base.Update(gameTime); }