Ejemplo n.º 1
0
    public float TakeDamage(float dmg)
    {
        Sounds sounds = GetComponent <Sounds>();

        if (sounds != null)
        {
            sounds.play(gameObject, sounds.gotHit);
        }

        if (eq != null)
        {
            float totalArmor = armorValue;
            Item  armor      = eq.GetArmor();
            if (armor != null)
            {
                totalArmor += armor.armorValue;
            }
            foreach (GameObject tmp in this.activeBuffs)
            {
                Item tempBuff = tmp.GetComponent <Item>();
                totalArmor += tempBuff.armorValue;
            }

            dmg = Mathf.Max(0, dmg - totalArmor * dmg);

            Item shield = eq.GetShield();
            if (shield != null)
            {
                if (shieldActive)
                {
                    float shieldedDmg = Mathf.Min(shield.shieldHp, shield.shieldProtection * dmg);
                    dmg             = Mathf.Max(0, dmg - shieldedDmg);
                    shield.shieldHp = Mathf.Max(0, shield.shieldHp - shieldedDmg);
                    if (shield.shieldHp == 0)
                    {
                        shieldActive = false;
                        eq.RemoveItem(shield);
                    }
                }
            }
        }

        if (dmg > 0)
        {
            GameObject blood = Instantiate(Resources.Load("SmallBloodSplash")) as GameObject;
            blood.transform.localPosition = transform.localPosition;
            blood.transform.localRotation = transform.localRotation;
            Destroy(blood, 1);
        }

        float overkill = dmg - hp;

        hp -= dmg;
        if (hp <= 0)
        {
            Sounds _sounds = GetComponent <Sounds>();
            if (_sounds != null)
            {
                _sounds.dieSound(gameObject);
            }
            gameObject.SendMessage("LetMeDie");
        }
        return(overkill);
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (sc && critter)
        {
            //change backpack
            if (MoonzInput.GetKeyDown(MoonzInput.ARROW_UP, inputSuffix))
            {
                GetComponent <Eq>().ChangeSlot(Item.SLOT_UP);
            }

            if (MoonzInput.GetKeyDown(MoonzInput.ARROW_DOWN, inputSuffix))
            {
                GetComponent <Eq>().ChangeSlot(Item.SLOT_DOWN);
            }

            if (MoonzInput.GetKeyDown(MoonzInput.ARROW_LEFT, inputSuffix))
            {
                GetComponent <Eq>().ChangeSlot(Item.SLOT_LEFT);
            }

            if (MoonzInput.GetKeyDown(MoonzInput.ARROW_RIGHT, inputSuffix))
            {
                GetComponent <Eq>().ChangeSlot(Item.SLOT_RIGHT);
            }

            if (MoonzInput.GetKeyDown(MoonzInput.B, inputSuffix) && eq.GetShield() != null)
            {
                critter.shieldActive = !critter.shieldActive;
            }
            bubble.SetActive(critter.shieldActive && eq.GetShield() != null);

            if (MoonzInput.GetKeyDown(MoonzInput.A, inputSuffix))
            {
                if (eq.downSlot != null)
                {
                    critter.UseBuff(eq.downSlot);
                    eq.RemoveItem(eq.downSlot.GetComponent <Item>());
                }
            }

            float h = MoonzInput.GetAxis("H", inputSuffix);
            float v = MoonzInput.GetAxis("V", inputSuffix);

            float angle;
            if (Mathf.Abs(h) + Mathf.Abs(v) > 0.5f)
            {
                GetComponent <Animator>().SetInteger("animId", 0);
                angle       = Mathf.Atan2(h, v);
                sp.rotation = Quaternion.Euler(0, angle * 180 / Mathf.PI, 0);
            }
            else
            {
                GetComponent <Animator>().SetInteger("animId", 1);
            }

            sc.MoveForward(v * critter.getSpeed() * Time.deltaTime);
            sc.MoveSide(h * critter.getSpeed() * Time.deltaTime);

            float fh = MoonzInput.GetAxis("FH", inputSuffix);
            float fv = MoonzInput.GetAxis("FV", inputSuffix);
            angle = Mathf.Atan2(fh, fv);

            if (Mathf.Abs(fh) + Mathf.Abs(fv) > 0.5)
            {
                Vector3 shootDirection = Camera.main.transform.up * fv + Camera.main.transform.right * fh;
                critter.Attack(sc.position + shootDirection);
                sp.rotation = Quaternion.Euler(0, angle * 180 / Mathf.PI, 0);
            }

            if (MoonzInput.GetKeyDown(MoonzInput.RB, inputSuffix) || MoonzInput.GetKeyDown(MoonzInput.X, inputSuffix))
            {
                PickDropIfAny();
            }
        }
    }