Example #1
0
    // Update is called once per frame
    new void Update()
    {
        // runs cell update
        base.Update();

        AIBehavior();

        if (kills == 3)
        {
            emScript.playerCells.Remove(this);
            Destroy(this.gameObject);
        }

        if (isStopped)
        {
            killTimer -= Time.deltaTime;

            if (killTimer <= 0)
            {
                kills++;
                EnemyCell temp = targetCell;
                emScript.enemies.Remove(temp);
                Destroy(temp.gameObject);
                isStopped = false;
                ecoScript.money++;
                emScript.stats[0]++;
                emScript.stats[2]++;
            }

            if (targetCell == null)
            {
                isStopped = false;
            }
        }
    }
Example #2
0
 /// <summary>
 /// Checks for collision between enemies and player cells
 /// </summary>
 /// <param name="enemy">Enemy cell to be checked</param>
 /// <param name="player">Nearest Player Cell</param>
 public void CheckCollide(EnemyCell enemy, PlayerCell player)
 {
     if (Vector3.SqrMagnitude(enemy.transform.position - player.transform.position) <= enemy.GetComponent <CircleCollider2D>().radius / 20)
     {
         Debug.Log(Vector3.SqrMagnitude(enemy.transform.position - player.transform.position));
         enemy.isStopped  = true;
         player.isStopped = true;
         player.SetKillTimer(enemy.type);
     }
 }
Example #3
0
 /// <summary>
 /// Method to spawn enemies
 /// </summary>
 public void Spawn()
 {
     //should only spawn equal amount to wave, I want it to spawn more tho in the future
     for (int i = 0; i <= wave; i++)
     {
         GameObject tempE = Instantiate(enemyCellPrefabs[UnityEngine.Random.Range(0, enemyCellPrefabs.Count)], new Vector3(-9f, Random.Range(-5f, 5f), 0.001f), Quaternion.identity);
         EnemyCell  enemy = tempE.GetComponent <EnemyCell>();
         enemy.goal     = goal.gameObject;
         enemy.position = enemy.transform.position;
         enemies.Add(enemy);
     }
 }
Example #4
0
    /// <summary>
    /// returns if the enemy is colliding
    /// with the goal using the 2D colliders
    /// </summary>
    /// <param name="e"></param>
    /// <returns></returns>
    public bool CheckGoal(EnemyCell e)
    {
        CircleCollider2D circle = e.gameObject.GetComponent <CircleCollider2D>();

        if (e.transform.position.x + circle.bounds.extents.x < goal.transform.position.x + goalCollider.bounds.extents.x &&
            e.transform.position.y + circle.bounds.extents.y < goal.transform.position.y + goalCollider.bounds.extents.y &&
            e.transform.position.x - circle.bounds.extents.x > goal.transform.position.x - goalCollider.bounds.extents.x &&
            e.transform.position.y - circle.bounds.extents.y > goal.transform.position.y - goalCollider.bounds.extents.y)
        {
            return(true);
        }
        //return Vector3.SqrMagnitude(e.gameObject.transform.position - goal.transform.position) <= circle.radius ? true : false;
        return(false);
    }
Example #5
0
 public void Add(Enemy newEnemy)
 {
     if (enemies == null)
     {
         enemies = new EnemyCell(newEnemy);
     }
     else
     {
         if (Contains(newEnemy))
         {
             throw new ArgumentException("you added same enemy for Enemies");
         }
         enemies = new EnemyCell(newEnemy, enemies);
     }
 }
Example #6
0
        private IEnumerator InitFieldType()
        {
            ThisFinalStatus = new FinalStatusData();
            var dataList = LTLegionWarManager.Instance.FinalStatusList.AllFinalStatusDataList;

            for (var i = 0; i < dataList.Count; i++)
            {
                var data = dataList[i];
                if (data.FieldNumber == LTLegionWarManager.Instance.SemiFinalField && data.Type == WarFiled)
                {
                    ThisFinalStatus = data;
                    break;
                }
            }
            //0,1,2 开始,结束,准备中
            if (ThisFinalStatus.Status == 2)//准备中
            {
                UsCell.SetCurStatu(false);
                EnemyCell.SetCurStatu(false);
            }
            else if (ThisFinalStatus.Status == 0)//开始
            {
                PlayerLadderRanking.gameObject.CustomSetActive(false);
                TimeLabel.gameObject.CustomSetActive(false);

                //SetAllEnemyInfo(false);
                UsCell.SetCurStatu(false);
                EnemyCell.SetCurStatu(false);
            }
            else//结束
            {
                PlayerLadderRanking.gameObject.CustomSetActive(false);
                TimeLabel.gameObject.CustomSetActive(false);

                //SetAllEnemyInfo(false);
                if (Legions[0] != null)
                {
                    UsCell.SetCurStatu(true, ThisFinalStatus.WinAid == Legions[0].id);
                }
                if (Legions[1] != null)
                {
                    EnemyCell.SetCurStatu(true, ThisFinalStatus.WinAid == Legions[1].id);
                }
            }
            yield break;
        }
