Beispiel #1
0
        public void UpdateHp()
        {
            HealthText.Text = Player.BattleData.CurrentHp.GetDouble() > 0 ?
                              Player.BattleData.CurrentHp.GetDouble().ToString("0") : "-";
            Hp.BeginAnimation(RangeBase.ValueProperty, new DoubleAnimation()
            {
                From           = Hp.Value,
                To             = Player.BattleData.CurrentHp.GetDouble(),
                Duration       = TimeSpan.FromSeconds(0.3),
                EasingFunction = new ExponentialEase()
                {
                    EasingMode = EasingMode.EaseInOut
                }
            });

            double HpRatio = Player.BattleData.CurrentHp.GetDouble() / BattleData.TotalHp;
            Color  Color;

            if (Player.BattleData.CurrentHp.GetInt() == 0)
            {
                Color = Colors.Gray;
            }
            else if (HpRatio <= 0.25)
            {
                Color = Colors.Red;
            }
            else if (HpRatio <= 0.5)
            {
                Color = Colors.DarkOrange;
            }
            else if (HpRatio <= 0.75)
            {
                Color = Colors.YellowGreen;
            }
            else
            {
                Color = Colors.LimeGreen;
            }

            HealthText.Foreground = HealthText.Foreground.Clone();
            ((SolidColorBrush)HealthText.Foreground).BeginAnimation(SolidColorBrush.ColorProperty,
                                                                    new ColorAnimation()
            {
                From           = ((SolidColorBrush)HealthText.Foreground).Color,
                To             = Color,
                Duration       = TimeSpan.FromSeconds(0.3),
                EasingFunction = new ExponentialEase()
                {
                    EasingMode = EasingMode.EaseInOut
                }
            });
            Hp.Foreground = Hp.Foreground.Clone();
            ((SolidColorBrush)Hp.Foreground).BeginAnimation(SolidColorBrush.ColorProperty,
                                                            new ColorAnimation()
            {
                From           = ((SolidColorBrush)Hp.Foreground).Color,
                To             = Color,
                Duration       = TimeSpan.FromSeconds(0.3),
                EasingFunction = new ExponentialEase()
                {
                    EasingMode = EasingMode.EaseInOut
                }
            });
        }