Comments + variable structure

This commit is contained in:
Ader Alisma 01 2024-03-03 13:41:23 -05:00
parent bc4b4c30a8
commit bd28e30da5
3 changed files with 12 additions and 15 deletions

View File

@ -15,10 +15,10 @@ public class WaveConfig : ScriptableObject
[SerializeField] [SerializeField]
private List<GroupList> _nestedGroupSpawn = new List<GroupList>(); private List<GroupList> _nestedGroupSpawn = new List<GroupList>();
[SerializeField] [SerializeField]
private List<GameObject> _constraintList = new List<GameObject>(); //List of depleted enemies
private float _gameDuration = 1; private float _gameDuration = 1;
private float _enemySpawndOnStart = 0; private float _enemySpawndOnStart = 0;
private int _enemySum = 0; private int _enemySum = 0;
private List<GameObject> _constraintList = new List<GameObject>();
public List<EnemyType> ConstantSpawn public List<EnemyType> ConstantSpawn
{ {
get get
@ -57,6 +57,8 @@ public class WaveConfig : ScriptableObject
/** /**
* Returns a random enemy among the constantSpawn list * Returns a random enemy among the constantSpawn list
* Called when assigning a new enemy to a spawner
* <param name="constraint"> When given, ensures that assigned enemy hasn't depleted </param>
*/ */
public EnemyType GetRandomSpawn(GameObject constraint = null) public EnemyType GetRandomSpawn(GameObject constraint = null)
{ {
@ -76,7 +78,7 @@ public class WaveConfig : ScriptableObject
{ {
randomEnemy = _constantSpawn[Random.Range(0, _constantSpawn.Count)]; randomEnemy = _constantSpawn[Random.Range(0, _constantSpawn.Count)];
} while (_constraintList.Contains(randomEnemy.GetEnemyObject())); } while (_constraintList.Contains(randomEnemy.GetEnemyObject()));
return randomEnemy; return randomEnemy;
} else } else
{ {
return null; return null;

View File

@ -5,17 +5,18 @@ using UnityEngine;
public class WaveObserver : Singleton<WaveObserver> public class WaveObserver : Singleton<WaveObserver>
{ {
private const int MAXTOUGHNESS = 10;
private List<SpawnerTile> _subjects = new List<SpawnerTile>(); private List<SpawnerTile> _subjects = new List<SpawnerTile>();
private List<float> _aliveEnemyCount = new List<float>(); private List<float> _aliveEnemyCount = new List<float>();
private List<int> _copyConstantSpawn;
private List<List<int>> _copyGroupSpawn; //Contains count of enemies per group
private List<float> _groupSpawnTimers; private List<float> _groupSpawnTimers;
private WaveConfig _levelConfig; private List<int> _copyConstantSpawn;
private const int MAXTOUGHNESS = 10;
private int _spawnerTiming = 0;
private List<int> _intervalTiming = new List<int>(); private List<int> _intervalTiming = new List<int>();
private bool _once = true; private List<List<int>> _copyGroupSpawn; //Contains count of enemies per group
private WaveConfig _levelConfig;
private int _spawnerTiming = 0;
private int _currentGroupIndex = 0; private int _currentGroupIndex = 0;
private bool _once = true;
public void Init(WaveConfig config) public void Init(WaveConfig config)
{ {
@ -83,14 +84,12 @@ public class WaveObserver : Singleton<WaveObserver>
{ {
if (_copyConstantSpawn[spawnIndex] == 0) //Doesn't compare this iteration because it's already empty if (_copyConstantSpawn[spawnIndex] == 0) //Doesn't compare this iteration because it's already empty
{ {
Debug.Log("--I'm empty--");
continue; continue;
} }
if (paramPrefab.Equals(_levelConfig.ConstantSpawn[spawnIndex].GetEnemyObject())) if (paramPrefab.Equals(_levelConfig.ConstantSpawn[spawnIndex].GetEnemyObject()))
{ {
_copyConstantSpawn[spawnIndex]--; _copyConstantSpawn[spawnIndex]--;
Debug.Log("Amout to spawn is now: " + _copyConstantSpawn[spawnIndex]);
if (_copyConstantSpawn[spawnIndex] == 0) if (_copyConstantSpawn[spawnIndex] == 0)
{ {
foreach (SpawnerTile spawner in _subjects) foreach (SpawnerTile spawner in _subjects)
@ -101,12 +100,10 @@ public class WaveObserver : Singleton<WaveObserver>
if (randomEnemy?.GetEnemyObject() == spawner.Prefab || randomEnemy == null) if (randomEnemy?.GetEnemyObject() == spawner.Prefab || randomEnemy == null)
{ {
spawner.StopSpawn(); spawner.StopSpawn();
Debug.Log("----Spawn Stopped----");
} }
else else
{ {
spawner.Prefab = randomEnemy.GetEnemyObject(); spawner.Prefab = randomEnemy.GetEnemyObject();
Debug.Log("----Spawn Changed!!!----");
} }
} }
} }
@ -222,7 +219,7 @@ public class WaveObserver : Singleton<WaveObserver>
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] != 0) if (_copyGroupSpawn[_currentGroupIndex][groupIndex] != 0)
{ {
CycleRows(usedRows, currentGroup, groupIndex); CycleRows(usedRows, currentGroup, groupIndex);
/*If group is done OR max rows reached while group is not done*/ // If group is done OR max rows reached while group is not done
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] > 0 || (usedRows.Count == _subjects.Count && _copyGroupSpawn[_currentGroupIndex][groupIndex] > 0)) if (_copyGroupSpawn[_currentGroupIndex][groupIndex] > 0 || (usedRows.Count == _subjects.Count && _copyGroupSpawn[_currentGroupIndex][groupIndex] > 0))
{ {
return false; return false;

View File

@ -60,9 +60,7 @@ public class SpawnerTile : LevelTile
} }
} }
} }
//Debug.Log("Time: " + _spawnCounter);
if (_spawnCounter < _spawnSpeed) return; if (_spawnCounter < _spawnSpeed) return;
Debug.Log("Stopped but still spawning");
_spawnCounter = 0; _spawnCounter = 0;
if (!_cooldownEnded) if (!_cooldownEnded)
{ {