示例#1
0
        public override void Draw(RenderManager renderMgr, Camera camera)
        {
            float healthFactor = HealthComponent.CurrentHealth / HealthComponent.MaxHealth;

            if (healthFactor < 0)
                healthFactor = 0;

            float shieldFactor = HealthComponent.CurrentShield / HealthComponent.MaxShield;
            if (shieldFactor < 0)
                shieldFactor = 0;

            HealthVertices[0].Position = new Vector2f(HealthLeftX, HealthTopY);
            HealthVertices[1].Position = new Vector2f(HealthLeftX, HealthBottomY);
            HealthVertices[2].Position = new Vector2f(HealthLeftX + (HealthBottomRightX - HealthLeftX) * healthFactor, HealthBottomY);
            HealthVertices[3].Position = new Vector2f(HealthLeftX + (HealthTopRightX - HealthLeftX) * healthFactor, HealthTopY);

            ShieldVertices[0].Position = new Vector2f(ShieldTopLeftX, ShieldTopY);
            ShieldVertices[1].Position = new Vector2f(ShieldBottomLeftX, ShieldBottomY);
            ShieldVertices[2].Position = new Vector2f(ShieldBottomLeftX + (ShieldRightX - ShieldBottomLeftX) * shieldFactor, ShieldBottomY);
            ShieldVertices[3].Position = new Vector2f(ShieldTopLeftX + (ShieldRightX - ShieldTopLeftX) * shieldFactor, ShieldTopY);

            for (int i = 0; i < 4; i++)
            {
                HealthVertices[i].Position = HealthVertices[i].Position + Offset;
                ShieldVertices[i].Position = ShieldVertices[i].Position + Offset;
            }

            renderMgr.SetOverlayView();

            RenderStates renderStates = new RenderStates(BorderTexture);
            RenderStates healthGradientRenderStates = new RenderStates(HealthTexture);
            RenderStates shieldGradientRenderStates = new RenderStates(ShieldTexture);

            renderMgr.Target.Draw(BorderVertices, PrimitiveType.Quads, renderStates);
            renderMgr.Target.Draw(HealthVertices, PrimitiveType.Quads, healthGradientRenderStates);
            renderMgr.Target.Draw(ShieldVertices, PrimitiveType.Quads, shieldGradientRenderStates);

            renderMgr.SetCameraView();
        }