Esempio n. 1
0
        static public void Draw(SpriteBatch spriteBatch)
        {
            if (_healthBar == null || _healthUnit == null)
            {
                return;
            }
            var _player = PlayerController.Player;

            if (_player == null)
            {
                return;
            }

            spriteBatch.Begin(SpriteSortMode.FrontToBack,
                              BlendState.AlphaBlend,
                              SamplerState.PointClamp,
                              null,
                              null,
                              null,
                              ManageResolution.GetTransformationMatrix());

            spriteBatch.Draw(_healthBarExtender, new Vector2(16, 40 - (4 * (PlayerStats.MaxHealth - 12))), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.2f);
            spriteBatch.Draw(_healthBar, new Vector2(16, 40), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, .1f);


            for (int i = 0; i < PlayerCurrentHealth; i++)
            {
                spriteBatch.Draw(_healthUnit, new Vector2(16 + (4), 49 + 40 - (4 * i)), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.3f);
            }

            if (ManageInput.GamePaused)
            {
                spriteBatch.Draw(_pauseTexture, new Rectangle(0, 0, ManageResolution.VirtualWidth, ManageResolution.VirtualHeight), new Color(Color.Black, _alpha));
            }

            if (ManageInput.GamePaused)
            {
                _manageMenu.Draw(spriteBatch);
            }

            spriteBatch.End();
        }
Esempio n. 2
0
        private static void CalculateMatrixAndRectangle()
        {
            //The math involved with calculated our transformMatrix and screenRect is a little intense, so instead of calling the math whenever we need these variables,
            //we'll calculate them once each frame and store them... when someone needs these variables we will simply return the stored variable instead of re cauclating them every time.

            //Calculate the camera transform matrix:
            transformMatrix = Matrix.CreateTranslation(new Vector3(-position, 0)) * Matrix.CreateRotationZ(rotation) *
                              Matrix.CreateScale(new Vector3(zoom, zoom, 1)) * Matrix.CreateTranslation(new Vector3(ManageResolution.VirtualWidth
                                                                                                                    * 0.5f, ManageResolution.VirtualHeight * 0.5f, 0));

            //Now combine the camera's matrix with the Resolution Manager's transform matrix to get our final working matrix:
            transformMatrix = transformMatrix * ManageResolution.GetTransformationMatrix();

            //Round the X and Y translation so the camera doesn't jerk as it moves:
            transformMatrix.M41 = (float)Math.Round(transformMatrix.M41, 0);
            transformMatrix.M42 = (float)Math.Round(transformMatrix.M42, 0);

            //Calculate the rectangle that represents where our camera is at in the world:
            screenRect = VisibleArea();
        }