Esempio n. 1
0
    IEnumerator ExplodeCoroutine(bool doubleRadius = false)
    {
        inExplodeCoroutine = true;

        if (GameManager.S.inGame)
        {
            SoundManager.instance.Play("BombExplode");
            SoundManager.instance.Play("Explosion");
        }
        hasExploded    = true;
        hitbox.enabled = false;
        GetComponent <SpriteRenderer>().enabled = false;
        GetComponentInChildren <ParticleSystem>().Play();
        Destroy(gameObject, 2.5f);

        Collider[]    allObjectsHit    = Physics.OverlapSphere(transform.position, (doubleRadius ? 2 : 1) * explosionRadius);
        ProximityMine nearestOtherMine = null;

        foreach (var obj in allObjectsHit)
        {
            //If any players are within the blast zone
            if (obj.gameObject.tag == "Player")
            {
                //Ignore the mine's owner
                Ship shipHit = obj.gameObject.GetComponentInParent <Ship>();
                if (shipHit.playerEnum == owningPlayer)
                {
                    continue;
                }
                //Deal damage to any other player
                else
                {
                    shipHit.TakeDamage(flatDamage);
                }
            }
            //Deal damage to any protag ship caught in the explosion
            else if (obj.gameObject.tag == "ProtagShip")
            {
                ProtagShip shipHit = obj.gameObject.GetComponentInParent <ProtagShip>();
                shipHit.TakeDamage(flatDamage);
            }
            //Blow up any other nearby proximity mines, with twice the radius (more mines == bigger explosion)
            else if (obj.gameObject.tag == "ProximityMine")
            {
                if (nearestOtherMine == null)
                {
                    nearestOtherMine = obj.gameObject.GetComponent <ProximityMine>();
                }
            }
        }

        if (nearestOtherMine != null)
        {
            yield return(new WaitForSeconds(otherMineDetonationDelay));

            nearestOtherMine.Explode(true);
        }

        inExplodeCoroutine = false;
    }
Esempio n. 2
0
    IEnumerator DealDamageCoroutine(ProtagShip hitShip)
    {
        float distance = (hitShip.transform.position - transform.position).magnitude;

        yield return(new WaitForSeconds(distance / shotSpeed));

        hitShip.TakeDamage(damage);
    }
Esempio n. 3
0
    void OnTriggerStay(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            Ship otherShip = other.GetComponentInParent <Ship>();
            if (otherShip.playerEnum != blackHole.owningPlayer)
            {
                //Do damage to the player hit
                otherShip.TakeDamage(blackHole.directDamageInCenter);

                GameObject explosion = Instantiate(explosionPrefab, other.transform.position, new Quaternion()) as GameObject;
                Destroy(explosion, 5f);
            }
        }
        else if (other.gameObject.tag == "ProtagShip")
        {
            ProtagShip protagShip = other.GetComponentInParent <ProtagShip>();
            protagShip.TakeDamage(blackHole.directDamageInCenter);

            GameObject explosion = Instantiate(explosionPrefab, other.transform.position, new Quaternion()) as GameObject;
            Destroy(explosion, 5f);
        }
        else if (other.gameObject.tag == "Bullet")
        {
            Bullet bullet = other.gameObject.GetComponent <Bullet>();
            //Don't interact if the bullet has already interacted with something
            if (bullet.curState != BulletState.absorbedByBlackHole)
            {
                return;
            }

            if (bullet.gameObject.layer == LayerMask.NameToLayer("TrappedBullet"))
            {
                bullet.physics.acceleration = (transform.position - other.transform.position).normalized * blackHole.gravityForce;
            }
        }
    }
Esempio n. 4
0
    void Explode(float explosionDamage, float explosionRadius)
    {
        if (GameManager.S.inGame)
        {
            SoundManager.instance.Play("Explosion");
        }
        Collider[] allObjectsHit = Physics.OverlapSphere(transform.position, explosionRadius);
        foreach (var obj in allObjectsHit)
        {
            if (obj.gameObject.tag == "Player")
            {
                Ship shipHit = obj.gameObject.GetComponentInParent <Ship>();
                if (shipHit.playerEnum == owningPlayer)
                {
                    return;
                }
                else
                {
                    shipHit.TakeDamage(CalculateDamageDealt(obj.transform, explosionDamage, explosionRadius));
                }
            }
            else if (obj.gameObject.tag == "ProtagShip")
            {
                ProtagShip shipHit = obj.gameObject.GetComponentInParent <ProtagShip>();
                shipHit.TakeDamage(CalculateDamageDealt(obj.transform, explosionDamage, explosionRadius));
            }
        }

        int numMinesSpawned = Random.Range(minNumBombs, maxNumBombs);

        for (int i = 0; i < numMinesSpawned; i++)
        {
            ProximityMine newMine = Instantiate(minePrefab, transform.position, new Quaternion()) as ProximityMine;
            newMine.owningPlayer = owningPlayer;
        }
    }