private void HealingAnimatedPeriodic()
 {
     if (isHealing)
     {
         bool fullyHealed = true;
         List <HeartsHealthSystem.Heart> heartList = heartsHealthSystem.GetHeartList();
         for (int i = 0; i < heartList.Count; i++)
         {
             HeartImage heartImage          = heartImageList[i];
             HeartsHealthSystem.Heart heart = heartList[i];
             if (heartImage.GetFragmentAmount() != heart.GetFragmentAmount())
             {
                 // Visual is different from logic
                 heartImage.AddHeartVisualFragment();
                 if (heartImage.GetFragmentAmount() == HeartsHealthSystem.MAX_FRAGMENT_AMOUNT)
                 {
                     // This heart was fully healed
                     heartImage.PlayHeartFullAnimation();
                 }
                 fullyHealed = false;
                 break;
             }
         }
         if (fullyHealed)
         {
             isHealing = false;
         }
     }
 }
    public void SetHeartsHealthSystem(HeartsHealthSystem heartsHealthSystem)
    {
        this.heartsHealthSystem  = heartsHealthSystem;
        heartsHealthSystemStatic = heartsHealthSystem;

        List <HeartsHealthSystem.Heart> heartList = heartsHealthSystem.GetHeartList();
        int   row        = 0;
        int   col        = 0;
        int   colMax     = 5;
        float rowColSize = 30f;

        for (int i = 0; i < heartList.Count; i++)
        {
            HeartsHealthSystem.Heart heart = heartList[i];
            Vector2 heartAnchoredPosition  = new Vector2(col * rowColSize, -row * rowColSize);
            CreateHeartImage(heartAnchoredPosition).SetHeartFraments(heart.GetFragmentAmount());

            col++;
            if (col >= colMax)
            {
                row++;
                col = 0;
            }
        }

        heartsHealthSystem.OnDamaged += HeartsHealthSystem_OnDamaged;
        heartsHealthSystem.OnHealed  += HeartsHealthSystem_OnHealed;
        heartsHealthSystem.OnDead    += HeartsHealthSystem_OnDead;
    }
    private void RefreshAllHearts()
    {
        List <HeartsHealthSystem.Heart> heartList = heartsHealthSystem.GetHeartList();

        for (int i = 0; i < heartImageList.Count; i++)
        {
            HeartImage heartImage          = heartImageList[i];
            HeartsHealthSystem.Heart heart = heartList[i];
            heartImage.SetHeartFraments(heart.GetFragmentAmount());
        }
    }
Ejemplo n.º 4
0
    private void HeartsHealthSystem_OnDamaged(object sender, EventArgs e)
    {
        // Hearts health system was damaged
        //RefreshAllHearts();
        List <HeartsHealthSystem.Heart> heartList = heartsHealthSystem.GetHeartList();

        for (int i = 0; i < heartImageList.Count; i++)
        {
            HeartImage heartImage          = heartImageList[i];
            HeartsHealthSystem.Heart heart = heartList[i];
            heartImage.SetHeartFragments(heart.GetFragmentAmount());
        }
    }