public void OnGUI() { if (dialogMsg != null) { GUI.Box(new Rect(Screen.width / 2.0f - 100.0f, Screen.height / 2.0f - 50.0f, 200.0f, 100.0f), dialogMsg); if (dismissMenu != null && GUI.Button(new Rect(Screen.width / 2.0f - 75.0f, Screen.height / 2.0f - 50.0f + 100.0f - 30.0f, 150.0f, 25.0f), "OK")) { OpenMenu(dismissMenu); dismissMenu = dialogMsg = null; } Screen.lockCursor = false; // Force cursor to show! } else if (activeMenu != null) { activeMenu.Draw(); } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { if (State == GameState.Playing || State == GameState.Paused) { if (State != GameState.Paused) { if (transitioningAreaP1) { if (warpOpacityP1 > 255) { warpOpacityP1 = 255; opacityChangeP1 = -5; UpdateCameraForWarp(gameTime, warpArgsP1); } else if (warpOpacityP1 <= 0) { transitioningAreaP1 = false; warpArgsP1 = null; Player1.StateMachine.TransitionIdle(); } } if (transitioningAreaP2 && (Mode == GameMode.MultiPlayer)) { if (warpOpacityP2 > 255) { warpOpacityP2 = 255; opacityChangeP2 = -5; UpdateCameraForWarp(gameTime, warpArgsP2); } else if (warpOpacityP2 <= 0) { transitioningAreaP2 = false; warpArgsP2 = null; Player2.StateMachine.TransitionIdle(); } } } Vector2 parallax = new Vector2(1.0f); GraphicsDevice.Clear(Color.LightSkyBlue); GraphicsDevice.Viewport = player1Viewport; _backgroundP1.Draw(); gameGrid.CurrentLeftSideViewPort = Player1Camera.Position.X; gameGrid.CurrentTopSideViewPort = Player1Camera.Position.Y; List <AbstractGameObject> player1Objects = gameGrid.GetAllCurrentGameObjects; spriteBatch.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, Player1Camera.GetViewMatrix(parallax)); if (transitioningAreaP1 && !(State == GameState.Paused)) { opacityChangeTimeDeltaP1 += gameTime.ElapsedGameTime.Milliseconds; if (opacityChangeTimeDeltaP1 >= 1) { opacityChangeTimeDeltaP1 = 0; warpOpacityP1 += opacityChangeP1; } } DrawPlayerHalfOfGame(gameTime, HUDs[0], Player1Camera, player1Objects, transitioningAreaP1, warpOpacityP1); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.BackToFront); if (Player1.LevelCompleted) { player1CompletedMenu.Draw(spriteBatch, gameTime); } spriteBatch.End(); if (Mode == GameMode.MultiPlayer) { GraphicsDevice.Viewport = player2Viewport; _backgroundP2.Draw(); gameGrid.CurrentLeftSideViewPort = Player2Camera.Position.X; gameGrid.CurrentTopSideViewPort = Player2Camera.Position.Y; List <AbstractGameObject> player2Objects = gameGrid.GetAllCurrentGameObjects; spriteBatch.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, Player2Camera.GetViewMatrix(parallax)); //TODO probably remove time delta if (transitioningAreaP2 && !(State == GameState.Paused)) { opacityChangeTimeDeltaP2 += gameTime.ElapsedGameTime.Milliseconds; if (opacityChangeTimeDeltaP2 >= 1) { opacityChangeTimeDeltaP2 = 0; warpOpacityP2 += opacityChangeP2; } } DrawPlayerHalfOfGame(gameTime, HUDs[1], Player2Camera, player2Objects, transitioningAreaP2, warpOpacityP2); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.BackToFront); if (Player2.LevelCompleted) { player2CompletedMenu.Draw(spriteBatch, gameTime); } spriteBatch.End(); } GraphicsDevice.Viewport = new Viewport(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); if (Mode == GameMode.MultiPlayer) { spriteBatch.Begin(SpriteSortMode.BackToFront); using (Texture2D pixel = new Texture2D(GraphicsDevice, 1, 1)) { Color[] color = { Color.Crimson }; pixel.SetData(color); spriteBatch.Draw(pixel, new Rectangle(player1Viewport.Width, 0, player2Viewport.X - player1Viewport.Width, graphics.PreferredBackBufferHeight), Color.White); } spriteBatch.End(); } if (State == GameState.Paused) { spriteBatch.Begin(SpriteSortMode.BackToFront); pauseMenu.Draw(spriteBatch, gameTime); spriteBatch.End(); base.Draw(gameTime); } base.Draw(gameTime); } else if (State == GameState.GameStart) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.BackToFront); mainMenu.Draw(spriteBatch, gameTime); spriteBatch.End(); base.Draw(gameTime); } else if (State == GameState.GameOver) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.BackToFront); gameOverScreen.Draw(spriteBatch, gameTime); spriteBatch.End(); base.Draw(gameTime); } }