diff --git a/Assets/Editor/WaveConfigCustomInspector.cs b/Assets/Editor/WaveConfigCustomInspector.cs index 13bc681..8ee92ad 100644 --- a/Assets/Editor/WaveConfigCustomInspector.cs +++ b/Assets/Editor/WaveConfigCustomInspector.cs @@ -9,13 +9,13 @@ namespace GatherAndDefend.LevelEditor public override void OnInspectorGUI() { EditorGUILayout.HelpBox(@"How to use : -- ConstantSpawn: Drag l'ennemi choisi dans Enemy et insérer le nombre à créer dans Count -- GameDuration : Le temps du jeu, en minutes -- Utilité : Déposez cette configuration dans le niveau de votre choix -- L'intervalle de création est déterminé d'après la durée du jeux et le nombre d'ennemi à créer +- ConstantSpawn: Drag the chosen Enemy and insert the number to make in Count +- GameDuration : Duration of the game, in minutes +- Usage : Drop this config into a level +- Creation interval is determined by the game duration and the number of enemies to create -Importante consideration : -- Il faut assigner au moins un ennemi avec un Count d'au moins 1 pour jouer.", MessageType.None); +Important consideration : +- You must assign at least 1 enemy of Count of at least 1 to play.", MessageType.None); base.OnInspectorGUI(); } } diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs index 2ff5a79..060d5cf 100644 --- a/Assets/Scripts/LevelConfig/WaveObserver.cs +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -4,8 +4,10 @@ using UnityEngine; public class WaveObserver : Singleton { private List _subjects = new List(); + private List _aliveEnemyCount = new List(); private List _copyConstantSpawn; private WaveConfig _levelConfig; + private const int MAXENEMYCOUNT = 3; public WaveConfig LevelConfig { set @@ -24,6 +26,7 @@ public class WaveObserver : Singleton spawnerSubject.Prefab = _levelConfig.GetRandomSpawn().GetEnemyObject(); spawnerSubject.InitialSpawnSpeed(_levelConfig.GetInterval()); _subjects.Add(spawnerSubject); + _aliveEnemyCount.Add(0); } public void NotifySpawned(SpawnerTile spawnerSubject) @@ -53,4 +56,32 @@ public class WaveObserver : Singleton } } } + + 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"); + } } diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index 14a2451..4e2dd35 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -7,6 +7,7 @@ public class Opponent : Entity private Vector2 _movementVector = Vector2.zero; private Rigidbody2D _rigidbody; + private WaveObserver _observer; public override void Start() { @@ -14,6 +15,8 @@ public class Opponent : Entity _rigidbody = GetComponent(); Animation = gameObject.AddComponent(); + _observer = WaveObserver.Instance; + _observer.NotifyEnemy(transform.position.y); } void Update() diff --git a/Assets/Scripts/Tiles/SpawnerTile.cs b/Assets/Scripts/Tiles/SpawnerTile.cs index f73ac52..3cd94d4 100644 --- a/Assets/Scripts/Tiles/SpawnerTile.cs +++ b/Assets/Scripts/Tiles/SpawnerTile.cs @@ -17,6 +17,7 @@ public class SpawnerTile : LevelTile private float _initialSpawnSpeed; private const float MAX_SPAWN_SPEED = 0.01f; private const float RANDOM_MODIFIER = 5.0f; + private bool stopped = false; public override void LevelStart() @@ -32,12 +33,15 @@ public class SpawnerTile : LevelTile public override void LevelUpdate() { _lifetime += Time.deltaTime; - _spawnCounter += Time.deltaTime * _spawnSpeed; + if (!stopped) + { + _spawnCounter += Time.deltaTime * _spawnSpeed; + } if (_spawnCounter < 1) return; _spawnCounter = 0; _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); } public override bool Equals(ILevelObject other) @@ -61,9 +65,16 @@ public class SpawnerTile : LevelTile internal void StopSpawn() { - _spawnSpeed = 0.0f; + stopped = true; + Debug.Log("I STOPPED, GAWSH!!!"); } + internal void StartSpawn() + { + stopped = false; + } + + public override void LoadDictionary(Dictionary dict) { base.LoadDictionary(dict); @@ -91,6 +102,6 @@ public class SpawnerTile : LevelTile public void InitialSpawnSpeed(float 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); } } \ No newline at end of file