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:
parent
35f0796ad1
commit
a0aa9cfb64
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,8 +4,10 @@ using UnityEngine;
|
||||
public class WaveObserver : Singleton<WaveObserver>
|
||||
{
|
||||
private List<SpawnerTile> _subjects = new List<SpawnerTile>();
|
||||
private List<int> _aliveEnemyCount = new List<int>();
|
||||
private List<int> _copyConstantSpawn;
|
||||
private WaveConfig _levelConfig;
|
||||
private const int MAXENEMYCOUNT = 3;
|
||||
public WaveConfig LevelConfig
|
||||
{
|
||||
set
|
||||
@ -24,6 +26,7 @@ public class WaveObserver : Singleton<WaveObserver>
|
||||
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<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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Rigidbody2D>();
|
||||
Animation = gameObject.AddComponent<AnimationEntity>();
|
||||
_observer = WaveObserver.Instance;
|
||||
_observer.NotifyEnemy(transform.position.y);
|
||||
}
|
||||
|
||||
void Update()
|
||||
|
||||
@ -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<string, object> 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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user