Ejemplo n.º 1
0
 private void HealingAnimatedPeriodic()
 {
     if (isHealing)
     {
         float alpha = 1f / total * (total - GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth>().getCurrentHealth());
         GameObject.FindGameObjectWithTag("Mask").GetComponent <Image>().color = new Color(1, 1, 1, alpha);
         bool fullyHealed = true;
         List <HeartLogic.Heart> heartList = HSystem.getHeartList();
         for (int i = 0; i < heartsImageList.Count; i++)
         {
             HeartImage       hImage = heartsImageList[i];
             HeartLogic.Heart heart  = heartList[i];
             if (hImage.GetFragmentsAmount() != heart.getFragmentAmount())
             {
                 hImage.AddHeartVisualFragment();
                 fullyHealed = false;
                 break;
             }
         }
         if (fullyHealed)
         {
             isHealing = false;
         }
     }
 }
Ejemplo n.º 2
0
    public HeartImage CreateHeartImage(Vector2 anchoredPosition)
    {
        //Crear el GameObject
        GameObject heartGameObject = new GameObject("Heart", typeof(Image), typeof(Animation));

        //Ponerlo como hijo de este Transform
        heartGameObject.transform.SetParent(this.transform);
        heartGameObject.transform.localPosition = Vector3.zero;

        //Colocar la posicion del ancla y el tamaño del corazón
        heartGameObject.GetComponent <RectTransform>().anchoredPosition = anchoredPosition;
        heartGameObject.GetComponent <RectTransform>().sizeDelta        = new Vector2(heartsSize, heartsSize);
        heartGameObject.GetComponent <RectTransform>().localScale       = new Vector2(1, 1);

        heartGameObject.GetComponent <Animation>().AddClip(heartFullAnimationClip, "HeartFull");

        //Ponerle el sprite
        Image heartImageUI = heartGameObject.GetComponent <Image>();

        heartImageUI.sprite = heart0_Sprite;

        HeartImage heartImage = new HeartImage(this, heartImageUI, heartGameObject.GetComponent <Animation>());

        heartImageList.Add(heartImage);

        return(heartImage);
    }
Ejemplo n.º 3
0
    private HeartImage createAfter(HeartImage currentHeart)
    {
        RectTransform rectTransform = currentHeart.heartImage.GetComponent <RectTransform>();
        var           newHeart      = CreateHeartImage(new Vector2(rectTransform.anchoredPosition.x + 100, rectTransform.anchoredPosition.y));

        return(newHeart);
    }
 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;
         }
     }
 }
Ejemplo n.º 5
0
    public void HealingAnimatedPeriodic()
    {
        if (isHealing)
        {
            bool fullyHealed = true;

            List <HealthHeartsSystem.Heart> heartList = healthHeartsSystem.GetHeartList();
            for (int i = 0; i < heartList.Count; i++)
            {
                HeartImage heartImage          = heartImageList[i];
                HealthHeartsSystem.Heart heart = heartList[i];

                if (heartImage.GetFragmentAmount() != heart.GetFragmentAmount())
                {
                    //Comprobar si el resultado visual es diferente de la lógica
                    heartImage.AddHeartVisualFragment();
                    if (heartImage.GetFragmentAmount() == HealthHeartsSystem.MAX_FRAGMENT_AMOUNT)
                    {
                        //Este corazón estaba completamente curado
                        heartImage.PlayHeartFullAnimation();
                    }
                    fullyHealed = false;
                    break;
                }
            }

            if (fullyHealed)
            {
                isHealing = false;
            }
        }
    }
