Exemplo n.º 1
0
        /// <inheritdoc />
        /// <summary>
        ///     Ctor
        /// </summary>
        /// <param name="type"></param>
        /// <param name="processor"></param>
        internal HealthBar(HealthBarType type, ScoreProcessor processor) : base(SkinManager.Skin.HealthBarBackground)
        {
            Type      = type;
            Processor = processor;

            Size = new ScalableVector2(Frames.First().Width, Frames.First().Height);

            // Start animation
            StartLoop(Direction.Forward, 60);

            // Create the foreground bar (the one that'll serve as the gauge progress).
            ForegroundBar = new AnimatableSprite(SkinManager.Skin.HealthBarForeground)
            {
                Parent             = this,
                SpriteBatchOptions = new SpriteBatchOptions()
                {
                    SortMode          = SpriteSortMode.Deferred,
                    BlendState        = BlendState.NonPremultiplied,
                    SamplerState      = SamplerState.PointClamp,
                    DepthStencilState = DepthStencilState.Default,
                    RasterizerState   = RasterizerState.CullNone,
                    Shader            = new Shader(GameBase.Game.Resources.Get("Quaver.Resources/Shaders/semi-transparent.mgfxo"), new Dictionary <string, object>()
                    {
                        { "p_position", new Vector2() },
                        { "p_rectangle", new Vector2() },
                        { "p_dimensions", new Vector2() },
                        { "p_alpha", 0f }
                    })
                }
            };

            ForegroundBar.Size = new ScalableVector2(ForegroundBar.Frames.First().Width, ForegroundBar.Frames.First().Height);

            // Start animation.
            ForegroundBar.StartLoop(Direction.Forward, 60);

            switch (Type)
            {
            case HealthBarType.Horizontal:
                Alignment = Alignment.TopLeft;
                ForegroundBar.Alignment = Alignment.TopLeft;

                ForegroundBar.SpriteBatchOptions.Shader.SetParameter("p_position", new Vector2(ForegroundBar.Width, 0f), true);
                break;

            case HealthBarType.Vertical:
                Alignment = Alignment.BotLeft;
                ForegroundBar.Alignment = Alignment.TopLeft;

                ForegroundBar.SpriteBatchOptions.Shader.SetParameter("p_position", new Vector2(0, 0), true);
                break;

            default:
                throw new NotImplementedException();
            }

            // Set default shader params.
            ForegroundBar.SpriteBatchOptions.Shader.SetParameter("p_rectangle", new Vector2(Width, Height), true);
            ForegroundBar.SpriteBatchOptions.Shader.SetParameter("p_dimensions", new Vector2(Width, Height), true);
        }
Exemplo n.º 2
0
    public void SetHealthBarType(HealthBarType healthBarType)
    {
        switch (healthBarType)
        {
        case HealthBarType.None:
            healthBar.SetActive(false);
            break;

        case HealthBarType.Friendly:
            healthBar.SetActive(true);
            break;

        case HealthBarType.Enemy:
            healthBar.SetActive(true);
            break;

        default:
            throw new ArgumentOutOfRangeException(nameof(healthBarType), healthBarType, null);
        }
    }
Exemplo n.º 3
0
 public static void WriteHealthBarType(this PacketWriter writer, HealthBarType data)
 {
     writer.WriteByte((byte)data);
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Reads a HealtHBarType
 /// </summary>
 /// <param name="defaultType"></param>
 /// <param name="newVal"></param>
 /// <returns></returns>
 internal static HealthBarType ReadHealthBarType(HealthBarType defaultType, string newVal)
 {
     return(Enum.TryParse(newVal, out HealthBarType newOne) ? newOne : defaultType);
 }