/// <summary> /// Draws the menu. /// </summary> public override void Draw(GameTime gameTime) { SpriteBatch spriteBatch = ScreenManager.SpriteBatch; SpriteFont font = ScreenManager.Font; if (this is MessageBoxScreen) { // make sure our entries are in the right place before we draw them UpdateMessageBoxMenuEntryLocations(); // Darken down any other screens that were drawn beneath the popup. ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 7 / 10); // Center the message text in the viewport. Viewport viewport = ScreenManager.GraphicsDevice.Viewport; Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height); Vector2 textSize = new Vector2(gradientTexture.Width, gradientTexture.Height); Vector2 textPosition = textSize / 6; // The background includes a border somewhat larger than the text itself. const int hPad = 320; const int vPad = 140; Rectangle backgroundRectangle = new Rectangle((int)textPosition.X - hPad, (int)textPosition.Y - vPad, (int)(textSize.X * 1.1), (int)(textSize.Y * 1.1)); // Fade the popup alpha during transitions. Color color = Color.White * TransitionAlpha; GraphicsDevice graphics = ScreenManager.GraphicsDevice; spriteBatch.Begin(); // Draw the background rectangle. spriteBatch.Draw(gradientTexture, backgroundRectangle, color); // Draw each menu entry in turn. for (int i = 0; i < menuEntries.Count; i++) { MenuEntry menuEntry = menuEntries[i]; bool isSelected = IsActive && (i == selectedEntry); menuEntry.Draw(this, isSelected, gameTime); } // Make the menu slide into place during transitions, using a // power curve to make things look more interesting (this makes // the movement slow down as it nears the end). float transitionOffset = (float)Math.Pow(TransitionPosition, 2); // Draw the menu title centered on the screen Vector2 titlePosition = new Vector2(graphics.Viewport.Width / 2, 250f); Vector2 titlePosition2 = new Vector2((graphics.Viewport.Width / 2) - 1, 249f); Vector2 titleOrigin = font.MeasureString(menuTitle) / 2; float titleScale = 1.25f; // titlePosition.Y -= transitionOffset * 100; spriteBatch.DrawString(font, menuTitle, titlePosition, Color.Black, 0, titleOrigin, titleScale, SpriteEffects.None, 0); spriteBatch.DrawString(font, menuTitle, titlePosition2, Color.Violet, 0, titleOrigin, titleScale, SpriteEffects.None, 0); spriteBatch.End(); } else { // make sure our entries are in the right place before we draw them UpdateMenuEntryLocations(); if (!(this is MainMenuScreen)) { // Darken down any other screens that were drawn beneath the popup. ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 4 / 5); } GraphicsDevice graphics = ScreenManager.GraphicsDevice; spriteBatch.Begin(); // Draw each menu entry in turn. for (int i = 0; i < menuEntries.Count; i++) { MenuEntry menuEntry = menuEntries[i]; bool isSelected = IsActive && (i == selectedEntry); menuEntry.Draw(this, isSelected, gameTime); } // Make the menu slide into place during transitions, using a // power curve to make things look more interesting (this makes // the movement slow down as it nears the end). float transitionOffset = (float)Math.Pow(TransitionPosition, 2); // Draw the menu title centered on the screen Vector2 titlePosition = new Vector2(graphics.Viewport.Width / 2, 80); Vector2 titleOrigin = font.MeasureString(menuTitle) / 2; Color titleColor = new Color(192, 192, 192) * TransitionAlpha; float titleScale = 1.25f; titlePosition.Y -= transitionOffset * 100; spriteBatch.DrawString(font, menuTitle, titlePosition, titleColor, 0, titleOrigin, titleScale, SpriteEffects.None, 0); spriteBatch.End(); ScreenManager.GraphicsDevice.RasterizerState = RasterizerState.CullNone; ScreenManager.GraphicsDevice.BlendState = BlendState.Opaque; ScreenManager.GraphicsDevice.DepthStencilState = DepthStencilState.Default; ScreenManager.GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; } }
/// <summary> /// Draws the gameplay screen. /// </summary> public override void Draw(GameTime gameTime) { // This game has a red background. Why? Because BLOOD LOL ScreenManager.GraphicsDevice.Clear(ClearOptions.Target, Color.Red, 0, 0); currentLevel.Draw(); Game1.getGraphicsDevice().SetRenderTarget(null); // If the game is transitioning on or off, fade it out to black. if (TransitionPosition > 0 || pauseAlpha > 0) { float alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, pauseAlpha / 2); ScreenManager.FadeBackBufferToBlack(alpha); } if (player.controls.Locked && !oldPlayerLocked) //fade out { //Debug.WriteLine("fade out!"); fadeOut = true; fadeIn = false; iAlpha = 255; } else if (!player.controls.Locked && oldPlayerLocked) //fade in { //Debug.WriteLine("fade in!"); fadeIn = true; fadeOut = false; iAlpha = 0; } else { if (fadeIn) { iAlpha += 1; //Debug.WriteLine("alpha="+iAlpha); if (iAlpha == 255) { fadeIn = false; } //Debug.WriteLine("fadein=" + fadeIn); } if (fadeOut) { iAlpha -= 1; //Debug.WriteLine("alpha=" + iAlpha); if (iAlpha == 0) { fadeOut = false; } //Debug.WriteLine("fadeout=" + fadeOut); } } DrawUI(); oldPlayerLocked = player.controls.Locked; ScreenManager.GraphicsDevice.RasterizerState = RasterizerState.CullNone; ScreenManager.GraphicsDevice.BlendState = BlendState.Opaque; ScreenManager.GraphicsDevice.DepthStencilState = DepthStencilState.Default; ScreenManager.GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; }