Esempio n. 1
0
    private IEnumerator Spawn(int enemyInd)
    {
        EnemySpawnInfo info        = m_Enemies[enemyInd];
        int            i           = 0;
        bool           alwaysSpawn = false;

        if (info.NumberToSpawn == 0)
        {
            alwaysSpawn = true;
        }
        while (alwaysSpawn || i < info.NumberToSpawn)
        {
            yield return(new WaitForSeconds(info.TimeToNextSpawn));

            float xVal = m_Bounds.x / 2;
            float yVal = m_Bounds.y / 2;
            float zVal = m_Bounds.z / 2;

            Vector3 spawnPos = new Vector3(
                Random.Range(-xVal, xVal),
                Random.Range(-yVal, yVal),
                Random.Range(-zVal, zVal));

            spawnPos += transform.position;
            Instantiate(info.EnemyGO, spawnPos, Quaternion.identity);
            if (!alwaysSpawn)
            {
                i++;
            }
        }
    }
Esempio n. 2
0
    public void DeactivateAndStoreEnemy(GameObject enemy /*, int groupIndex, int indexInTheGroup*/)
    {
        enemy.SetActive(false);
        EnemySpawnInfo enemySpawnInfo = enemy.GetComponent <EnemySpawnInfo>();

        groupsOfEnemies[enemySpawnInfo.enemyGroupIndex].enemies[enemySpawnInfo.enemyIndexInTheGroup].Add(enemy);
    }
Esempio n. 3
0
    public void CreateEnemy(int groupIndex, int indexInTheGroup, Vector3 position)
    {
        GameObject enemy;

        if (groupsOfEnemies[groupIndex].enemies[indexInTheGroup].Count == 0)
        {
            enemy = Instantiate(groupsOfEnemies[groupIndex].enemyPrefabs[indexInTheGroup], position, groupsOfEnemies[groupIndex].enemyPrefabs[indexInTheGroup].transform.rotation);
            //groupsOfEnemies[groupIndex].enemies[indexInTheGroup].Add(enemy);
            enemy.transform.parent = groupsOfEnemies[groupIndex].enemyParents[indexInTheGroup].transform;
        }
        else
        {
            enemy = groupsOfEnemies[groupIndex].enemies[indexInTheGroup][groupsOfEnemies[groupIndex].enemies[indexInTheGroup].Count - 1];
            groupsOfEnemies[groupIndex].enemies[indexInTheGroup].RemoveAt(groupsOfEnemies[groupIndex].enemies[indexInTheGroup].Count - 1);

            Health enemyHealth = enemy.GetComponent <Health>();
            enemyHealth.ReinitializeHealth();
            Energy enemyEnergy = enemy.GetComponent <Energy>();
            enemyEnergy.ReinitializeEnergy();

            enemy.transform.position = position;
            enemy.SetActive(true);
        }

        EnemySpawnInfo enemySpawnInfo = enemy.GetComponent <EnemySpawnInfo>();

        //Debug.Log("enemySpawnInfo == null: " + (enemySpawnInfo == null).ToString());
        enemySpawnInfo.enemyGroupIndex      = groupIndex;
        enemySpawnInfo.enemyIndexInTheGroup = indexInTheGroup;
    }
Esempio n. 4
0
    IEnumerator SpawnEnemy2()
    {
        EnemySpawnInfo EnemyCount = Enemies[currentWave];

        for (int i = 0; i < EnemyCount.count2; i++)
        {
            SpawnEnemy2(EnemyCount.Enemy2);
            yield return(new WaitForSeconds(1 / EnemyCount.rate2));
        }
    }
Esempio n. 5
0
    /// <summary>
    /// method that create the state machine for the enemy, with the data from enemy spawn info.
    /// get the data and create the stane machine
    ///
    /// the idea is have the data from the enemy spawn info of different way. So here depending how is the info,
    /// differents state machines will be created so the enemy will have differents behavior
    /// </summary>
    /// <param name="enemyBeingSpawn"></param>
    /// <param name="enemySpawnInfo"></param>
    /// <returns></returns>
    private FSMachine CreateEnemyBehaviorFSM(EnemyEntity enemyBeingSpawn, EnemySpawnInfo enemySpawnInfo)
    {
        // getting the data for the enemy state machine
        Vector3 initialWorldPosition = Camera.main.ViewportToWorldPoint(enemySpawnInfo.EnemyViewPortInitialPosition);
        Vector3 turnWorldPosition    = Camera.main.ViewportToWorldPoint(enemySpawnInfo.EnemyViewPortTurnPosition);
        Vector3 finalWorldPosition   = Camera.main.ViewportToWorldPoint(enemySpawnInfo.EnemyViewPortFinalPosition);

        // creating the FSM with the data from enemy spawn info
        return(new FSMEnemyGoShotAndLeave(enemyBeingSpawn, initialWorldPosition, turnWorldPosition, finalWorldPosition));
    }