Ejemplo n.º 6
0
    private void HealingAnimatedPeriodic()
    {
        if (!isHealing)
        {
            return;
        }
        bool fullyHealed = true;

        for (int i = 0; i < heartImageList.Count; i++)
        {
            HeartImage heartImage          = heartImageList[i];
            HeartsHealthSystem.Heart heart = heartsHealthSystem.GetHeartList()[i];
            if (Math.Round(heartImage.GetValue(), 3) != heart.GetValue())
            {
                heartImage.AddHeartVisualValue();
                if (Math.Round(heartImage.GetValue(), 2) == HeartsHealthSystem.MAX_HEARTH_VALUE)
                {
                    heartImage.PlayHeartFullAnimation();
                }
                fullyHealed = false;
                break;
            }
        }
        if (fullyHealed)
        {
            isHealing = false;
        }
    }
    private HeartImage CreateHeartImage(Vector2 anchoredPosition)
    {
        // Create Game Object
        GameObject heartGameObject = new GameObject("Heart", typeof(Image), typeof(Animation));

        // Set as child of this transform
        heartGameObject.transform.parent        = transform;
        heartGameObject.transform.localPosition = Vector3.zero;
        heartGameObject.transform.localScale    = Vector3.one;

        // Locate and Size heart
        heartGameObject.GetComponent <RectTransform>().anchoredPosition = anchoredPosition;
        heartGameObject.GetComponent <RectTransform>().sizeDelta        = new Vector2(35, 35);

        heartGameObject.GetComponent <Animation>().AddClip(heartFullAnimationClip, "HeartFull");

        // Set heart sprite
        Image heartImageUI = heartGameObject.GetComponent <Image>();

        heartImageUI.sprite = heart4Sprite;

        HeartImage heartImage = new HeartImage(this, heartImageUI, heartGameObject.GetComponent <Animation>());

        heartImageList.Add(heartImage);

        return(heartImage);
    }
Ejemplo n.º 8
0
    public void UpdateHeartContainersFillState(int numHalfHearts)
    {
        numHalfHearts = Mathf.Clamp(numHalfHearts, 0, _numHeartContainers * 2);

        int  numFullHearts = (int)(numHalfHearts * 0.5f);
        bool plusHalfHeart = numHalfHearts % 2 == 1;

        for (int i = 0; i < _heartImages.Length; i++)
        {
            HeartImage heartImage = _heartImages[i].GetComponent <HeartImage>();

            if (i < numFullHearts)
            {
                heartImage.SetToFull();
            }
            else if (i == numFullHearts && plusHalfHeart)
            {
                heartImage.SetToHalfFull();
            }
            else
            {
                heartImage.SetToEmpty();
            }
        }
    }
    private HeartImage CreateHeartImage(Vector2 anchoredPosition)
    {
        GameObject heartGameObject = new GameObject("Heart", typeof(Image), typeof(Animation));

        //heartGameObject.transform.parent = transform;
        heartGameObject.transform.SetParent(transform, false);
        heartGameObject.GetComponent <Image>().sprite = fullHeartSprite;
        heartGameObject.transform.localPosition       = Vector3.zero;

        // Set as child of this transform
        heartGameObject.GetComponent <RectTransform>().anchoredPosition = anchoredPosition;
        heartGameObject.GetComponent <RectTransform>().sizeDelta        = new Vector2(50, 50);

        heartGameObject.GetComponent <Animation>().AddClip(heartFullAnimationClip, "HeartFull");

        // Locate and size heart
        Image heartImageUI = heartGameObject.GetComponent <Image>();

        heartImageUI.sprite = fullHeartSprite;
        HeartImage heartImage = new HeartImage(this, heartImageUI, heartGameObject.GetComponent <Animation>());

        heartImageList.Add(heartImage);

        return(heartImage);
    }
Ejemplo n.º 10
0
 public void RefreshAllHearts(object sender, EventArgs e)
 {
     for (int i = 0; i < heartImageList.Count; i++)
     {
         HeartImage heartImage          = heartImageList[i];
         HeartsHealthSystem.Heart heart = heartsHealthSystem.GetHeartList()[i];
         heartImage.SetHeartValue(heart.GetValue());
     }
 }
