示例#1
0
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = TankWars.SpriteBatch;
            SpriteFont  font        = TankWars.Font;

            TankWars.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);

            Viewport viewport     = TankWars.GraphicsDevice.Viewport;
            Vector2  viewportSize = new Vector2(viewport.Width, viewport.Height);
            Vector2  textSize     = font.MeasureString(message);
            Vector2  textPosition = (viewportSize - textSize) / 2;

            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);

            Color color = Color.White * TransitionAlpha;

            spriteBatch.Begin();

            spriteBatch.Draw(gradientTexture, backgroundRectangle, Color.Orange);

            spriteBatch.DrawString(font, message, textPosition, color);

            spriteBatch.End();
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime)
        {
            // Màu nền
            TankWars.GraphicsDevice.Clear(Color.Black);

            // Dùng để vẽ các đối tượng
            SpriteBatch spriteBatch = TankWars.SpriteBatch;

            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend
                              /*, null, null, null, null, Camera.get_transformation(Game.GraphicsDevice)*/);



            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);

                TankWars.FadeBackBufferToBlack(alpha);
            }
        }
示例#3
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime)
        {
            // Màu nền
            TankWars.GraphicsDevice.Clear(Color.Black);

            // Dùng để vẽ các đối tượng
            SpriteBatch spriteBatch = TankWars.SpriteBatch;

            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend
                              /*, null, null, null, null, Camera.get_transformation(Game.GraphicsDevice)*/);

            // Vẽ Màn chơi
            Map.Draw(gameTime, spriteBatch);

            foreach (PowerIcon power in PowerIconList)
            {
                power.Draw(gameTime, spriteBatch);
            }

            // Vẽ Minimap
            Minimap.Draw(gameTime, spriteBatch);

            // Vẽ cursor người chơi
            Cursor.Draw(gameTime, spriteBatch);

            // Vẽ người chơi
            if (!Player.IsDead)
            {
                Player.Draw(gameTime, spriteBatch);
                Direction.Draw(gameTime, spriteBatch);
                Minimap.DrawDot(Player, Color.Blue, spriteBatch);
            }

            // Vẽ Health Bar
            HealthBar.Draw(Player.HitPoints, Player.MaxHitPoints, spriteBatch);

            // Vẽ Energy Bar
            EnergyBar.Draw(Player.EnergyPoints, Player.MaxEnergyPoints, spriteBatch);

            // Vẽ đạn
            foreach (Ammunition ammunition in AmmunitionList)
            {
                ammunition.Draw(gameTime, spriteBatch);
            }

            // Vẽ các vụ nổ
            foreach (Sprite effect in EffectList)
            {
                effect.Draw(gameTime, spriteBatch);
            }

            // Vẽ Enemy
            foreach (Tank enemy in EnemyList)
            {
                enemy.Draw(gameTime, spriteBatch);
                Minimap.DrawDot(enemy, Color.Red, 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);

                TankWars.FadeBackBufferToBlack(alpha);
            }
        }