Exemple #1
0
    public static EnemyAim GetClosestEnemy(Vector3 position, float maxRange)
    {
        EnemyAim closest = null;

        foreach (EnemyAim enemy in enemyList)
        {
            if (enemy.IsDead())
            {
                continue;
            }
            if (Vector3.Distance(position, enemy.GetPosition()) <= maxRange)
            {
                if (closest == null)
                {
                    closest = enemy;
                }
                else
                {
                    if (Vector3.Distance(position, enemy.GetPosition()) < Vector3.Distance(position, closest.GetPosition()))
                    {
                        closest = enemy;
                    }
                }
            }
        }
        return(closest);
    }
Exemple #2
0
 // Despawns bullets when they leave the bounds of the screen.
 // Deactivates enemy powers (like shooting) when they leave the screen.
 private void OnCollisionExit2D(Collision2D coll)
 {
     if (coll.gameObject.tag.Equals("PlayerBullet") || coll.gameObject.tag.Equals("EnemyBullet"))
     {
         coll.gameObject.SetActive(false);
     }
     if (coll.gameObject.tag.Equals("GroundEnemy") || coll.gameObject.tag.Equals("AirEnemy"))
     {
         Exploder exp = coll.gameObject.GetComponent <Exploder>();
         EnemyAim nma = coll.gameObject.GetComponent <EnemyAim>();
         Tank     tnk = coll.gameObject.GetComponent <Tank>();
         Cannon   can = coll.gameObject.GetComponent <Cannon>();
         if (exp)
         {
             exp.StopShoot();
         }
         if (nma)
         {
             nma.StopShoot();
         }
         if (tnk)
         {
             tnk.StopShoot();
         }
         if (can)
         {
             can.StopShoot();
         }
         // If an enemy was left alive, decrease the threat level.
         ThreatLevel.instance.AddKillLevel(-1f);
     }
 }
Exemple #3
0
    public static EnemyAim Create(Vector3 position)
    {
        Transform enemyTransform = Instantiate(GameAssets.i.pfEnemy, position, Quaternion.identity);

        EnemyAim enemyHandler = enemyTransform.GetComponent <EnemyAim>();

        return(enemyHandler);
    }
Exemple #4
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.CompareTag("SpaceshipPart"))
     {
         Debug.Log("UnCollided with SpaceshipPart");
         diggablePart = null;
     }
     if (collision.CompareTag("EnemyAim"))
     {
         aim = null;
     }
 }
Exemple #5
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.CompareTag("SpaceshipPart"))
     {
         Debug.Log("Collided with SpaceshipPart");
         diggablePart = collision.GetComponent <SpaceshipPart>();
     }
     if (collision.CompareTag("EnemyAim"))
     {
         aim = collision.GetComponent <EnemyAim>();
     }
 }
Exemple #6
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     //Return parts to ship
     if (collision.CompareTag("Player"))
     {
         Player player = collision.GetComponent <Player>();
         player.Dazzle();
         if (aIDestinationSetter.targetType == TargetType.Player)
         {
             GetNewTarget(TargetType.Spaceship);
         }
         Debug.Log("Collided with player");
         // TODO: set player dazzle or something like that?
     }
     else if (collision.CompareTag("Spaceship") && !holdsPart && aIDestinationSetter.targetType == TargetType.Spaceship)
     {
         // Debug.Log("Collided with spaceship");
         Spaceship spaceship = collision.GetComponent <Spaceship>();
         spaceship.StealPart();
         holdsPart = true;
         GetNewTarget(TargetType.EnemyAim);
         // TODO: remove spaceship part
     }
     else if (collision.CompareTag("EnemyAim") && holdsPart)
     {
         // Debug.Log("Collided with EnemyAim");
         EnemyAim aim = collision.GetComponent <EnemyAim>();
         if (holdsPart)
         {
             aim.AddSpaceshipPart();
             holdsPart = false;
             SpaceshipPart newPart = Instantiate(_part, aim.transform.position, Quaternion.identity);
             newPart.DigIn();
         }
         isWaiting = true;
         StartCoroutine(WaitForNextSteal());
     }
     else if (collision.CompareTag("Enemy"))
     {
         // GameObject otherEnemy = collision.gameObject;
         // TODO: maybe find some sort of avoidance?
         StartCoroutine(CheckIfStuck());
     }
     else
     {
         // Debug.LogWarning("Collided with " + collision);
     }
 }
Exemple #7
0
    public void Damage(EnemyAim attacker)
    {
        Vector3 bloodDir = (GetPosition() - attacker.GetPosition()).normalized;

        Blood_Handler.SpawnBlood(GetPosition(), bloodDir);

        healthSystem.Damage(1);
        if (IsDead())
        {
            FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir);
            playerBase.DestroySelf();
            Destroy(gameObject);
        }
        else
        {
            // Knockback
            transform.position += bloodDir * 2.5f;
        }
    }
    // If destroyed, then stop shooting, stop moving, and set the flags to indicate destruction.
    private void DestroyCheck()
    {
        if (health <= 0 && !destroyed)
        {
            destroyed    = true;
            coll.enabled = false;
            sr.sprite    = destroySprite;
            // Disable shooting.
            Exploder exp = GetComponent <Exploder>();
            EnemyAim nma = GetComponent <EnemyAim>();
            Tank     tnk = GetComponent <Tank>();
            Cannon   can = GetComponent <Cannon>();

            if (exp)
            {
                exp.StopShoot();
            }
            if (nma)
            {
                nma.StopShoot();
            }
            if (tnk)
            {
                tnk.StopShoot();
            }
            if (can)
            {
                can.StopShoot();
            }

            // Display the explosion effect.
            FXManager.instance.ShowFX("explosion", transform.position, transform.localScale);
            // Add to score.
            ScoreManager.instance.AddScore(pointsOnDestroy);

            SFXManager.instance.PlayClip("destroy");

            // Make note of it with the Threat Level.
            ThreatLevel.instance.AddKillLevel(1 / 2f);
        }
    }
 private void Awake()
 {
     nmeAim = GetComponent <EnemyAim>();
     child  = transform.GetChild(0).transform;
     tm     = GetComponent <Transform>();
 }
Exemple #10
0
 private void Awake()
 {
     nmeAim = GetComponent <EnemyAim>();
     tm     = GetComponent <Transform>();
     dir.Normalize();
 }