예제 #1
0
    //
    AffectedByPulseAttack GetElementsOnReachOfPulseAttack(float pulseReach, float pulseRadius)
    {
        //
        AffectedByPulseAttack affectedByPulseAttack = new AffectedByPulseAttack();

        //
        Collider[] collidersOnReach = Physics.OverlapSphere(transform.position, pulseReach);
        //
        for (int i = 0; i < collidersOnReach.Length; i++)
        {
            //Si no entra en el ángulo, siguiente
            Vector3 pointFromPlayer = collidersOnReach[i].transform.position - transform.position;
            if (Vector3.Angle(pointFromPlayer, transform.forward) > pulseRadius)
            {
                continue;
            }

            // Chequemamos primero por enemy colliders
            EnemyCollider enemyCollider = collidersOnReach[i].GetComponent <EnemyCollider>();
            if (enemyCollider != null)
            {
                affectedByPulseAttack.affectedEnemyColliders.Add(enemyCollider);
            }
            // Después enemy consistencies
            EnemyConsistency enemyConsistency = collidersOnReach[i].GetComponent <EnemyConsistency>();
            if (enemyConsistency == null)
            {
                enemyConsistency = collidersOnReach[i].GetComponentInParent <EnemyConsistency>();
            }
            if (enemyConsistency != null)
            {
                affectedByPulseAttack.affectedEnemyConsistencies.Add(enemyConsistency);
            }
            //
            WeakPoint weakPoint = collidersOnReach[i].GetComponent <WeakPoint>();
            if (weakPoint != null)
            {
                Debug.Log("Adding weakpoint");
                affectedByPulseAttack.affectedWeakPoints.Add(weakPoint);
            }
            // Terrenos destruibles
            DestructibleTerrain destructibleTerrain = collidersOnReach[i].GetComponent <DestructibleTerrain>();
            if (destructibleTerrain == null)
            {
                destructibleTerrain = collidersOnReach[i].GetComponentInParent <DestructibleTerrain>();
            }
            if (destructibleTerrain != null)
            {
                affectedByPulseAttack.affectedDestructibleTerrains.Add(destructibleTerrain);
            }
            // Y por último rigidbodies
            // Estos solo deberían entrar en la lista si no ha cuajado arriba
            Rigidbody rigidbody = collidersOnReach[i].GetComponent <Rigidbody>();
            if (rigidbody != null && enemyConsistency == null)
            {
                affectedByPulseAttack.affectedRigidbodies.Add(rigidbody);
            }
        }
        return(affectedByPulseAttack);
    }
예제 #2
0
    void DestroyTile(Collider2D collider, DestructibleTerrain dt)
    {
        Debug.Log("DestroyTile -- " + dt.gameObject.name);

        Tilemap tilemap = dt.GetComponentInParent <Tilemap>();

        Vector3Int tilePos = tilemap.WorldToCell(collider.gameObject.transform.position);

        Debug.Log(tilePos);
        Debug.Log(tilemap.GetTile(tilePos));

        tilemap.SetTile(tilePos, null);
    }
예제 #3
0
파일: FallingRock.cs 프로젝트: quill18/LD45
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Health h = collision.gameObject.GetComponentInParent <Health>();

        DoDamage(h);

        DestructibleTerrain dt = collision.gameObject.GetComponentInParent <DestructibleTerrain>();

        DestroyTerrain(dt, collision);

        Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);

        Destroy(gameObject);
    }
예제 #4
0
    IEnumerator WallDestruction()
    {
        Vector2 pos            = transform.position;
        Vector2 dir            = rb2d.velocity.x < 0 ? Vector2.left : Vector2.right;
        float   WallDestHeight = GetComponentInChildren <Collider2D>().bounds.size.y;
        float   WallDestDist   = 1;

        bool tryAgain = false;

        do
        {
            tryAgain = false;

            RaycastHit2D[] hits = Physics2D.BoxCastAll(pos, new Vector2(1.0f, WallDestHeight), 0, dir, WallDestDist);
            //Debug.Log("LENGTH: " + hits.Length);

            foreach (RaycastHit2D hit in hits)
            {
                //Debug.Log("HIT: " + hit.collider.name);

                DestructibleTerrain dt = hit.collider.GetComponentInParent <DestructibleTerrain>();
                if (dt == null)
                {
                    continue;
                }

                Tilemap tilemap = dt.GetComponentInParent <Tilemap>();

                Vector3Int tilePos = tilemap.WorldToCell(hit.point);
                if (tilemap.GetTile(tilePos) != null)
                {
                    tilemap.SetTile(tilePos, null);

                    if (dt.DebrisPrefab != null)
                    {
                        Instantiate(dt.DebrisPrefab, hit.point, Quaternion.identity);
                    }

                    // Because terrain is a single collider, we need to
                    // repeat the cast to see if any other tiles would be hit.
                    tryAgain = true;
                    yield return(null); // wait a frame
                }
            }
        } while (tryAgain);
    }
예제 #5
0
    private void OnTriggerStay2D(Collider2D collider)
    {
        //Debug.Log("AttackHitbox::OnTriggerStay2D -- " + collision.gameObject.name);

        Health h = collider.GetComponentInParent <Health>();

        if (h != null)
        {
            h.TakeDamage(Damage);
            return;
        }

        DestructibleTerrain dt = collider.GetComponentInParent <DestructibleTerrain>();

        if (dt != null)
        {
            //DestroyTile(collider, dt);
        }
    }
