Пример #1
0
        /// <summary>
        /// Draws the gameplay screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            // This game has a blue background. Why? Because!
            ScreenManager.GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 0, 0);

            // Our player and enemy are both actually just text strings.
            var spriteBatch = ScreenManager.SpriteBatch;

            spriteBatch.Begin();

            //Draw Player Ship here
            _mPlayerShipSprite.Draw(spriteBatch);

            //draw Boss test sprite
            _mBossTestSprite.Draw(spriteBatch);

            if (_mPlayerShipSprite.IsHit) // Change the background to red when the player is hit by an enemy projectile
            {
                ScreenManager.GraphicsDevice.Clear(Color.DarkRed);
            }
            else if (_mBossTestSprite.IsHit) // Change the background to green when the enemy is hit by a player projectile
            {
                ScreenManager.GraphicsDevice.Clear(Color.DarkGreen);
            }
            else
            {
                ScreenManager.GraphicsDevice.Clear(Color.Black);
            }

            spriteBatch.End();

            // If the game is transitioning on or off, fade it out to black.
            if (!(TransitionPosition > 0) && !(_pauseAlpha > 0))
            {
                return;
            }

            //Linear interpolation
            var alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, _pauseAlpha / 2);

            ScreenManager.FadeBackBufferToBlack(alpha);
        }
Пример #2
0
        /// <summary>
        /// Draws the message box.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            var spriteBatch = ScreenManager.SpriteBatch;
            var font        = ScreenManager.Font;

            // Darken down any other screens that were drawn beneath the popup.
            ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);

            // Center the message text in the viewport.
            var viewport     = ScreenManager.GraphicsDevice.Viewport;
            var viewportSize = new Vector2(viewport.Width, viewport.Height);
            var textSize     = font.MeasureString(_message);
            var textPosition = (viewportSize - textSize) / 2;

            // The background includes a border somewhat larger than the text itself.
            const int hPad = 32;
            const int vPad = 16;

            var backgroundRectangle = new Rectangle(
                (int)textPosition.X - hPad,
                (int)textPosition.Y - vPad,
                (int)textSize.X + hPad * 2,
                (int)textSize.Y + vPad * 2);

            // Fade the popup alpha during transitions.
            var color = Color.White * TransitionAlpha;

            spriteBatch.Begin();

            // Draw the background rectangle.
            spriteBatch.Draw(_gradientTexture, backgroundRectangle, color);

            // Draw the message box text.
            spriteBatch.DrawString(font, _message, textPosition, color);

            spriteBatch.End();
        }