private void OnCollisionEnter2D(Collision2D collision)
    {
        StickmanElement other = null;

        if (collision.gameObject.CompareTag("Player"))
        {
            other = collision.gameObject.GetComponent <StickmanPart>();
        }
        else if (collision.gameObject.CompareTag("Weapon"))
        {
            other = collision.gameObject.GetComponent <StickmanWeapon>();
        }

        if (!_inSuperArmer && ((((other != null) && (other.Stickman != this.Stickman)))) && (this._rigidbody.velocity.sqrMagnitude > other.Rigidbody.velocity.sqrMagnitude))
        {
            Vector2 hitPoint = collision.contacts[0].point;
            Vector2 vector4  = this._rigidbody.position - hitPoint;
            this.StartForce(1000f * vector4.normalized, hitPoint, 0.2f);

            Vector2 vector5 = other.Rigidbody.position - hitPoint;
            other.StartForce(1000f * vector5.normalized, hitPoint, 0.2f);


            ArrayList args = new ArrayList {
                hitPoint, this, other
            };
            EventDispatcher.Instance.DispatchImmediately(EventName.EVENT_ON_COLLISION, args);
            StartCoroutine(SuperArmerCoroutine());
        }
    }
Exemple #2
0
    private void OnEventCollision(string eid, ArrayList args)
    {
        Vector2         hitPoint = (Vector2)args[0];
        StickmanElement s1       = (StickmanElement)args[1];
        StickmanElement s2       = (StickmanElement)args[2];

        DamageCalculation(s1, s2);
    }
Exemple #3
0
    private void DamageCalculation(StickmanElement s1, StickmanElement s2)
    {
        float damage1 = 0f;
        float damage2 = 0f;

        switch (s1.Type)
        {
        case StickmanElement.StickmanElementType.BODY:
            damage1 = s2.Attack - s1.Defence * (s2.Type == StickmanElement.StickmanElementType.BODY? 1f: 0f);
            damage1 = Mathf.Max(0f, damage1);
            s1.Hp  -= damage1;
            break;

        case StickmanElement.StickmanElementType.EQUIPMENT:
            damage1 = s2.Attack - s1.Defence * (s2.Type == StickmanElement.StickmanElementType.WEAPON ? 0f : 1f);
            damage1 = Mathf.Max(0f, damage1);
            s1.Hp  -= damage1;
            break;

        case StickmanElement.StickmanElementType.WEAPON:
            break;
        }


        switch (s2.Type)
        {
        case StickmanElement.StickmanElementType.BODY:
            damage2 = s1.Attack - s2.Defence * (s1.Type == StickmanElement.StickmanElementType.BODY ? 1f : 0f);
            damage2 = Mathf.Max(0f, damage2);
            s2.Hp  -= damage2;
            break;

        case StickmanElement.StickmanElementType.EQUIPMENT:
            damage2 = s1.Attack - s2.Defence * (s1.Type == StickmanElement.StickmanElementType.WEAPON ? 0f : 1f);
            damage2 = Mathf.Max(0f, damage2);
            s2.Hp  -= damage2;
            break;

        case StickmanElement.StickmanElementType.WEAPON:
            break;
        }

        string msg = string.Format("{0} {1} hurt {2},  {3} {4} hurt {5}", s1.Stickman.gameObject.name, s1.gameObject.name, damage1.ToString(), s2.Stickman.gameObject.name, s2.gameObject.name, damage2.ToString());

        Debugger.Log(msg);
    }