PathfindingTest.Map.MiniMap.Draw C# (CSharp) Method

Draw() public method

Draws the minimap on the screen
public Draw ( SpriteBatch sb, Rectangle targetRectangle ) : void
sb Microsoft.Xna.Framework.Graphics.SpriteBatch SpriteBatch to draw on.
targetRectangle Microsoft.Xna.Framework.Rectangle The target rectangle the minimap will appear on.
return void
        public void Draw(SpriteBatch sb, Rectangle targetRectangle)
        {
            if (game.isFoggy)
            {
                if (miniMainTarget == null)
                {
                    miniMainTarget = game.CreateRenderTarget(targetRectangle.Width, targetRectangle.Height);
                }
                if (miniLightTarget == null)
                {
                    miniLightTarget = game.CreateRenderTarget(targetRectangle.Width, targetRectangle.Height);
                }

                game.GraphicsDevice.SetRenderTarget(miniMainTarget);
                game.GraphicsDevice.Clear(Color.Black);
            }

            currentDrawRectangle = targetRectangle;

            //sb.Draw(this.miniMapTexture, targetRectangle, null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, this.z);
            sb.Draw(this.miniMapTexture, new Rectangle(0,0,targetRectangle.Width,targetRectangle.Height), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, this.z);

            for (int i = 0; i < game.players.Count(); i++)
            {
                Player p = game.players.ElementAt(i);
                for (int j = 0; j < p.units.Count(); j++)
                {
                    Unit unit = p.units.ElementAt(j);
                    Point miniMapPoint = this.MapToMiniMap(unit.GetLocation());
                    sb.Draw(DrawUtil.lineTexture, new Rectangle(miniMapPoint.X - 1,
                        miniMapPoint.Y - 1,
                        2, 2), null, p.color, 0f, Vector2.Zero, SpriteEffects.None, this.z - 0.00001f);
                }

                for (int j = 0; j < p.buildings.Count(); j++)
                {
                    Building building = p.buildings.ElementAt(j);
                    if (building.state == Building.State.Preview) continue;
                    Point miniMapPoint = this.MapToMiniMap(building.GetLocation());
                    sb.Draw(DrawUtil.lineTexture, new Rectangle(miniMapPoint.X - 2,
                        miniMapPoint.Y - 2,
                        4, 4), null, p.color, 0f, Vector2.Zero, SpriteEffects.None, this.z - 0.00001f);
                }
            }

            sb.End();

            if (game.isFoggy)
            {
                try
                {
                    game.GraphicsDevice.SetRenderTarget(miniLightTarget);
                    game.GraphicsDevice.Clear(Color.Black);

                    sb.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

                    Game1.CURRENT_PLAYER.DrawMiniLights(sb, this);

                    sb.End();

                    game.GraphicsDevice.SetRenderTarget(null);

                    Texture2D miniMainTex = miniMainTarget;
                    Texture2D miniLightTex = miniLightTarget;

                    game.basicMiniFogOfWarEffect.Parameters["LightsTexture"].SetValue(miniLightTex);

                    sb.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

                    foreach (EffectPass effect in game.basicMiniFogOfWarEffect.CurrentTechnique.Passes)
                    {
                        effect.Apply();
                    }

                    sb.Draw(
                        miniMainTex,
                        targetRectangle,
                        Color.White
                    );

                    sb.End();

                }
                catch (Exception e) {
                    Console.WriteLine(e.Message);
                }
            }

            game.GraphicsDevice.SetRenderTarget(null);

            sb.Begin(SpriteSortMode.FrontToBack, null);

            this.DrawScreenRectangle(sb);
        }