コード例 #1
0
        /// <summary>
        /// Draws the gameplay screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None);
            stage.drawBackground(spriteBatch);
            player1.Draw(spriteBatch);
            foreach (Enemy e in stage.getEnemyList())
            {
                e.Draw(spriteBatch);
                if (e.hasHealthBar)
                {
                    DrawHealthBar(spriteBatch, e);
                }
            }
            foreach (Food f in stage.getFoodList())
            {
                f.Draw(spriteBatch);
            }
            score = String.Format("{0:d}", player1.getScore());
            lives = String.Format("{0:d}", player1.getLives());
            mult  = "x" + String.Format("{0:d}", player1.getMult());
            Color multColor = Color.Black;

            if (player1.getMult() == 4)
            {
                multColor = Color.Green;
            }
            spriteBatch.DrawString(UIFont, "Score", scoreLabelPos, Color.Black, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0.05f);
            spriteBatch.DrawString(UIFont, "Lives", livesLabelPos, Color.Black, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0.05f);
            spriteBatch.DrawString(UIFont, score, scorePos, Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.05f);
            spriteBatch.DrawString(UIFont, lives, livesPos, Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.05f);
            spriteBatch.DrawString(UIFont, mult, multPos, multColor, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.05f);
            spriteBatch.End();

            // If the game is transitioning on or off, fade it out to black.
            if (TransitionPosition > 0)
            {
                ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha);
            }
        }
コード例 #2
0
        /// <summary>
        /// Draws the message box.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            SpriteFont  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.
            Viewport viewport     = ScreenManager.GraphicsDevice.Viewport;
            Vector2  viewportSize = new Vector2(viewport.Width, viewport.Height);
            Vector2  textSize     = font.MeasureString(message);
            Vector2  textPosition = (viewportSize - textSize) / 2;

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

            Rectangle 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.
            Color color = new Color(255, 255, 255, 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();
        }
コード例 #3
0
        /// <summary>
        /// Draws the pause menu screen. This darkens down the gameplay screen
        /// that is underneath us, and then chains to the base MenuScreen.Draw.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);

            base.Draw(gameTime);
        }
コード例 #4
0
        /// <summary>
        /// Draws the pause menu screen. This darkens down the gameplay screen
        /// that is underneath us, and then chains to the base MenuScreen.Draw.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            SpriteFont  font        = ScreenManager.Font;

            Vector2 position = new Vector2(400, 450);
            Vector2 scorePos = new Vector2(400, 200);
            Vector2 contPos  = new Vector2(400, 375);
            // 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);

            if (ScreenState == ScreenState.TransitionOn)
            {
                position.X -= transitionOffset * 256;
                scorePos.X -= transitionOffset * 256;
                contPos.X  -= transitionOffset * 256;
            }
            else
            {
                position.X += transitionOffset * 512;
                scorePos.X += transitionOffset * 512;
                contPos.X  += transitionOffset * 512;
            }

            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.DrawCenter(this, position, isSelected, gameTime);

                position.Y += menuEntry.GetHeight(this);
            }

            // Draw the menu title.
            Vector2 titlePosition = new Vector2(400, 80);
            Vector2 titleOrigin   = font.MeasureString(menuTitle) / 2;
            Color   titleColor    = new Color(255, 255, 255, TransitionAlpha);
            float   titleScale    = 1.25f;

            titlePosition.Y -= transitionOffset * 100;

            spriteBatch.DrawString(font, menuTitle, titlePosition, titleColor, 0,
                                   titleOrigin, titleScale, SpriteEffects.None, 0);

            String  score       = "Score: " + String.Format("{0:d}", pc.getScore());
            Vector2 scoreOrigin = font.MeasureString(score) / 2;

            spriteBatch.DrawString(font, score, scorePos, Color.White, 0, scoreOrigin, 1, SpriteEffects.None, 0);

            String  cont       = "Continue?";
            Vector2 contOrigin = font.MeasureString(cont) / 2;

            spriteBatch.DrawString(font, cont, contPos, Color.White, 0, contOrigin, 1, SpriteEffects.None, 0);
            spriteBatch.End();
        }