Ejemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!isInited)
        {
            Debug.LogError("OnTriggerEnter2D shouldn be called before init");
            return;
        }

        //Debug.Log("OnTriggerEnter2D " + collision.gameObject.name);

        ICollisionHandler handler =
            collision.gameObject.GetComponent <ICollisionHandler>();


        bool result = false;

        if (handler != null)
        {
            result = handler.OnCollision(
                config.Damage, Owner, gameObject, Direction.normalized * config.PushForce);
        }
        if (result)
        {
            ReturnToPool();
        }
        //Photon.Destroy();
        //ReturnToPool();
    }
Ejemplo n.º 2
0
    private void ApplyExplosion()
    {
        //Debug.Log("ApplyExplosion");
        circleCollider2D.enabled = true;
        List <Collider2D> hitResult = new List <Collider2D>();

        circleCollider2D.OverlapCollider(new ContactFilter2D(), hitResult);
        foreach (var hit in hitResult)
        {
            ICollisionHandler handler = hit.GetComponent <ICollisionHandler>();
            if (handler != null)
            {
                Vector3 push = (hit.transform.position - transform.position).normalized * explosionPushForce;
                handler.OnCollision(30, null, gameObject, push);
            }
            //Debug.Log(hit.gameObject.name);
        }
    }
Ejemplo n.º 3
0
    //private void OnTriggerEnter2D(Collider2D collision)
    //private void OnCollisionEnter2D(Collision2D collision)
    private void OnCollisionStay2D(Collision2D collision)
    {
        //Debug.Log("OnCollisionEnter2D " + collision.gameObject.name);

        ICollisionHandler handler = collision.gameObject.GetComponent <ICollisionHandler>();

        if (handler == null)
        {
            return;
        }

        float lastCollisionTime;

        if (collisionTimes.TryGetValue(handler, out lastCollisionTime) &&
            lastCollisionTime > Time.time - MIN_COLLISION_DELAY)
        {
            //Debug.Log("Collision too soon");
            return;
        }

        if (collision.gameObject == owner.gameObject)
        {
            //Debug.Log("thats me ");
            return;
        }

        SoundController.PlaySound(ESound.Davinci_Tank_Hit, audioSource);
        Vector2 push = GetPush(collision.transform);

        Debug.Log($"Hit {collision.gameObject.name}. {push}");
        handler.OnCollision(damage, owner, gameObject, push);

        if (collisionTimes.ContainsKey(handler))
        {
            collisionTimes[handler] = Time.time;
        }
        else
        {
            collisionTimes.Add(handler, Time.time);
        }
    }
Ejemplo n.º 4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        ICollisionHandler handler = collision.GetComponent <ICollisionHandler>();

        if (handler == null)
        {
            return;
        }

        if (collision.gameObject == owner.gameObject)
        {
            //Debug.Log("thats me ");
            return;
        }

        float dist   = Vector2.Distance(transform.position, collision.transform.position);
        float factor = circleCollider2D.radius - dist;

        float damage = Mathf.Lerp(bomb.MaxDamage / 10f, bomb.MaxDamage, factor);

        //Debug.Log("OnTriggerEnter2D " + collision.gameObject.name);
        Vector3 push = (collision.transform.position - transform.position).normalized * bomb.PushForce;

        Debug.Log("TODO: calculate push force");
        handler.OnCollision((int)damage, owner, gameObject, push);

        SpriteRenderer sr = collision.GetComponent <SpriteRenderer>();

        if (sr)
        {
            int orderAbove = sr.sortingOrder + 5;
            //multiple players can be hit - use the topmost order
            if (spriteRend.sortingOrder < orderAbove)
            {
                Debug.Log($"Set order {orderAbove}");
                spriteRend.sortingOrder = orderAbove;
            }
        }
    }
Ejemplo n.º 5
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!owner.IsItMe)
        {
            Debug.LogError("Mine shouldnt be triggered on its owner image side");
            return;
        }

        if (isExploded || !isInited)
        {
            return;
        }

        ICollisionHandler handler = collision.GetComponent <ICollisionHandler>();

        if (handler == null)
        {
            return;
        }

        Player player = collision.GetComponent <Player>();

        if (player == null)
        {
            //Debug.Log("Not player");
            return;
        }
        if (player.Equals(owner))
        {
            //Debug.Log("thats me ");
            return;
        }

        int finalDamage = owner.InitInfo.Hero == EHero.Nobel ? damage * 2 : damage;

        handler.OnCollision(finalDamage, owner, gameObject, GetPush(player.transform));
        Explode();
    }
Ejemplo n.º 6
0
    public void Collide()
    {
        animator.SetBool(AC_KEY_IS_DEAD, true);

        //Debug.Log("BOOM " + collision.gameObject.name);
        LeanTween.cancel(gameObject);
        rigidBody2D.bodyType = RigidbodyType2D.Static;

        audioSource.Stop();
        SoundController.PlaySound(ESound.Curie_Truck_Explode, audioSource, false);

        Collider2D[] collisions = Physics2D.OverlapCircleAll(transform.position, radius);

        ICollisionHandler ownerHandler = owner.GetComponent <ICollisionHandler>();

        foreach (var c in collisions)
        {
            ICollisionHandler handler = c.GetComponent <ICollisionHandler>();
            if (handler == null)
            {
                continue;
            }

            if (handler == ownerHandler)
            {
                Debug.Log("SpecialCurieTruck Collision with myself " + handler);
                continue;
            }

            handler.OnCollision(damage, owner, gameObject, GetPush(c.transform));
            Debug.Log("SpecialCurieTruck Collision with " + handler);
        }

        Photon.Send(EPhotonMsg.Special_Curie_Collide);
        canCollide = false;
    }