Example #1
0
    private WaveInfo GetWaveInfo(int wave)
    {
        CurrentWave = wave;

        // TODO: Replace Test wave with real algorithm
        WaveSectionObject section = new WaveSectionObject();

        section.Enemies = new EnemySpawnData[]
        {
            new EnemySpawnData(EnemyModel.EnemyCharacterType.Normal, 1, "First"),
            new EnemySpawnData(EnemyModel.EnemyCharacterType.Double, 1, "Second"),
            new EnemySpawnData(EnemyModel.EnemyCharacterType.Normal, 2, "The Number after two"),
        };

        section.TimeToFightEnemiesInSeconds = TIME_TO_FIGHT_UNTIL_ALL_EXTINCT;
        // -- End Test Wave

        WaveInfo waveInfo = new WaveInfo(wave, section);

        if (SpawnWaveEvent != null)
        {
            SpawnWaveEvent(waveInfo);
        }

        return(waveInfo);
    }
Example #2
0
    private void SpawnWaveSection(WaveSectionObject waveSection)
    {
        EnemyModel[] enemiesSpawned = new EnemyModel[waveSection.Enemies.Length];

        float spawnDistY = _gameCamera.OrthographicSize + _orthographicSpawnMargin;
        float spawnDistX = spawnDistY * Screen.width / Screen.height;

        for (int i = 0; i < waveSection.Enemies.Length; i++)
        {
            float distanceVarienceValue = UnityEngine.Random.value * 2f;
            bool  fullX = UnityEngine.Random.value > 0.5f;
            int   xMult = UnityEngine.Random.value > 0.5f ? 1 : -1;
            int   yMult = UnityEngine.Random.value > 0.5f ? 1 : -1;
            float x     = ((fullX) ? 1 : UnityEngine.Random.value);
            float y     = ((!fullX) ? 1 : UnityEngine.Random.value);
            x = (Mathf.Lerp(0, spawnDistX, x) + distanceVarienceValue) * xMult;
            y = (Mathf.Lerp(0, spawnDistY, y) + distanceVarienceValue) * yMult;
            Vector2 spawnPos = new Vector2(x, y);

            EnemyModel enemy = waveSection.Enemies[i].CreateEnemy();
            enemy.Transform.Position = spawnPos;

            enemiesSpawned[i] = enemy;

            if (SpawnEnemyEvent != null)
            {
                SpawnEnemyEvent(enemy);
            }
        }

        if (waveSection.TimeToFightEnemiesInSeconds == TIME_TO_FIGHT_UNTIL_ALL_EXTINCT)
        {
            _sectionTracker.TrackExtinction(enemiesSpawned, OnEndSection);
        }
        else
        {
            _sectionTracker.TrackEndOfTime(waveSection.TimeToFightEnemiesInSeconds, OnEndSection);
        }
    }