MrGravity.MrGravityMain.DrawHud C# (CSharp) Méthode

DrawHud() public méthode

public DrawHud ( ) : void
Résultat void
        public void DrawHud()
        {
            Rectangle mScreenRect = Graphics.GraphicsDevice.Viewport.TitleSafeArea;
            _mSpriteBatch.Begin();

            var goalString = "Goal: ";
            Vector2 goalLength = _mQuartz.MeasureString(goalString);

            /* TIMER VARIABLES*/
            var timerString = "Timer: ";
            var timeString = _mCurrentLevel.Timer.ToString();
            var timeGoal = _mCurrentLevel.IdealTime.ToString();
            Vector2 timerLength = _mQuartz.MeasureString(timerString);
            Vector2 numberLength = _mQuartz.MeasureString("99   ");

            /* COLLECTED VARIABLES*/
            var collectedString = "Collected: ";
            var collectString = _mCurrentLevel.NumCollected.ToString(); // + "/" + mCurrentLevel.NumCollectable;
            var collectGoal = _mCurrentLevel.NumCollectable.ToString();
            Vector2 collectedLength = _mQuartz.MeasureString(collectedString);

            /* DEATHS VARIABLE*/
            var livesString = "Lives:";
            //int lives = mCurrentLevel.NumLives;
            Vector2 livesLength = _mQuartz.MeasureString(livesString);

            //Draw Timer

            //HUDTrans block
            _mSpriteBatch.Draw(_mHudTrans, new Rectangle(mScreenRect.Left, mScreenRect.Top,
                (int) timerLength.X + (int) numberLength.X, (int) timerLength.Y + (int) numberLength.Y), Color.White);

            var placement = new Vector2(mScreenRect.Left + 10, mScreenRect.Top);
            _mSpriteBatch.DrawString(_mQuartz, timerString, new Vector2(placement.X - 1, placement.Y - 1), Color.White);
            _mSpriteBatch.DrawString(_mQuartz, timerString, placement, Color.SteelBlue);
            _mSpriteBatch.DrawString(_mQuartz, timeString, new Vector2(placement.X + timerLength.X, placement.Y),
                Color.White);
            placement.Y += timerLength.Y;
            _mSpriteBatch.DrawString(_mQuartz, goalString, new Vector2(placement.X - 1, placement.Y - 1), Color.White);
            _mSpriteBatch.DrawString(_mQuartz, goalString, placement, Color.SteelBlue);
            _mSpriteBatch.DrawString(_mQuartz, timeGoal, new Vector2(placement.X + timerLength.X, placement.Y),
                Color.White);

            //Draw collected

            //HUDTrans block
            _mSpriteBatch.Draw(_mHudTrans,
                new Rectangle(mScreenRect.Right - (int) collectedLength.X - (int) numberLength.X, mScreenRect.Top,
                    (int) collectedLength.X + (int) numberLength.X, (int) collectedLength.Y + (int) numberLength.Y),
                Color.White);

            placement = new Vector2(mScreenRect.Right - collectedLength.X - numberLength.X, mScreenRect.Top);
            _mSpriteBatch.DrawString(_mQuartz, collectedString, new Vector2(placement.X - 1, placement.Y - 1),
                Color.White);
            _mSpriteBatch.DrawString(_mQuartz, collectedString, placement, Color.SteelBlue);
            _mSpriteBatch.DrawString(_mQuartz, collectString, new Vector2(placement.X + collectedLength.X, placement.Y),
                Color.White);
            placement.Y += collectedLength.Y;
            _mSpriteBatch.DrawString(_mQuartz, goalString, new Vector2(placement.X - 1, placement.Y - 1), Color.White);
            _mSpriteBatch.DrawString(_mQuartz, goalString, placement, Color.SteelBlue);
            _mSpriteBatch.DrawString(_mQuartz, collectGoal, new Vector2(placement.X + collectedLength.X, placement.Y),
                Color.White);
            placement.Y += goalLength.Y;

            //Draw deaths

            //HUDTrans block
            _mSpriteBatch.Draw(_mHudTrans, new Rectangle(mScreenRect.Left, mScreenRect.Bottom - _mLives[0].Height - 10,
                (int) livesLength.X + (int) (_mLives[0].Width*0.75f)*(_mCurrentLevel.NumLives + 1),
                _mLives[0].Height + 5), Color.White);

            //Number lives
            placement = new Vector2(mScreenRect.Left + 10, mScreenRect.Bottom - _mLives[0].Height - 10);

            _mSpriteBatch.DrawString(_mQuartz, livesString, new Vector2(placement.X - 1, placement.Y - 1), Color.White);
            _mSpriteBatch.DrawString(_mQuartz, livesString, placement, Color.SteelBlue);

            placement = new Vector2(mScreenRect.Left + livesLength.X, mScreenRect.Bottom - _mLives[0].Height - 10);
            if (_mCurrentLevel.NumLives == 5)
            {
                _mSpriteBatch.Draw(_mLives[5],
                    new Rectangle((int) (placement.X + (_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
                _mSpriteBatch.Draw(_mLives[5],
                    new Rectangle((int) (placement.X + 2*(_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
                _mSpriteBatch.Draw(_mLives[5],
                    new Rectangle((int) (placement.X + 3*(_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
                _mSpriteBatch.Draw(_mLives[5],
                    new Rectangle((int) (placement.X + 4*(_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
                _mSpriteBatch.Draw(_mLives[5],
                    new Rectangle((int) (placement.X + 5*(_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
            }
            else if (_mCurrentLevel.NumLives == 4)
            {
                _mSpriteBatch.Draw(_mLives[4],
                    new Rectangle((int) (placement.X + (_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
                _mSpriteBatch.Draw(_mLives[4],
                    new Rectangle((int) (placement.X + 2*(_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
                _mSpriteBatch.Draw(_mLives[4],
                    new Rectangle((int) (placement.X + 3*(_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
                _mSpriteBatch.Draw(_mLives[4],
                    new Rectangle((int) (placement.X + 4*(_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
            }
            else if (_mCurrentLevel.NumLives == 3)
            {
                _mSpriteBatch.Draw(_mLives[3],
                    new Rectangle((int) (placement.X + (_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
                _mSpriteBatch.Draw(_mLives[3],
                    new Rectangle((int) (placement.X + 2*(_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
                _mSpriteBatch.Draw(_mLives[3],
                    new Rectangle((int) (placement.X + 3*(_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
            }
            else if (_mCurrentLevel.NumLives == 2)
            {
                _mSpriteBatch.Draw(_mLives[2],
                    new Rectangle((int) (placement.X + (_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
                _mSpriteBatch.Draw(_mLives[2],
                    new Rectangle((int) (placement.X + 2*(_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
            }
            else if (_mCurrentLevel.NumLives == 1)
            {
                _mSpriteBatch.Draw(_mLives[1],
                    new Rectangle((int) (placement.X + (_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
            }
            else if (_mCurrentLevel.NumLives == 0)
            {
                _mSpriteBatch.Draw(_mLives[0],
                    new Rectangle((int) (placement.X + (_mLives[0].Width*0.75f)), (int) placement.Y,
                        (int) (_mLives[0].Width*0.6f), (int) (_mLives[0].Height*0.6f)), Color.White);
            }

            if (_mCurrentLevel.NumLives <= 0)
            {
                var request = "Out of Lives       Press A to Restart";

                Vector2 stringSize = _mQuartz.MeasureString(request);
                _mSpriteBatch.DrawString(_mQuartz, request,
                    new Vector2(mScreenRect.Center.X - stringSize.X/2, mScreenRect.Center.Y), Color.DarkTurquoise);
                _mSpriteBatch.DrawString(_mQuartz, request,
                    new Vector2(mScreenRect.Center.X - stringSize.X/2 + 2, mScreenRect.Center.Y + 2), Color.White);

            }
            _mSpriteBatch.End();
        }