Ejemplo n.º 11
0
    private HeartImage CreateHeart(Vector2 anchoredPosition)
    {
        GameObject heartGameObject = new GameObject("heart", typeof(Image));
        Image      heartImageUI    = heartGameObject.GetComponent <Image>();
        HeartImage heartImage      = new HeartImage(this, heartImageUI);

        HeartPositionAndSize(heartGameObject, anchoredPosition);
        heartImageList.Add(heartImage);
        return(heartImage);
    }
    public void RefreshAllHearts()
    {
        List <PlayerHeartSystem.Heart> heartList = heartSystem.GetHeartList();

        for (int i = 0; i < heartImageList.Count; i++)
        {
            HeartImage heartImage         = heartImageList[i];
            PlayerHeartSystem.Heart heart = heartList[i];
            heartImage.SetHeartLevel(heart.GetHeartLevel());
        }
    }
Ejemplo n.º 13
0
    private void RefreshHearts()
    {
        List <HeartHealthSystem.Heart> heartList = healthSystem.getHeartList();

        for (int i = 0; i < heartImagelist.Count; i++)
        {
            HeartImage image = heartImagelist[i];
            HeartHealthSystem.Heart heart = heartList[i];
            image.setHeartFragment(healthSystem.getHeartList()[i].GetFragments());
        }
    }
Ejemplo n.º 14
0
    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.º 15
0
    private void RefreshAllHearts()                                        ///// make the health can be decrease
                                                                           /// if delete this it will always be full health
    {
        List <healthSystem.Heart> heartList = HealthSystem.GetHeartList(); //a

        for (int i = 0; i < heartImageList.Count; i++)
        {
            HeartImage         heartImage = heartImageList[i];
            healthSystem.Heart heart      = heartList[i];
            heartImage.SetHeartFraments(heart.GetFragmentAmount());
        }
    }
Ejemplo n.º 16
0
    private void refreshAllHearts()
    {
        // get a lisst of all hearts
        List <HeartsHealthSystem.Heart> hearts = heartHealthSystem.getHeartsList();

        for (int i = 0; i < heartImageList.Count; i++)
        {
            HeartImage img = heartImageList[i];
            HeartsHealthSystem.Heart heart = hearts[i];              // update heart
            img.SetHeartFragments(heart.GetCurrentFragmentAmount()); // reset fragment
        }
    }
Ejemplo n.º 17
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());
        }
    }
Ejemplo n.º 18
0
    private void RefreshAllHearts()
    {
        List <HeartLogic.Heart> heartList = HSystem.getHeartList();

        for (int i = 0; i < heartsImageList.Count; i++)
        {
            HeartImage       hImage = heartsImageList[i];
            HeartLogic.Heart heart  = heartList[i];
            hImage.setHeartFragment(heart.getFragmentAmount());
        }
        float alpha = 1f / total * (total - GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth>().getCurrentHealth());

        GameObject.FindGameObjectWithTag("Mask").GetComponent <Image>().color = new Color(1, 1, 1, alpha);
    }
Ejemplo n.º 19
0
    private void RefreshHearts(object sender, System.EventArgs e)
    {
        for (int i = 0; i < heartImageList.Count; i++)
        {
            HeartImage heartImage          = heartImageList[i];
            HeartsHealthSystem.Heart heart = heartsHealthSystem.GetHeartList()[i];
            heartImage.SetValue(heart.GetValue());
        }

        if (heartsHealthSystem.HeartEmpty() == true)
        {
            _player.IsDead();
        }
    }
Ejemplo n.º 20
0
    public void SetHeartsHealthSystem(HeartsHealthSystem heartsHealthSystem)
    {
        List <HeartsHealthSystem.Heart> heartList = heartsHealthSystem.GetHeartList();
        int heartOffset = 42;

        this.heartsHealthSystem  = heartsHealthSystem;
        heartsHealthSystemStatic = heartsHealthSystem;
        for (int i = 0; i < heartList.Count; i++)
        {
            HeartImage newHeart = CreateHeart(new Vector2(i * heartOffset, 0));
            newHeart.SetValue(heartList[i].GetValue());
        }

        heartsHealthSystem.OnDamaged += RefreshHearts;
        heartsHealthSystem.OnHealed  += RefreshHearts;
    }
