Esempio n. 1
0
 public virtual void EnemyGotStunned(AbstractEnemyControl enemy)
 {
     // Enemy got stunned. If he was active, return him to the pacing array. If he's still the closest, he'll get converted back in a heartbeat.
     if (enemiesAttacking.Contains(enemy))
     {
         enemiesPacing.Add(enemy);
         enemiesAttacking.Remove(enemy);
         AbstractEnemyControl.EnemyStates state = Random.value >= 0.5f ? AbstractEnemyControl.EnemyStates.paceBack : AbstractEnemyControl.EnemyStates.paceForth;
         enemy.setEnemyState(state);
         enemy.setBaseState(state);
     }
 }
Esempio n. 2
0
    // Update is called once per frame
    public virtual void Update()
    {
        if (enemyCount > 0)
        {
            for (var i = spawns.Length - 1; i >= 0; i--)
            {
                if (spawns [i].hasMissingEnemy)
                {
                    GameObject           newEnemy   = spawns [i].spawnEnemy();
                    AbstractEnemyControl newControl = newEnemy.GetComponent <AbstractEnemyControl>();
                    enemiesPacing.Add(newControl);
                    newControl.setBaseState(Random.value >= 0.5f ? AbstractEnemyControl.EnemyStates.paceBack : AbstractEnemyControl.EnemyStates.paceForth);
                    enemyCount--;
                    currentEnemyCount++;
                    if (enemyCount <= 0)
                    {
                        return;
                    }
                }
            }
        }
        else
        {
            bool hasEnemy = false;
            for (var i = spawns.Length - 1; i >= 0; i--)
            {
                if (!spawns [i].hasNoEnemy)
                {
                    hasEnemy = true;
                }
            }
            if (!hasEnemy)
            {
                _anim.SetTrigger("Complete");
                timer -= 1 * Time.deltaTime;
                if (timer <= 0)
                {
                    SavePlayerStats();
                    timer = 0;
                    Resources.UnloadUnusedAssets();
                    Application.LoadLevel(nextLevel);
                }
            }
        }

        UpdateEnemies();
    }
    public override void Update()
    {
        if (_player != null && _player.playerHealth <= 0)
        {
            ActivateScreen();
        }

        // Just keep spawning enemies.
        if (currentEnemyCount < enemyCount)
        {
            // Spawn enemies one at a time, cycling through the index.
            int i = spawnIndex;
            spawnIndex = (spawnIndex + 1) % spawns.Length;

            // Only spawn if the spawner doesn't have the max.
            if (spawns[i].hasMissingEnemy)
            {
                currentEnemyCount++;
                GameObject           newEnemy   = spawns[i].spawnEnemy();
                AbstractEnemyControl newControl = newEnemy.GetComponent <AbstractEnemyControl>();
                enemiesPacing.Add(newControl);
                newControl.setBaseState(Random.value >= 0.5f ? AbstractEnemyControl.EnemyStates.paceBack : AbstractEnemyControl.EnemyStates.paceForth);

                // Make enemies go crazy upon spawning if dieToWin.
                if (dieToWin)
                {
                    GameObject[] enemies = spawns[i].getEnemies();
                    for (int j = enemies.Length - 1; j >= 0; j--)
                    {
                        if (enemies[j] != null)
                        {
                            Clown clown = (enemies[j] as GameObject).GetComponent <Clown>();
                            if (clown == null)
                            {
                                continue;
                            }
                            clown.setShudder(10);
                            clown.setPhaseChance(.3f);
                            clown.setEnemyDamage(10);
                            clown.setMoveSpeed(2f);
                        }
                    }
                }
            }
        }

        timePassed += Time.deltaTime;

        if (enemyCount >= 10)
        {
            // Boss time.
            if (!bossSpawned)
            {
                if (timePassed % timeToAdvance < timePassed)
                {
                    // Hit a 30-second mark. Spawn the boss.
                    GameObject bossObj = Instantiate(boss.gameObject);

                    // Boss is placed in GameController.
                    bossObj.transform.parent = transform;

                    // Boss has 2 spawn points. Spawn wherever it's farthest from the player.
                    if (Vector3.Distance(player.transform.position, bossSpawnCenter.position) > Vector3.Distance(player.transform.position, bossSpawnRight.position))
                    {
                        bossObj.transform.position = bossSpawnCenter.transform.position;
                    }
                    else
                    {
                        bossObj.transform.position = bossSpawnRight.transform.position;
                    }

                    timePassed  = 0;
                    bossSpawned = true;
                }
            }
            else
            {
                // Boss time update.
            }
        }
        else if (timePassed % timeToAdvance < timePassed)
        {
            // Hit a 30-second mark. Add one to the adCount.
            timePassed -= timeToAdvance;
            enemyCount++;
        }

        UpdateEnemies();
    }