Example #7
0
 public bool MoveNext()
 {
     if (position == -1)
     {
         current = firstCell;
     }
     else
     {
         current = current.NextCell;
     }
     if (current == null)
     {
         return(false);
     }
     position++;
     return(true);
 }
Example #8
0
    /// <summary>
    /// The method that runs when the cell is in AI mode
    /// </summary>
    public virtual void AIBehavior()
    {
        if (!isWaiting)
        {
            if (toPoint)
            {
                if (Vector3.SqrMagnitude(transform.position - targetPoint) <= circleCollider.radius / 20)
                {
                    isWaiting = true;
                    waitTimer = 1.5f;
                    velocity  = Vector3.zero;
                }
            }

            // checks if it need to find a target
            if (targetCell == null)
            {
                targetCell = FindClosestEnemy();

                if (targetCell == null)
                {
                    toPoint = true;
                }
            }
            else
            {
                if (targetCell.isStopped && !isStopped)
                {
                    targetCell = null;
                }
            }
        }
        else
        {
            waitTimer -= Time.deltaTime;
            if (waitTimer <= 0)
            {
                isWaiting  = false;
                targetCell = FindClosestEnemy();
                toPoint    = false;
            }
        }
    }
Example #9
0
        private IEnumerator InitWatchLogFieldType()
        {
            ThisFinalStatus = new FinalStatusData();
            var dataList = LTLegionWarManager.Instance.WatchLogList.AllFinalStatusDataList;

            for (var i = 0; i < dataList.Count; i++)
            {
                var data = dataList[i];
                if (data.FieldNumber == LTLegionWarManager.Instance.SemiFinalField && data.Type == WarFiled)
                {
                    ThisFinalStatus = data;
                    break;
                }
            }
            if (Legions[0] != null)
            {
                UsCell.SetCurStatu(true, ThisFinalStatus.WinAid == Legions[0].id);
            }
            if (Legions[1] != null)
            {
                EnemyCell.SetCurStatu(true, ThisFinalStatus.WinAid == Legions[1].id);
            }
            yield break;
        }
Example #10
0
 private void InitLegionData()
 {
     UsCell.inWarFill(Legions[0]);
     EnemyCell.inWarFill(Legions[1]);
     PlayerLadderRanking.text = PlayerLadderRanking.transform.GetChild(0).GetComponent <UILabel>().text = string.Format(EB.Localizer.GetString("ID_MY_LADDER_RANK") + ":[fff348]{0}", LadderManager.Instance.Info.Rank > 0 ? LadderManager.Instance.Info.Rank.ToString() : EB.Localizer.GetString("ID_ARENA_RANK_OUT_OF_RANGE"));
 }