Ejemplo n.º 21
0
    private HeartImage CreateHeartImage(Vector2 anchoredPosition)
    {
        GameObject heartGameObject = Instantiate(heartObject);

        heartGameObject.transform.parent        = transform;
        heartGameObject.transform.localPosition = Vector3.zero;
        heartGameObject.transform.localScale    = Vector3.one;
        heartGameObject.AddComponent <Animation>();
        heartGameObject.GetComponent <Animation>().AddClip(heartFullAnimationClip, "HeartFull");
        heartGameObject.GetComponent <RectTransform>().anchoredPosition = anchoredPosition;
        heartGameObject.GetComponent <RectTransform>().sizeDelta        = new Vector2(1, 1);
        HeartImage heartImage = new HeartImage(heartGameObject, heartGameObject.GetComponent <Animation>());

        heartImageList.Add(heartImage);

        return(heartImage);
    }
Ejemplo n.º 22
0
    private HeartImage CreateHeartImage(Vector2 anchoredPostion)
    {
        GameObject heartGameObject = new GameObject("Heart", typeof(Image));

        heartGameObject.transform.SetParent(transform, false);
        heartGameObject.transform.localPosition = Vector3.zero;
        heartGameObject.GetComponent <RectTransform>().anchoredPosition = anchoredPostion;
        heartGameObject.GetComponent <RectTransform>().sizeDelta        = new Vector2(100, 100);
        var heartImage = heartGameObject.GetComponent <Image>();

        heartImage.sprite = heartSprite_full;

        var imageObj = new HeartImage(this, heartImage);

        heartImageList.Add(imageObj);
        return(imageObj);
    }
Ejemplo n.º 23
0
    private void Start()
    {
        GameObject thePlayer    = GameObject.Find("PlayerCollider");
        PlayerHP   playerScript = thePlayer.GetComponent <PlayerHP>();

        numberOfHearts = playerScript.health;
        HeartImage image1  = createHeartImage(new Vector2(0, 0));
        HeartImage image2  = createHeartImage(new Vector2(50, 0));
        HeartImage image3  = createHeartImage(new Vector2(100, 0));
        HeartImage image4  = createHeartImage(new Vector2(150, 0));
        HeartImage image5  = createHeartImage(new Vector2(200, 0));
        HeartImage image6  = createHeartImage(new Vector2(0, -50));
        HeartImage image7  = createHeartImage(new Vector2(50, -50));
        HeartImage image8  = createHeartImage(new Vector2(100, -50));
        HeartImage image9  = createHeartImage(new Vector2(150, -50));
        HeartImage image10 = createHeartImage(new Vector2(200, -50));
    }
Ejemplo n.º 24
0
    private HeartImage createHeartImage(Vector2 anchorPosit)
    {
        GameObject go = new GameObject("Heart", typeof(Image));

        go.transform.parent        = transform;
        go.transform.localPosition = Vector3.zero;

        go.transform.GetComponent <RectTransform>().anchoredPosition = anchorPosit;
        go.transform.GetComponent <RectTransform>().sizeDelta        = new Vector2(25, 25);

        Image heartImageUI = go.GetComponent <Image>();

        heartImageUI.sprite = heartSprite;
        HeartImage heartImage = new HeartImage(h, heartImageUI);

        hiList.Add(heartImage);
        return(heartImage);
    }
