Changed comments to english

Added a limit to how many monsters are created per lane
Unfixed issue where SpawnOnStart breaks the system
This commit is contained in:
Ader Alisma 01 2023-08-06 18:27:23 -04:00
parent 35f0796ad1
commit a0aa9cfb64
4 changed files with 55 additions and 10 deletions

View File

@ -9,13 +9,13 @@ namespace GatherAndDefend.LevelEditor
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
EditorGUILayout.HelpBox(@"How to use : EditorGUILayout.HelpBox(@"How to use :
- ConstantSpawn: Drag l'ennemi choisi dans Enemy et insérer le nombre à créer dans Count - ConstantSpawn: Drag the chosen Enemy and insert the number to make in Count
- GameDuration : Le temps du jeu, en minutes - GameDuration : Duration of the game, in minutes
- Utilité : Déposez cette configuration dans le niveau de votre choix - Usage : Drop this config into a level
- L'intervalle de création est déterminé d'après la durée du jeux et le nombre d'ennemi à créer - Creation interval is determined by the game duration and the number of enemies to create
Importante consideration : Important consideration :
- Il faut assigner au moins un ennemi avec un Count d'au moins 1 pour jouer.", MessageType.None); - You must assign at least 1 enemy of Count of at least 1 to play.", MessageType.None);
base.OnInspectorGUI(); base.OnInspectorGUI();
} }
} }

View File

@ -4,8 +4,10 @@ using UnityEngine;
public class WaveObserver : Singleton<WaveObserver> public class WaveObserver : Singleton<WaveObserver>
{ {
private List<SpawnerTile> _subjects = new List<SpawnerTile>(); private List<SpawnerTile> _subjects = new List<SpawnerTile>();
private List<int> _aliveEnemyCount = new List<int>();
private List<int> _copyConstantSpawn; private List<int> _copyConstantSpawn;
private WaveConfig _levelConfig; private WaveConfig _levelConfig;
private const int MAXENEMYCOUNT = 3;
public WaveConfig LevelConfig public WaveConfig LevelConfig
{ {
set set
@ -24,6 +26,7 @@ public class WaveObserver : Singleton<WaveObserver>
spawnerSubject.Prefab = _levelConfig.GetRandomSpawn().GetEnemyObject(); spawnerSubject.Prefab = _levelConfig.GetRandomSpawn().GetEnemyObject();
spawnerSubject.InitialSpawnSpeed(_levelConfig.GetInterval()); spawnerSubject.InitialSpawnSpeed(_levelConfig.GetInterval());
_subjects.Add(spawnerSubject); _subjects.Add(spawnerSubject);
_aliveEnemyCount.Add(0);
} }
public void NotifySpawned(SpawnerTile spawnerSubject) public void NotifySpawned(SpawnerTile spawnerSubject)
@ -53,4 +56,32 @@ public class WaveObserver : Singleton<WaveObserver>
} }
} }
} }
public int NotifyEnemy(float yPosition)
{
for (int i = 0; i < _subjects.Count; i++)
{
if(_subjects[i].Position.y == yPosition)
{
_aliveEnemyCount[i]++;
if(_aliveEnemyCount[i] >= MAXENEMYCOUNT)
{
_subjects[i].StopSpawn();
}
Debug.Log("Made in: " + i + ". In count of : " + _aliveEnemyCount[i]);
return i;
}
}
return -1;
}
public void NotifyDies(int position)
{
if(_aliveEnemyCount[position] >= MAXENEMYCOUNT)
{
_subjects[position].StartSpawn();
}
_aliveEnemyCount[position]--;
Debug.Log("RIP");
}
} }

View File

@ -7,6 +7,7 @@ public class Opponent : Entity
private Vector2 _movementVector = Vector2.zero; private Vector2 _movementVector = Vector2.zero;
private Rigidbody2D _rigidbody; private Rigidbody2D _rigidbody;
private WaveObserver _observer;
public override void Start() public override void Start()
{ {
@ -14,6 +15,8 @@ public class Opponent : Entity
_rigidbody = GetComponent<Rigidbody2D>(); _rigidbody = GetComponent<Rigidbody2D>();
Animation = gameObject.AddComponent<AnimationEntity>(); Animation = gameObject.AddComponent<AnimationEntity>();
_observer = WaveObserver.Instance;
_observer.NotifyEnemy(transform.position.y);
} }
void Update() void Update()

View File

@ -17,6 +17,7 @@ public class SpawnerTile : LevelTile
private float _initialSpawnSpeed; private float _initialSpawnSpeed;
private const float MAX_SPAWN_SPEED = 0.01f; private const float MAX_SPAWN_SPEED = 0.01f;
private const float RANDOM_MODIFIER = 5.0f; private const float RANDOM_MODIFIER = 5.0f;
private bool stopped = false;
public override void LevelStart() public override void LevelStart()
@ -32,12 +33,15 @@ public class SpawnerTile : LevelTile
public override void LevelUpdate() public override void LevelUpdate()
{ {
_lifetime += Time.deltaTime; _lifetime += Time.deltaTime;
_spawnCounter += Time.deltaTime * _spawnSpeed; if (!stopped)
{
_spawnCounter += Time.deltaTime * _spawnSpeed;
}
if (_spawnCounter < 1) return; if (_spawnCounter < 1) return;
_spawnCounter = 0; _spawnCounter = 0;
_prefab.Create(Position, parent: LevelManager.Instance.LevelTransform); _prefab.Create(Position, parent: LevelManager.Instance.LevelTransform);
_spawnSpeed = Mathf.Max(_initialSpawnSpeed / Random.Range(0.0f, RANDOM_MODIFIER), MAX_SPAWN_SPEED); _spawnSpeed = Mathf.Max(_initialSpawnSpeed / Random.Range(1.0f, RANDOM_MODIFIER), MAX_SPAWN_SPEED);
_observer.NotifySpawned(this); _observer.NotifySpawned(this);
} }
public override bool Equals(ILevelObject other) public override bool Equals(ILevelObject other)
@ -61,9 +65,16 @@ public class SpawnerTile : LevelTile
internal void StopSpawn() internal void StopSpawn()
{ {
_spawnSpeed = 0.0f; stopped = true;
Debug.Log("I STOPPED, GAWSH!!!");
} }
internal void StartSpawn()
{
stopped = false;
}
public override void LoadDictionary(Dictionary<string, object> dict) public override void LoadDictionary(Dictionary<string, object> dict)
{ {
base.LoadDictionary(dict); base.LoadDictionary(dict);
@ -91,6 +102,6 @@ public class SpawnerTile : LevelTile
public void InitialSpawnSpeed(float value) public void InitialSpawnSpeed(float value)
{ {
_initialSpawnSpeed = value; _initialSpawnSpeed = value;
_spawnSpeed = Mathf.Max(_initialSpawnSpeed / Random.Range(0.0f, RANDOM_MODIFIER - 2.0f), MAX_SPAWN_SPEED); _spawnSpeed = Mathf.Max(_initialSpawnSpeed / Random.Range(1.0f, RANDOM_MODIFIER - 2.0f), MAX_SPAWN_SPEED);
} }
} }