/// <summary> /// Draws the gameplay screen. /// </summary> public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) { spriteBatch.GraphicsDevice.Clear(ClearOptions.Target, Color.White, 0, 0); spriteBatch.Begin(); // Draw the background. spriteBatch.Draw(editableLevel.Background, Vector2.Zero, Color.White); // Draw the walls. DrawWalls(spriteBatch); // Draw all the level objects. DrawLevelObjects(spriteBatch); // Draw any informational text. DrawText(spriteBatch); spriteBatch.End(); // 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); spriteBatch.FadeBackBufferToBlack(alpha); } }
/// <summary> /// Draws the message box. /// </summary> public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) { // Darken down any other screens that were drawn beneath the popup. spriteBatch.FadeBackBufferToBlack(TransitionAlpha * 2 / 3); // Center the message text in the viewport. Viewport viewport = spriteBatch.GraphicsDevice.Viewport; Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height); Vector2 textSize = _font.MeasureString(_message); Vector2 textPosition = new Vector2(((viewportSize - textSize) / 2).X, 40); Rectangle backgroundRectangle = new Rectangle(20, 20, Simulation.FieldWidth - 40, Simulation.FieldHeight - 40); // Fade the popup alpha during transitions. Color color = Color.White * TransitionAlpha; spriteBatch.Begin(); // Draw the background rectangle. spriteBatch.Draw(_gradientTexture, backgroundRectangle, color); // Draw the platforms in the toolbox, referring to the dictionaries to determine // what textures to draw. foreach (Rectangle rect in _platforms) { Texture2D textureToUse = platformTextures[new Vector2(rect.Width, rect.Height)]; spriteBatch.Draw(textureToUse, new Vector2(rect.X, rect.Y), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); } foreach (Rectangle rect in _breakablePlatforms) { Texture2D textureToUse = breakablePlatformTextures[new Vector2(rect.Width, rect.Height)]; spriteBatch.Draw(textureToUse, new Vector2(rect.X, rect.Y), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); } if (editableLevel.Custom) { deathTrap.Draw(spriteBatch); treasure.Draw(spriteBatch); } // Draw the message box text. spriteBatch.DrawString(_font, _message, textPosition, color); spriteBatch.End(); }
public void Draw(SpriteBatch spriteBatch, GameTime gameTime, SpriteFont font, float transitionAlpha, Color color, Texture2D gradientTexture) { float transitionOffset = (float)Math.Pow(TransitionPosition, 2); Vector2 origin = new Vector2(spriteBatch.GraphicsDevice.Viewport.Width / 2, 0); // Darken down any other screens that were drawn beneath the popup. spriteBatch.FadeBackBufferToBlack(transitionAlpha * 2 / 3); GraphicsCursor cursor = new GraphicsCursor(); cursor.Position = origin; spriteBatch.Begin(); Rectangle backgroundRectangle = new Rectangle(RectangleXPosition, RectangleYPosition, ReactangleWidth, RectangleHeight); // Draw the background rectangle. spriteBatch.Draw(gradientTexture, backgroundRectangle, color); // Draw the title cursor.Y = backgroundRectangle.Top + font.LineSpacing; if (Title != null) { GraphicsCursor titleCursor = cursor; //Shift the title based on the current transition state. titleCursor = (new OffsetEffect(0, -transitionOffset * 100)).ApplyTo(titleCursor); Title.Draw(spriteBatch, titleCursor, gameTime); } //Draw the content cursor.Y = 175.0f; { GraphicsCursor lineCursor = cursor; // Modify the alpha to fade text out during transitions. lineCursor = (new AlphaEffect(1.0f - TransitionPosition)).ApplyTo(lineCursor); // Shift the text based on the current transition state. lineCursor = (new OffsetEffect(-transitionOffset * 256, 0)).ApplyTo(lineCursor); foreach (IMenuLine line in Lines) lineCursor.Y += line.Draw(spriteBatch, lineCursor, gameTime); } // Draw the buttons var labels = new Selection[] { Selection.Left, Selection.Middle, Selection.Right }; ItemRects.Clear(); cursor.X = backgroundRectangle.X + 100; cursor.Y = backgroundRectangle.Bottom - font.LineSpacing; // This was changed - Jorenz foreach (Selection label in labels) { MenuButton button; Buttons.TryGetValue(label, out button); if (button != null) { GraphicsCursor buttonCursor = cursor; // Modify the alpha to fade text out during transitions. buttonCursor = (new AlphaEffect(1.0f - TransitionPosition)).ApplyTo(buttonCursor); Rectangle box = button.Draw(spriteBatch, buttonCursor, label == SelectedItem, gameTime); ItemRects.Add(Tuple.Create(box, button)); } cursor.X += backgroundRectangle.Width / 3; } spriteBatch.End(); }