Ejemplo n.º 25
0
    private HeartImage CreateHeart(Vector2 anchoredPos)
    {
        GameObject heartGO = new GameObject("Heart", typeof(Image));

        heartGO.transform.localScale = new Vector3(1, 1f, 1);
        heartGO.transform.SetParent(transform);
        heartGO.transform.localPosition = Vector3.zero;
        heartGO.GetComponent <RectTransform>().anchoredPosition = anchoredPos;
        heartGO.GetComponent <RectTransform>().sizeDelta        = new Vector2(50f, 50f);

        Image heartImageUI = heartGO.transform.GetComponent <Image>();

        heartImageUI.sprite = heartSprite4;

        HeartImage heartImage = new HeartImage(this, heartImageUI);

        heartImagelist.Add(heartImage);
        return(heartImage);
    }
    private HeartImage CreateHeartImage()
    {
        GameObject heartObject = new GameObject("heart", typeof(Image));

        heartObject.transform.SetParent(heartContainer);

        heartObject.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
        heartObject.GetComponent <RectTransform>().sizeDelta  = new Vector2(70, 60);
        heartObject.transform.SetParent(heartContainer);

        Image heartImageUI = heartObject.GetComponent <Image>();

        heartImageUI.sprite = heartFull;

        HeartImage heartImage = new HeartImage(this, heartImageUI);

        heartImageList.Add(heartImage);

        return(heartImage);
    }
Ejemplo n.º 27
0
    private HeartImage CreateHeartImage(Vector2 anchor)
    {
        GameObject heartObject = new GameObject("Heart", typeof(Image));

        heartObject.transform.SetParent(transform);
        heartObject.transform.localPosition = Vector3.zero;

        heartObject.GetComponent <RectTransform>().anchoredPosition = anchor;
        heartObject.GetComponent <RectTransform>().sizeDelta        = new Vector2(30, 30);

        Image heartImageUI = heartObject.GetComponent <Image>();

        heartImageUI.sprite = heartSprites[0];


        HeartImage heartImage = new HeartImage(this, heartImageUI);

        heartsImageList.Add(heartImage);
        return(heartImage);
    }
Ejemplo n.º 28
0
    private HeartImage CreateHeartImage(Vector2 anchoredPosition)
    {
        GameObject heartGameObject = new GameObject("Heart", typeof(Image));

        heartGameObject.transform.parent = transform;
        heartGameObject.GetComponent <Image>().sprite = heartFull;
        heartGameObject.transform.localPosition       = Vector3.zero;

        heartGameObject.GetComponent <RectTransform>().anchoredPosition = anchoredPosition;
        heartGameObject.GetComponent <RectTransform>().sizeDelta        = new Vector2(50, 50);

        Image heartImageUI = heartGameObject.GetComponent <Image>();

        heartImageUI.sprite = heartFull;

        HeartImage heartImage = new HeartImage(this, heartImageUI);

        heartImageList.Add(heartImage);
        return(heartImage);
    }
Ejemplo n.º 29
0
    private HeartImage CreateHeartImage(Vector2 anchoredPosition) ////// create the heart on the screen
    {
        GameObject hgo = new GameObject("Heart", typeof(Image));  // heartGameObject

        hgo.transform.SetParent(gameObject.transform);            // Set as child of this transform
        hgo.transform.localPosition = Vector3.zero;
        hgo.transform.localScale    = Vector3.one;

        hgo.GetComponent <RectTransform>().anchoredPosition = anchoredPosition;  // Locate and Size heart
        hgo.GetComponent <RectTransform>().sizeDelta        = new Vector2(32, 32);

        Image heartImageUI = hgo.GetComponent <Image>();   // Set heart sprite

        heartImageUI.sprite = heart2Sprite;

        HeartImage heartImage = new HeartImage(this, heartImageUI);   // heartGameObject.GetComponent<Animation>()

        heartImageList.Add(heartImage);

        return(heartImage);
    }
Ejemplo n.º 30
0
    Image CreateHeartImage(Vector2 anchoredPosition)
    {
        GameObject heartGameObject = new GameObject("Heart", typeof(Image));

        heartGameObject.transform.SetParent(transform);
        heartGameObject.transform.localPosition = Vector3.zero;

        heartGameObject.GetComponent <RectTransform>().anchoredPosition = anchoredPosition;
        heartGameObject.GetComponent <RectTransform>().sizeDelta        = heartSize;

        Image heartImageUI = heartGameObject.GetComponent <Image>();

        HeartImage heart = new HeartImage(heartImageUI);

        heart.SetHeart(true);
        hearts.Add(heart);
        heart.full  = heartFull;
        heart.empty = heartEmpty;

        return(heartImageUI);
    }