Example #1
0
 private void PerformAttack(PlayerTroop playerTroop)
 {
     if (EnemiesManager.Instance != null && playerTroop.Attack.IsAttackPossible())
     {
         EnemyCreature enemy = EnemiesManager.Instance.GetNearestEnemy(playerTroop.GameObject.transform.position,
                                                                       playerTroop.Attack.Range);
         if (enemy != null)
         {
             playerTroop.PerformAttack(enemy.Health, enemy.Position);
         }
     }
 }
Example #2
0
 public void KillTroopWithInfection(int troopIndex)
 {
     if (Troops != null)
     {
         PlayerTroop troopToKill = Troops.Find((t) => t.Index.Equals(troopIndex));
         if (troopToKill != null)
         {
             troopToKill.IsDead = true;
             troopToKill.Health.CurrentHealth = 0;
         }
     }
 }
Example #3
0
 public void InfectRandomTroop()
 {
     if (Troops != null)
     {
         PlayerTroop troopToInfect = Troops.Find((t) => !t.IsInfected && !t.IsDead);
         if (troopToInfect != null)
         {
             troopToInfect.IsInfected = true;
             GameManager.Instance.ShowInfectedTroop(troopToInfect.Index);
             troopToInfect.ChangeColorToInfected();
         }
     }
 }
Example #4
0
 private void PerformAttack(EnemyCreature enemyCreature)
 {
     if (GameManager.Instance != null && enemyCreature.GameObject != null &&
         enemyCreature.Attack.IsAttackPossible())
     {
         PlayerTroop troop = GameManager.Instance.GetNearestPlayerTroop(enemyCreature.GameObject.transform.position,
                                                                        enemyCreature.Attack.Range);
         if (troop != null)
         {
             enemyCreature.PerformAttack(troop.Health, troop.Position);
         }
     }
 }
Example #5
0
    public PlayerTroop GetNearestTroop(Vector2 origin, float range)
    {
        PlayerTroop nearestTroop      = null;
        float       distanceToClosest = float.MaxValue;

        for (int i = 0; i < Troops.Count; i++)
        {
            float distanceToCurrent = Vector3.Distance(Troops[i].Position, origin);
            if (distanceToCurrent < distanceToClosest &&
                distanceToCurrent < range)
            {
                nearestTroop      = Troops[i];
                distanceToClosest = distanceToCurrent;
            }
        }
        return(nearestTroop);
    }