예제 #6
0
파일: Attacks.cs 프로젝트: quill18/LD45
    IEnumerator WallDestruction()
    {
        Vector2 pos = transform.position + (spriteRenderer.flipX ? -AttackPrefabOffset : AttackPrefabOffset);
        Vector2 dir = spriteRenderer.flipX ? Vector2.left : Vector2.right;

        bool tryAgain = false;

        do
        {
            tryAgain = false;

            RaycastHit2D[] hits = Physics2D.BoxCastAll(pos, new Vector2(1.0f, WallDestHeight), 0, dir);
            //Debug.Log("LENGTH: " + hits.Length);

            foreach (RaycastHit2D hit in hits)
            {
                //Debug.Log("HIT: " + hit.collider.name);

                DestructibleTerrain dt = hit.collider.GetComponentInParent <DestructibleTerrain>();
                if (dt == null)
                {
                    continue;
                }

                Tilemap tilemap = dt.GetComponentInParent <Tilemap>();

                Vector3Int tilePos = tilemap.WorldToCell(hit.point);
                if (tilemap.GetTile(tilePos) != null)
                {
                    tilemap.SetTile(tilePos, null);
                    // Because terrain is a single collider, we need to
                    // repeat the cast to see if any other tiles would be hit.
                    tryAgain = true;
                    yield return(null); // wait a frame
                }
            }
        } while (tryAgain);
    }
예제 #7
0
파일: FallingRock.cs 프로젝트: quill18/LD45
    void DestroyTerrain(DestructibleTerrain dt, Collision2D collision)
    {
        if (dt == null)
        {
            return;
        }

        Tilemap tilemap = dt.GetComponentInParent <Tilemap>();

        Vector2 pos = collision.contacts[0].point;

        Vector3Int tilePos = tilemap.WorldToCell(pos);

        if (tilemap.GetTile(tilePos) != null)
        {
            tilemap.SetTile(tilePos, null);

            if (dt.DebrisPrefab != null)
            {
                Instantiate(dt.DebrisPrefab, pos, Quaternion.identity);
            }
        }
    }
 private void Start()
 {
     //brokenVersion = transform.Find
     parentTerrain = GetComponentInParent <DestructibleTerrain>();
 }
예제 #9
0
    //
    public void GenerateExplosion()
    {
        //
        if (exploding)
        {
            return;
        }
        else
        {
            exploding = true;
        }
        // Primero aplicamos la onda de choque
        // Vamos a hacer que este daño vaya contra la "estrucura"
        Collider[] affectedColliders = Physics.OverlapSphere(transform.position, shockWaveRange);
        //
        for (int i = 0; i < affectedColliders.Length; i++)
        {
            //
            Vector3 affectedColliderDirection = affectedColliders[i].transform.position - transform.position;
            float   receivedBlastForce        = explosionForce / (1 + Mathf.Pow(affectedColliderDirection.magnitude, 2));
            Vector3 blastForceWithDirection   = affectedColliderDirection.normalized * receivedBlastForce;
            //
            PlayerIntegrity playerIntegrity = affectedColliders[i].GetComponent <PlayerIntegrity>();
            if (playerIntegrity != null)
            {
                playerIntegrity.ReceiveBlastDamage(blastForceWithDirection);
            }
            //
            EnemyCollider enemyCollider = affectedColliders[i].GetComponent <EnemyCollider>();
            if (enemyCollider != null)
            {
                enemyCollider.ReceivePulseDamage(blastForceWithDirection);
            }
            // Después enemy consistencies
            EnemyConsistency enemyConsistency = affectedColliders[i].GetComponent <EnemyConsistency>();
            if (enemyConsistency == null)
            {
                enemyConsistency = affectedColliders[i].GetComponentInParent <EnemyConsistency>();
            }
            if (enemyConsistency != null)
            {
                enemyConsistency.ReceivePulseDamage(blastForceWithDirection);
            }
            //
            DestructibleTerrain destructibleTerrain = affectedColliders[i].GetComponent <DestructibleTerrain>();
            if (destructibleTerrain != null)
            {
                destructibleTerrain.ReceivePulseImpact(blastForceWithDirection);
            }
            // Aplicamos fuerza directa a los rigidbodies que no son el player ni los enemigos
            // Estos se lo gestionan en la funcióbn de recibir daño de explosión
            Rigidbody rigidbody = affectedColliders[i].GetComponent <Rigidbody>();
            if (rigidbody != null && enemyConsistency == null && playerIntegrity == null && rigidbody != proyectileRb)
            {
                rigidbody.AddForce(blastForceWithDirection / 1000);
            }
        }
        //
        if (generatesFragments)
        {
            GenerateFragments(fragmentsPerHeight, fragmentsPerWidth, 1 / 2);
        }
        //
        //GeneralFunctions.PlaySoundEffect(audioObjectManager, explosionClip);
        if (audioObjectManager != null)
        {
            audioObjectManager.CreateAudioObject(explosionClip, transform.position);
        }
        //
        //Destroy(gameObject);
        //proyectileRb.velocity = Vector3.zero;
        //bulletPool.ReturnBullet(gameObject);

        bulletScript.ReturnBulletToPool();
    }