Beispiel #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);
        }
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <param name="screen"></param>
        public TestDrawingSpritesScreenView(Screen screen) : base(screen)
        {
            #region GREEN_BOX
            GreenBox = new Sprite()
            {
                Parent    = Container,
                Size      = new ScalableVector2(50, 50),
                Tint      = Color.Green,
                Position  = new ScalableVector2(0, 10),
                Alignment = Alignment.TopCenter
            };

            GreenBox.AddBorder(Color.White, 2);
            #endregion

            #region HELLO_WORLD_TEXT
            HelloWorldText = new SpriteText("exo2-bold", "Hello, World!", 18)
            {
                Parent    = Container,
                Alignment = Alignment.TopCenter,
                Y         = GreenBox.Height + GreenBox.Y + 40
            };
            #endregion

            #region CLICK_ME_BUTTON
            ClickMeButton = new TextButton(WobbleAssets.WhiteBox, "exo2-bold", "Click me!", 18, (sender, args) =>
            {
                // Click event handler method goes here.
                // Choose a random background color!
                BackgroundColor = new Color(Rng.Next(0, 255), Rng.Next(0, 255), Rng.Next(0, 255));
            })
            {
                Parent    = Container,
                Size      = new ScalableVector2(150, 50),
                Tint      = Color.White,
                Text      = { Tint = Color.Black },
                Alignment = Alignment.TopCenter,
                Y         = HelloWorldText.Y + 40
            };
            #endregion

            #region ANIMATING_LIGHTING
            AnimatingLighting = new AnimatableSprite(Textures.TestSpritesheet)
            {
                Parent    = Container,
                Size      = new ScalableVector2(200, 200),
                Alignment = Alignment.MidRight,
                X         = -20,
                // Here we will create new custom SpriteBatchOptions for this sprite.
                // This overrides SpriteBatch.Begin() to include these new SpriteBatchOptions ONLY for this sprite and any
                // sprites drawn after it that specify `UsePreviousSpriteBatchOptions`
                //
                // IMPORTANT!
                // Any sprites you want to have these same SpriteBatch.Begin options for WITHOUT creating a new SpriteBatch,
                // you must set `UsePreviousSpriteBatchOptions` to true.
                SpriteBatchOptions = new SpriteBatchOptions {
                    BlendState = BlendState.Additive
                },
            };

            // Start the animation loop forwards at 60FPS infinitely.
            AnimatingLighting.StartLoop(Direction.Forward, 60);
            #endregion

            #region SPRITE_WITH_SHADER
            SpriteWithShader = new Sprite
            {
                Image              = WobbleAssets.WhiteBox,
                Size               = new ScalableVector2(200, 200),
                Alignment          = Alignment.TopCenter,
                Parent             = Container,
                Tint               = Color.Orange,
                Y                  = ClickMeButton.Y + ClickMeButton.Height + 40,
                SpriteBatchOptions = new SpriteBatchOptions
                {
                    SortMode          = SpriteSortMode.Deferred,
                    BlendState        = BlendState.NonPremultiplied,
                    SamplerState      = SamplerState.PointClamp,
                    DepthStencilState = DepthStencilState.Default,
                    RasterizerState   = RasterizerState.CullNone,
                    // The shader attached is to make the sprite semi transparent
                    // Shader created by "Vortex-" (https://github.com/VortexCoyote)
                    Shader = new Shader(GameBase.Game.Resources.Get("Wobble.Tests.Resources/Shaders/semi-transparent.mgfxo"),
                                        new Dictionary <string, object>
                    {
                        { "p_dimensions", new Vector2(200, 200) },
                        { "p_position", new Vector2(0, 0) },
                        { "p_rectangle", new Vector2(100, 100) },
                        { "p_alpha", 0f }
                    })
                }
            };
            #endregion
        }