Esempio n. 6
0
        private void GenerateSpawnInfo()
        {
            var quantity = Random.Range(minNumberOfSpawnedAtOnce, maxNumberOfSpawnedAtOnce);

            for (var i = 0; i < quantity; i++)
            {
                var spawnFunction = GetSpawnEnemyFunction();
                var interval      = Random.Range(minIntervalInMillis, maxIntervalInMillis);
                var spawnInfo     = new EnemySpawnInfo(interval, spawnFunction);
                _enemySpawnInfoQueue.Enqueue(spawnInfo);
            }
        }
Esempio n. 7
0
    public void SetUpSettings(EnemySpawnInfo enemySpawnInfo)
    {
        moveSpeed           = enemySpawnInfo.moveSpeed;
        stopDistance        = enemySpawnInfo.stopDistance;
        healthPoints        = enemySpawnInfo.maxXp;
        currentHealthPoints = enemySpawnInfo.startXp * (1 + GameStats.level * 0.1f);
        healthPoints        = enemySpawnInfo.maxXp * (1 + GameStats.level * 0.1f);
        damage      = enemySpawnInfo.damage;
        goldPerKill = enemySpawnInfo.goldPerKill;

        onHpChange?.Invoke(currentHealthPoints, healthPoints);
    }
Esempio n. 8
0
    /// <summary>
    /// method that sort the spawn list by time, lower to greater
    /// </summary>
    /// <param name="info1"></param>
    /// <param name="info2"></param>
    /// <returns></returns>
    private int orderByTime(EnemySpawnInfo info1, EnemySpawnInfo info2)
    {
        if (info1.Time < info2.Time)
        {
            return(-1);
        }
        if (info1.Time > info2.Time)
        {
            return(1);
        }

        return(0);
    }
Esempio n. 9
0
    public void SpawnNextEnemy()
    {
        if (!HaveSpawnedAllEnemies())
        {
            EnemySpawnInfo enemySpawnInfo = enemySpawns[enemySpawnIndex];
            enemySpawnIndex++;
            GameObject enemyObject = Instantiate(enemySpawnInfo.enemyPrefab, enemySpawnInfo.position.position, Quaternion.identity);

            if (enemySpawnInfo.spawnSeqType != SpawnSequenceType.Indestructable)
            {
                enemiesLeft += 1;
                Enemy enemy = enemyObject.GetComponentInChildren <Enemy>();
                enemy.OnDeath.AddListener(EnemyDied);
            }
            else
            {
                indestructableObjects.Add(enemyObject);
            }

            if (enemySpawnIndex < enemySpawns.Length)
            {
                EnemySpawnInfo nextEnemySpawnInfo = enemySpawns[enemySpawnIndex];
                switch (nextEnemySpawnInfo.spawnSeqType)
                {
                case SpawnSequenceType.PreviousEnemiesCleared:
                    spawnWhenEnemiesCleared = true;
                    break;

                case SpawnSequenceType.Immediate:
                    SpawnNextEnemy();
                    break;

                case SpawnSequenceType.Indestructable:
                    SpawnNextEnemy();
                    break;

                default:
                    break;
                }
            }
        }
    }
Esempio n. 10
0
    //-- Initialize
    private void RestartAI()
    {
        int index = 0;

        for (int i = 0; i < enemySpawnDetails_list.Count; ++i)
        {
            int totalEnemyCount = enemySpawnDetails_list[i].ai_spawn_count;

            for (int z = 0; z < totalEnemyCount; ++z)
            {
                EnemySpawnInfo info = enemySpawnDetails_list[i];

                //RePosition enemy [Manual Position Enemy, move Way Point to Way Point]
                if (info.ai_spawn_type == SpawnType.RANGE && info.ai_movement_type == AIType.MOVE)
                {
                    // Spawn enemy at their CP1
                    ListOfEnemies[index].position = info.T_CheckPoints[0].position;
                }
                // Reposition Enemy: [Random spawn within a range, spawn idle enemy]
                else if (info.ai_spawn_type == SpawnType.RANDOM && info.ai_movement_type == AIType.IDLE)
                {
                    Vector3 randomPos = new Vector3(Random.Range(info.T_CheckPoints[0].position.x, info.T_CheckPoints[1].position.x),
                                                    0.5f,
                                                    Random.Range(info.T_CheckPoints[0].position.z, info.T_CheckPoints[1].position.z));
                    ListOfEnemies[index].position = randomPos;
                }
                // Reposition Enemy: [Random Spawn within a range, spawn charge enemy]
                else if (info.ai_spawn_type == SpawnType.RANDOM && info.ai_movement_type == AIType.CHARGE)
                {
                    Vector3 randomPos = new Vector3(Random.Range(info.T_CheckPoints[0].position.x, info.T_CheckPoints[1].position.x),
                                                    0.5f,
                                                    Random.Range(info.T_CheckPoints[0].position.z, info.T_CheckPoints[1].position.z));
                    ListOfEnemies[index].position = randomPos;
                }
                index++;
            }
        }
    }