Example #11
0
    // Update is called once per frame
    void Update()
    {
        //begin wave im not sure how to yet

        if (enemies.Count == 0)
        {
            EndWave();
        }
        if (waitTimer > 0 && activeWave == false)
        {
            waitTimer -= Time.deltaTime;
        }
        if ((waitTimer <= 0 && activeWave == false) || Input.GetKeyDown(KeyCode.Return))
        {
            BeginWave();
        }

        // for targeting cells
        if (Input.GetMouseButtonDown(0))
        {
            // gets the mouse position
            Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            // gets player script if its obj was clicked
            PlayerCell tempPlayer = ClickedPlayer();

            // checks if new player cell was clicked
            if (tempPlayer != null)
            {
                // sets to new player cell
                selectedCell = tempPlayer;
                //selectedCell.aiMode = false;
            }
            else if (selectedCell != null)
            {
                // gets the enemy script if it clicked on an enemy obj
                EnemyCell tempEnemy  = ClickedEnemy();
                bool      properType = false;

                // checks if they clicked an enemy
                if (tempEnemy != null)
                {
                    switch (selectedCell.type)
                    {
                    case CellType.Neutrophil:
                        if (tempEnemy.type == EnemyType.Normal || tempEnemy.type == EnemyType.Bacteria)
                        {
                            properType = true;
                        }
                        break;

                    case CellType.Eosinophil:
                        if (tempEnemy.type == EnemyType.Normal || tempEnemy.type == EnemyType.Paracyte)
                        {
                            properType = true;
                        }
                        break;

                    case CellType.Basophil:
                        if (tempEnemy.type == EnemyType.Paracyte || tempEnemy.type == EnemyType.Allergen)
                        {
                            properType = true;
                        }
                        break;

                    default:
                        properType = true;
                        break;
                    }
                }

                if (!properType)
                {
                    // formats the cell to target new point
                    selectedCell.targetPoint   = pos;
                    selectedCell.targetPoint.z = 0;
                    selectedCell.targetCell    = null;
                    selectedCell.toPoint       = true;
                }
                else
                {
                    // sets the player cell to target new enemy
                    selectedCell.targetCell = tempEnemy;
                    selectedCell.toPoint    = false;
                }
            }
        }
        // resets the cell to null so you can click elsewhere
        if (Input.GetMouseButtonDown(1))
        {
            selectedCell = null;
        }

        // loop that checks collision
        for (int i = 0; i < enemies.Count; i++)
        {
            // checks if the playercell of that enemy exists
            if (enemies[i].playerCell != null && !enemies[i].isStopped && enemies[i].playerCell.GetComponent <PlayerCell>().targetCell == enemies[i])
            {
                CheckCollide(enemies[i], enemies[i].playerCell.GetComponent <PlayerCell>());
            }

            if (CheckGoal(enemies[i]))
            {
                goal.health -= 5;
                EnemyCell enemy = enemies[i];
                enemies.Remove(enemy);
                Destroy(enemy.gameObject);
            }
        }
    }
Example #12
0
    /// <summary>
    /// Finds the closest enemy to pursue
    /// </summary>
    /// <returns>The enemy cell that's closest</returns>
    public EnemyCell FindClosestEnemy()
    {
        // temp vars
        EnemyCell currentCell = null;
        float     currentDist = 0f;

        // loop that goes through all the enemies
        int count = emScript.enemies.Count;

        for (int i = 0; i < count; i++)
        {
            switch (type)
            {
            case CellType.Neutrophil:
                if (emScript.enemies[i].type != EnemyType.Bacteria && emScript.enemies[i].type != EnemyType.Normal)
                {
                    continue;
                }
                else if (currentCell == null)
                {
                    currentDist = Vector3.SqrMagnitude(this.transform.position - emScript.enemies[i].transform.position);
                    currentCell = emScript.enemies[i];
                    continue;
                }
                break;

            case CellType.Eosinophil:
                if (emScript.enemies[i].type != EnemyType.Paracyte && emScript.enemies[i].type != EnemyType.Normal)
                {
                    continue;
                }
                else if (currentCell == null)
                {
                    currentDist = Vector3.SqrMagnitude(this.transform.position - emScript.enemies[i].transform.position);
                    currentCell = emScript.enemies[i];
                    continue;
                }
                break;

            case CellType.Basophil:
                if (emScript.enemies[i].type != EnemyType.Paracyte && emScript.enemies[i].type != EnemyType.Allergen)
                {
                    continue;
                }
                else if (currentCell == null)
                {
                    currentDist = Vector3.SqrMagnitude(this.transform.position - emScript.enemies[i].transform.position);
                    currentCell = emScript.enemies[i];
                    continue;
                }
                break;
            }

            // gets the dist
            float dist = Vector3.SqrMagnitude(this.transform.position - emScript.enemies[i].transform.position);

            if (currentCell == null)
            {
                currentDist = Vector3.SqrMagnitude(this.transform.position - emScript.enemies[i].transform.position);
                currentCell = emScript.enemies[i];
                continue;
            }

            // checks current dist for closer
            if (dist < currentDist)
            {
                currentCell = emScript.enemies[i];
                currentDist = dist;
            }
        }

        // returns closest cell
        return(currentCell);
    }
Example #13
0
 public void Clear()
 {
     enemies = null;
 }
Example #14
0
 public void Reset()
 {
     position = -1;
     current  = null;
 }
Example #15
0
 //public Object IEnumerator<Enemy>.Current
 //{
 //    get
 //    {
 //        return this.Current;
 //    }
 //}
 public EnemyEnumrator(EnemyCell firstCell)
 {
     position       = -1;
     this.firstCell = firstCell;
 }
Example #16
0
 public EnemyCell(Enemy enemy, EnemyCell nextCell)
 {
     this.enemy    = enemy;
     this.nextCell = nextCell;
 }