Start delay with for loop and breakTag
This commit is contained in:
parent
4c8b34993a
commit
4ae8f0dcfa
@ -18,10 +18,10 @@ MonoBehaviour:
|
||||
_nestedGroupSpawn:
|
||||
- groupSpawn:
|
||||
- _enemy: {fileID: 313037212318601125, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3}
|
||||
_count: 11
|
||||
_count: 0
|
||||
- _enemy: {fileID: 313037212318601125, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3}
|
||||
_count: 4
|
||||
triggerTime: 0.5
|
||||
_count: 2
|
||||
triggerTime: 0.1
|
||||
- groupSpawn:
|
||||
- _enemy: {fileID: 313037212318601125, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3}
|
||||
_count: 1
|
||||
|
||||
@ -6,7 +6,7 @@ public class WaveObserver : Singleton<WaveObserver>
|
||||
private List<SpawnerTile> _subjects = new List<SpawnerTile>();
|
||||
private List<float> _aliveEnemyCount = new List<float>();
|
||||
private List<int> _copyConstantSpawn;
|
||||
private List<GroupList> _copyGroupSpawn;
|
||||
private List<List<int>> _copyGroupSpawn;
|
||||
private List<float> _groupSpawnTimers;
|
||||
private WaveConfig _levelConfig;
|
||||
private const int MAXTOUGHNESS = 10;
|
||||
@ -19,7 +19,7 @@ public class WaveObserver : Singleton<WaveObserver>
|
||||
{
|
||||
_levelConfig = config;
|
||||
_copyConstantSpawn = new List<int>();
|
||||
_copyGroupSpawn = new List<GroupList>();
|
||||
_copyGroupSpawn = new List<List<int>>();
|
||||
_groupSpawnTimers = new List<float>();
|
||||
foreach (EnemyType enemy in _levelConfig.ConstantSpawn)
|
||||
{
|
||||
@ -27,7 +27,11 @@ public class WaveObserver : Singleton<WaveObserver>
|
||||
}
|
||||
for (int index = 0; index < _levelConfig.NestedGroupSpawn.Count; index++)
|
||||
{
|
||||
_copyGroupSpawn.Add(_levelConfig.NestedGroupSpawn[index]);
|
||||
_copyGroupSpawn.Add(new List<int>());
|
||||
for (int nestedIndex = 0; nestedIndex < _levelConfig.NestedGroupSpawn[index].groupSpawn.Count; nestedIndex++)
|
||||
{
|
||||
_copyGroupSpawn[index].Add(_levelConfig.NestedGroupSpawn[index].groupSpawn[nestedIndex].Count);
|
||||
}
|
||||
_groupSpawnTimers.Add(_levelConfig.NestedGroupSpawn[index].triggerTime);
|
||||
}
|
||||
}
|
||||
@ -158,16 +162,55 @@ public class WaveObserver : Singleton<WaveObserver>
|
||||
* Called when it is time to spawn a group
|
||||
* Assigns a random element of the group to a random spawner
|
||||
*/
|
||||
public void NotifyGroupSpawn()
|
||||
public bool NotifyGroupSpawn()
|
||||
{
|
||||
System.Random rand = new System.Random();
|
||||
foreach (EnemyType groupEnemy in _copyGroupSpawn[_currentGroupIndex].groupSpawn)
|
||||
List<int> usedRows = new List<int>();
|
||||
List<EnemyType> currentGroup = _levelConfig.NestedGroupSpawn[_currentGroupIndex].groupSpawn;
|
||||
for (int groupIndex = 0; groupIndex < currentGroup.Count; groupIndex++) //Loops through enemy groups
|
||||
{
|
||||
for (int i = 0; i < groupEnemy.Count; i++)
|
||||
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] == 0)
|
||||
if (usedRows.Count < _subjects.Count) //TODO: decreases actual count + goes into negatives
|
||||
{
|
||||
_subjects[rand.Next(_subjects.Count)].TriggerSpawn(groupEnemy.GetEnemyObject());
|
||||
for (int i = 0; i < _subjects.Count; i++) //Loops through spawners
|
||||
{
|
||||
bool breakTag = false;
|
||||
do
|
||||
{
|
||||
int currentRow = rand.Next(_subjects.Count);
|
||||
if (!usedRows.Contains(currentRow))
|
||||
{
|
||||
_subjects[rand.Next(_subjects.Count)].TriggerSpawn(currentGroup[groupIndex].GetEnemyObject());
|
||||
_copyGroupSpawn[_currentGroupIndex][groupIndex]--;
|
||||
Debug.Log(_copyGroupSpawn[_currentGroupIndex][groupIndex]);
|
||||
usedRows.Add(currentRow);
|
||||
}
|
||||
if(_copyGroupSpawn[_currentGroupIndex][groupIndex] == 0) //If current ennemy has reached count of 0
|
||||
{
|
||||
breakTag = true;
|
||||
break;
|
||||
}
|
||||
}while(usedRows.Count==i);
|
||||
Debug.Log("Row: " + usedRows.Count);
|
||||
if (breakTag)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] > 0) //If after doing evry row, there are still some left
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_currentGroupIndex++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ public class SpawnerTile : LevelTile
|
||||
private WaveObserver _observer;
|
||||
private bool _stopped = false;
|
||||
private bool _cooldownEnded = false;
|
||||
private bool _EnemiesCleared = true;
|
||||
private List<float> _groupSpawnTimers = new List<float>();
|
||||
|
||||
public void SetGroupSpawnTimers(List<float> groupSpawnTimers)
|
||||
@ -49,8 +50,16 @@ public class SpawnerTile : LevelTile
|
||||
{
|
||||
if (_lifetime / 60 > _groupSpawnTimers[0])
|
||||
{
|
||||
_groupSpawnTimers.RemoveAt(0);
|
||||
_observer.NotifyGroupSpawn();
|
||||
_EnemiesCleared = _observer.NotifyGroupSpawn();
|
||||
if (_EnemiesCleared)
|
||||
{
|
||||
_groupSpawnTimers.RemoveAt(0);
|
||||
Debug.Log("Next...");
|
||||
} else
|
||||
{
|
||||
_groupSpawnTimers[0] += 0.05f;
|
||||
Debug.Log("Timer: " + _groupSpawnTimers[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_spawnCounter < _spawnSpeed) return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user