From 15b5976cb07b8a44ec1e3b9c947638c1cccf5499 Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sun, 9 Jul 2023 18:59:37 -0400 Subject: [PATCH 01/12] Debut Wave Editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LevelConfig cnotient la liste des ennemies à spawn à un rythme constant ainsi que la durée du jeux EnemyType contient l'ennemi ainsi que la quantité à SpawnerTile Modifications de Level et TilemapData afin d'accéder aux paramètres des Spawners du jeu --- Assets/LevelConfig.meta | 8 +++++ Assets/Scripts/LevelConfig.meta | 8 +++++ Assets/Scripts/LevelConfig/LevelConfig.cs | 16 ++++++++++ .../Scripts/LevelConfig/LevelConfig.cs.meta | 11 +++++++ Assets/Scripts/LevelEditor/Level.cs | 6 ++-- Assets/Scripts/LevelEditor/TilemapData.cs | 16 ++++++++-- Assets/Scripts/Opponent/EnemyType.cs | 31 +++++++++++++++++++ Assets/Scripts/Opponent/EnemyType.cs.meta | 11 +++++++ Assets/Scripts/PlayerAction/ClickBehavior.cs | 2 +- Assets/Scripts/Tiles/SpawnerTile.cs | 4 +++ 10 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 Assets/LevelConfig.meta create mode 100644 Assets/Scripts/LevelConfig.meta create mode 100644 Assets/Scripts/LevelConfig/LevelConfig.cs create mode 100644 Assets/Scripts/LevelConfig/LevelConfig.cs.meta create mode 100644 Assets/Scripts/Opponent/EnemyType.cs create mode 100644 Assets/Scripts/Opponent/EnemyType.cs.meta diff --git a/Assets/LevelConfig.meta b/Assets/LevelConfig.meta new file mode 100644 index 0000000..b7bd07b --- /dev/null +++ b/Assets/LevelConfig.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b3ad07c069cd06e4ebbd5f190b9aa25b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/LevelConfig.meta b/Assets/Scripts/LevelConfig.meta new file mode 100644 index 0000000..f06a54d --- /dev/null +++ b/Assets/Scripts/LevelConfig.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a386aeb53fe226d41bbee33ac6fafa4e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/LevelConfig/LevelConfig.cs b/Assets/Scripts/LevelConfig/LevelConfig.cs new file mode 100644 index 0000000..02e5054 --- /dev/null +++ b/Assets/Scripts/LevelConfig/LevelConfig.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[CreateAssetMenu(menuName = "Gather And Defend/Levels/LevelConfig")] +public class LevelConfig : ScriptableObject +{ + //IEnumerable for 1. list of type 2. timer. with title of row nbr INSPIRED FROM DATA + [SerializeField] + private List _constantSpawn = new List(); + [SerializeField] + private int _gameDuration = 0; + public List ConstantSpawn { get { return _constantSpawn; } } + public int GameDuration { get { return _gameDuration; } } + +} diff --git a/Assets/Scripts/LevelConfig/LevelConfig.cs.meta b/Assets/Scripts/LevelConfig/LevelConfig.cs.meta new file mode 100644 index 0000000..4c684ab --- /dev/null +++ b/Assets/Scripts/LevelConfig/LevelConfig.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eb0795e326609f0499365f5b65c2b5cd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/LevelEditor/Level.cs b/Assets/Scripts/LevelEditor/Level.cs index 73d7bb8..fe4463b 100644 --- a/Assets/Scripts/LevelEditor/Level.cs +++ b/Assets/Scripts/LevelEditor/Level.cs @@ -11,6 +11,8 @@ namespace GatherAndDefend.LevelEditor public Rect Bounds => _bounds; [SerializeField] private List _data = new List(); + [SerializeField] + private LevelConfig _levelConfig; public void SaveFromTilemap(Tilemap tilemap) { var data = new TilemapData(); @@ -21,8 +23,8 @@ namespace GatherAndDefend.LevelEditor { var data = _data.Find(x => x.Key == tilemap.name); if (data == null) return; - - data.LoadToTilemap(tilemap); + + data.LoadToTilemap(tilemap, _levelConfig); } public IEnumerator GetEnumerator() diff --git a/Assets/Scripts/LevelEditor/TilemapData.cs b/Assets/Scripts/LevelEditor/TilemapData.cs index d0e20c7..68b0f17 100644 --- a/Assets/Scripts/LevelEditor/TilemapData.cs +++ b/Assets/Scripts/LevelEditor/TilemapData.cs @@ -33,7 +33,7 @@ namespace GatherAndDefend.LevelEditor public string Key => _key; - public void LoadToTilemap(Tilemap reference) + public void LoadToTilemap(Tilemap reference, LevelConfig _levelConfig = null) { reference.transform.localPosition = _position; reference.transform.localScale = _scale; @@ -48,10 +48,22 @@ namespace GatherAndDefend.LevelEditor collision.isTrigger = _isTrigger; } - + Debug.Log(_levelConfig != null); + if ( _levelConfig != null && _key.Equals("Spawners")) + { + foreach (TileData spawner in _tiles) + { + //string id = spawner.Tile.GetInstanceID().ToString(); + //SpawnerTile spawnerGO = GameObject.Find(id).GetComponent(); + //spawnerGO.Prefab = _levelConfig.ConstantSpawn[0].GetEnemyObject(); + Debug.Log("____GODLIKE____"); + } + } foreach (TileData data in _tiles) { reference.SetTile(data.Position, data.Tile); + Debug.Log(_key.ToString()); + } } /// diff --git a/Assets/Scripts/Opponent/EnemyType.cs b/Assets/Scripts/Opponent/EnemyType.cs new file mode 100644 index 0000000..d32109f --- /dev/null +++ b/Assets/Scripts/Opponent/EnemyType.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System; + + +[Serializable] +public class EnemyType +{ + [SerializeField] + private Opponent _enemy; + [SerializeField] + private int _count; + + public int GetEnemyToughness() + { + float toughness = Mathf.Round((_enemy.Hp / 10) + _enemy.AttackDamage / 2); + return (int)toughness; + } + + public GameObject GetEnemyObject() + { + return _enemy.gameObject; + } + + public int GetEnemyCount() + { + return _count; + } + +} diff --git a/Assets/Scripts/Opponent/EnemyType.cs.meta b/Assets/Scripts/Opponent/EnemyType.cs.meta new file mode 100644 index 0000000..981da41 --- /dev/null +++ b/Assets/Scripts/Opponent/EnemyType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a747157705819b94499ad98134da8f88 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerAction/ClickBehavior.cs b/Assets/Scripts/PlayerAction/ClickBehavior.cs index 99d0ad0..a48c486 100644 --- a/Assets/Scripts/PlayerAction/ClickBehavior.cs +++ b/Assets/Scripts/PlayerAction/ClickBehavior.cs @@ -9,7 +9,7 @@ public class ClickBehavior : MonoBehaviour if (Input.GetMouseButton(0)) { Vector2 clickPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); - RaycastHit2D hit = Physics2D.Raycast(clickPoint, transform.up); + RaycastHit2D hit = Physics2D.Raycast(clickPoint, transform.up, 0.0f); if (hit.collider != null) { if (hit.collider.CompareTag("Resource")) diff --git a/Assets/Scripts/Tiles/SpawnerTile.cs b/Assets/Scripts/Tiles/SpawnerTile.cs index d281933..1646d21 100644 --- a/Assets/Scripts/Tiles/SpawnerTile.cs +++ b/Assets/Scripts/Tiles/SpawnerTile.cs @@ -61,4 +61,8 @@ public class SpawnerTile : LevelTile _lifetime = dict[nameof(_lifetime)].ToFloat(); _spawnOnStart = dict[nameof(_spawnOnStart)].ToBool(); } + + public GameObject Prefab { set { + Debug.Log("Changed"); + _prefab = value; } } } \ No newline at end of file From d75a1ec747aa66113c1608e44605ac342f3bc813 Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Fri, 14 Jul 2023 19:44:07 -0400 Subject: [PATCH 02/12] =?UTF-8?q?Progr=C3=A8s=20WaveEditor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WaveObserver donne aux spawners les unités à instancier ainsi que l'intervalle de création de ceux-ci LevelConfig passe de Level vers LevelManager puis il est utilisé dans l'instance de WaveObserver --- Assets/LevelEditor/Levels/TestDrag&Drop.asset | 4 + Assets/Scripts/LevelConfig/LevelConfig.cs | 38 +++++++++- Assets/Scripts/LevelConfig/WaveObserver.cs | 74 +++++++++++++++++++ .../Scripts/LevelConfig/WaveObserver.cs.meta | 11 +++ Assets/Scripts/LevelEditor/Level.cs | 7 +- Assets/Scripts/LevelEditor/TilemapData.cs | 15 +--- Assets/Scripts/LevelManager/LevelManager.cs | 5 ++ Assets/Scripts/Opponent/EnemyType.cs | 8 +- Assets/Scripts/Tiles/SpawnerTile.cs | 23 +++++- 9 files changed, 156 insertions(+), 29 deletions(-) create mode 100644 Assets/Scripts/LevelConfig/WaveObserver.cs create mode 100644 Assets/Scripts/LevelConfig/WaveObserver.cs.meta diff --git a/Assets/LevelEditor/Levels/TestDrag&Drop.asset b/Assets/LevelEditor/Levels/TestDrag&Drop.asset index e3e45d9..b206bd0 100644 --- a/Assets/LevelEditor/Levels/TestDrag&Drop.asset +++ b/Assets/LevelEditor/Levels/TestDrag&Drop.asset @@ -309,6 +309,7 @@ MonoBehaviour: _position: {x: 10, y: 1, z: 0} - _tile: {fileID: 11400000, guid: ef5a154519b23a34aaded32e86bf7f2f, type: 2} _position: {x: 10, y: 2, z: 0} + _isSpawner: 0 _isInvisible: 0 _isCollidable: 0 _isTrigger: 0 @@ -318,6 +319,7 @@ MonoBehaviour: _scale: {x: 1, y: 1} - _key: Entities _tiles: [] + _isSpawner: 0 _isInvisible: 0 _isCollidable: 0 _isTrigger: 0 @@ -343,6 +345,7 @@ MonoBehaviour: _position: {x: 10, y: 0, z: 0} - _tile: {fileID: 11400000, guid: 4002377ed7e87b34699f126f2b10c703, type: 2} _position: {x: 10, y: 2, z: 0} + _isSpawner: 0 _isInvisible: 0 _isCollidable: 0 _isTrigger: 0 @@ -350,3 +353,4 @@ MonoBehaviour: _renderLayer: Default _position: {x: 0, y: 0} _scale: {x: 1, y: 1} + _waveConfig: {fileID: 11400000, guid: 21b0f85f7c746974db1e72f2df646f5d, type: 2} diff --git a/Assets/Scripts/LevelConfig/LevelConfig.cs b/Assets/Scripts/LevelConfig/LevelConfig.cs index 02e5054..2bdec54 100644 --- a/Assets/Scripts/LevelConfig/LevelConfig.cs +++ b/Assets/Scripts/LevelConfig/LevelConfig.cs @@ -5,12 +5,42 @@ using UnityEngine; [CreateAssetMenu(menuName = "Gather And Defend/Levels/LevelConfig")] public class LevelConfig : ScriptableObject { - //IEnumerable for 1. list of type 2. timer. with title of row nbr INSPIRED FROM DATA [SerializeField] private List _constantSpawn = new List(); [SerializeField] - private int _gameDuration = 0; - public List ConstantSpawn { get { return _constantSpawn; } } - public int GameDuration { get { return _gameDuration; } } + private float _gameDuration = 0; + public List ConstantSpawn + { + get + { + return _constantSpawn; + } + } + public float GameDuration + { + get + { + float interval = SumCount().ToFloat() / _gameDuration * 0.01f; + return interval; + } + } + public EnemyType GetRandomSpawn() + { + if (_constantSpawn.Count == 1) + { + return _constantSpawn[0]; + } + return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)]; + } + + private int SumCount() + { + int sum = 0; + foreach (EnemyType enemy in _constantSpawn) + { + sum += enemy.Count; + } + return sum; + } } diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs new file mode 100644 index 0000000..bbcc802 --- /dev/null +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -0,0 +1,74 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class WaveObserver : Singleton +{ + private List _subjects = new List(); + private LevelConfig _levelConfig; + public LevelConfig LevelConfig { set { _levelConfig = value; } } + private float[] _delay = {0,1,2,3,4,5}; + private float _currentToughness = 0; + private int _gameProgress = 0; + private int _maxSync = 6; + + public void Attach(SpawnerTile spawnerSubject) + { + spawnerSubject.Prefab = _levelConfig.GetRandomSpawn().GetEnemyObject(); + WaveUpdate(spawnerSubject); + _subjects.Add(spawnerSubject); + } + + public void NotifySpawned(SpawnerTile spawnerSubject) + { + if (spawnerSubject.Prefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject())) + { + int currentCount = _levelConfig.ConstantSpawn[0].Count; + if (currentCount == 0) + { + foreach (SpawnerTile spawner in _subjects) + { + if (spawner.Prefab.Equals(spawnerSubject.Prefab)) + { + //spawner.SpawnSpeed = 0.0f; + } + } + } + } + } + + public void WaveUpdate(SpawnerTile spawnerSubject) + { + //Lottery of order. Reducing maxSync increases the chances team spawning + int spawningOrder = Random.Range(1, _maxSync); + Debug.Log("Je suis " + spawningOrder + "e de la liste."); + switch (spawningOrder) + { + case 1: + spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[0]; + break; + case 2: + spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[1]; + break; + case 3: + spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[2]; + break; + case 4: + spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[3]; + break; + case 5: + spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[4]; + break; + case 6: + spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[5]; + break; + } + _gameProgress++; + + if(_gameProgress == _maxSync) + { + _maxSync--; + _gameProgress = 0; + } + } +} diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs.meta b/Assets/Scripts/LevelConfig/WaveObserver.cs.meta new file mode 100644 index 0000000..f704317 --- /dev/null +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6eab34a14c5d4d746a70792d4d7914a2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/LevelEditor/Level.cs b/Assets/Scripts/LevelEditor/Level.cs index fe4463b..62505d5 100644 --- a/Assets/Scripts/LevelEditor/Level.cs +++ b/Assets/Scripts/LevelEditor/Level.cs @@ -12,7 +12,7 @@ namespace GatherAndDefend.LevelEditor [SerializeField] private List _data = new List(); [SerializeField] - private LevelConfig _levelConfig; + private LevelConfig _waveConfig; public void SaveFromTilemap(Tilemap tilemap) { var data = new TilemapData(); @@ -23,9 +23,10 @@ namespace GatherAndDefend.LevelEditor { var data = _data.Find(x => x.Key == tilemap.name); if (data == null) return; - - data.LoadToTilemap(tilemap, _levelConfig); + + data.LoadToTilemap(tilemap); } + public LevelConfig WaveConfig { get { return _waveConfig; } } public IEnumerator GetEnumerator() { diff --git a/Assets/Scripts/LevelEditor/TilemapData.cs b/Assets/Scripts/LevelEditor/TilemapData.cs index 68b0f17..20cf7c2 100644 --- a/Assets/Scripts/LevelEditor/TilemapData.cs +++ b/Assets/Scripts/LevelEditor/TilemapData.cs @@ -33,7 +33,7 @@ namespace GatherAndDefend.LevelEditor public string Key => _key; - public void LoadToTilemap(Tilemap reference, LevelConfig _levelConfig = null) + public void LoadToTilemap(Tilemap reference) { reference.transform.localPosition = _position; reference.transform.localScale = _scale; @@ -48,22 +48,9 @@ namespace GatherAndDefend.LevelEditor collision.isTrigger = _isTrigger; } - Debug.Log(_levelConfig != null); - if ( _levelConfig != null && _key.Equals("Spawners")) - { - foreach (TileData spawner in _tiles) - { - //string id = spawner.Tile.GetInstanceID().ToString(); - //SpawnerTile spawnerGO = GameObject.Find(id).GetComponent(); - //spawnerGO.Prefab = _levelConfig.ConstantSpawn[0].GetEnemyObject(); - Debug.Log("____GODLIKE____"); - } - } foreach (TileData data in _tiles) { reference.SetTile(data.Position, data.Tile); - Debug.Log(_key.ToString()); - } } /// diff --git a/Assets/Scripts/LevelManager/LevelManager.cs b/Assets/Scripts/LevelManager/LevelManager.cs index 8c159b3..620c494 100644 --- a/Assets/Scripts/LevelManager/LevelManager.cs +++ b/Assets/Scripts/LevelManager/LevelManager.cs @@ -20,6 +20,7 @@ public class LevelManager : Singleton private readonly List _toAdd; private readonly List _toRemove; private readonly List _levelObjects; + private WaveObserver _waveObserver; private Tilemap _dynamicTilemap; public Tilemap DynamicTilemap @@ -162,6 +163,10 @@ public class LevelManager : Singleton tilemap.transform.SetParent(grid.transform); } Debug.Log("level loaded successfully"); + + Debug.Log("Decompte = " + _currentLevel.WaveConfig.GameDuration); + _waveObserver = WaveObserver.Instance; + _waveObserver.LevelConfig = _currentLevel.WaveConfig; } /// diff --git a/Assets/Scripts/Opponent/EnemyType.cs b/Assets/Scripts/Opponent/EnemyType.cs index d32109f..a7f8e3f 100644 --- a/Assets/Scripts/Opponent/EnemyType.cs +++ b/Assets/Scripts/Opponent/EnemyType.cs @@ -14,7 +14,7 @@ public class EnemyType public int GetEnemyToughness() { - float toughness = Mathf.Round((_enemy.Hp / 10) + _enemy.AttackDamage / 2); + float toughness = Mathf.Round((_enemy.Hp / 10) / 2); return (int)toughness; } @@ -22,10 +22,10 @@ public class EnemyType { return _enemy.gameObject; } - - public int GetEnemyCount() + public int Count { - return _count; + get { return _count; } + set { _count = value; } } } diff --git a/Assets/Scripts/Tiles/SpawnerTile.cs b/Assets/Scripts/Tiles/SpawnerTile.cs index 1646d21..7890ec7 100644 --- a/Assets/Scripts/Tiles/SpawnerTile.cs +++ b/Assets/Scripts/Tiles/SpawnerTile.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; [CreateAssetMenu(menuName = "Gather And Defend/Spawner Tile")] -public class SpawnerTile : LevelTile +public class SpawnerTile : LevelTile, IWaveSubject { [SerializeField] private GameObject _prefab; @@ -13,13 +13,17 @@ public class SpawnerTile : LevelTile private float _spawnSpeed = 0; [SerializeField, Range(0, 1.001f)] private float _spawnCounter = 0; + private WaveObserver _observer; public override void LevelStart() { + _observer = WaveObserver.Instance; + _observer.Attach(this); if (_spawnOnStart && _lifetime <= 0) { _prefab.Create(Position, parent: LevelManager.Instance.LevelTransform); + _observer.NotifySpawned(this); } } @@ -31,6 +35,7 @@ public class SpawnerTile : LevelTile _spawnCounter = 0; _prefab.Create(Position, parent: LevelManager.Instance.LevelTransform); + _observer.NotifySpawned(this); } public override bool Equals(ILevelObject other) { @@ -62,7 +67,17 @@ public class SpawnerTile : LevelTile _spawnOnStart = dict[nameof(_spawnOnStart)].ToBool(); } - public GameObject Prefab { set { - Debug.Log("Changed"); - _prefab = value; } } + public GameObject Prefab + { + set + { + _prefab = value; + } + get + { + return _prefab; + } + } + + public float SpawnSpeed { set { _spawnSpeed = value; } } } \ No newline at end of file From cad24367737905ffad0bc182b5a8c5b53c3e4faf Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Fri, 14 Jul 2023 23:15:18 -0400 Subject: [PATCH 03/12] =?UTF-8?q?Progr=C3=A8s=20WaveEditor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WaveObserver gère le nombre d'ennemi à créer et assure d'arreter la création d'ennemis supplémentaires. SpawnerTile détermine un intervalle aléatoire automatiquement après chaque création d'ennemi. La première intervalle a plus de chance d'être plus courte que les intervalles suivantes. Config01 est le scriptable object de type LevelConfig Suppression de commentaires de tests --- Assets/LevelConfig/Config01.asset | 18 ++++++ Assets/LevelConfig/Config01.asset.meta | 8 +++ Assets/Scripts/LevelConfig/LevelConfig.cs | 9 +-- Assets/Scripts/LevelConfig/WaveObserver.cs | 69 ++++++++------------- Assets/Scripts/LevelManager/LevelManager.cs | 6 +- Assets/Scripts/Tiles/SpawnerTile.cs | 19 +++++- 6 files changed, 72 insertions(+), 57 deletions(-) create mode 100644 Assets/LevelConfig/Config01.asset create mode 100644 Assets/LevelConfig/Config01.asset.meta diff --git a/Assets/LevelConfig/Config01.asset b/Assets/LevelConfig/Config01.asset new file mode 100644 index 0000000..827612f --- /dev/null +++ b/Assets/LevelConfig/Config01.asset @@ -0,0 +1,18 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: eb0795e326609f0499365f5b65c2b5cd, type: 3} + m_Name: Config01 + m_EditorClassIdentifier: + _constantSpawn: + - _enemy: {fileID: 313037212318601125, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3} + _count: 20 + _gameDuration: 3 diff --git a/Assets/LevelConfig/Config01.asset.meta b/Assets/LevelConfig/Config01.asset.meta new file mode 100644 index 0000000..7ed0ea8 --- /dev/null +++ b/Assets/LevelConfig/Config01.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 21b0f85f7c746974db1e72f2df646f5d +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/LevelConfig/LevelConfig.cs b/Assets/Scripts/LevelConfig/LevelConfig.cs index 2bdec54..288da83 100644 --- a/Assets/Scripts/LevelConfig/LevelConfig.cs +++ b/Assets/Scripts/LevelConfig/LevelConfig.cs @@ -16,13 +16,10 @@ public class LevelConfig : ScriptableObject return _constantSpawn; } } - public float GameDuration + public float GetInterval() { - get - { - float interval = SumCount().ToFloat() / _gameDuration * 0.01f; - return interval; - } + float interval = SumCount().ToFloat() / _gameDuration * 0.01f; + return interval; } public EnemyType GetRandomSpawn() { diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs index bbcc802..5c70b21 100644 --- a/Assets/Scripts/LevelConfig/WaveObserver.cs +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -5,17 +5,25 @@ using UnityEngine; public class WaveObserver : Singleton { private List _subjects = new List(); + private List _copyConstantSpawn; private LevelConfig _levelConfig; - public LevelConfig LevelConfig { set { _levelConfig = value; } } - private float[] _delay = {0,1,2,3,4,5}; - private float _currentToughness = 0; - private int _gameProgress = 0; - private int _maxSync = 6; + public LevelConfig LevelConfig + { + set + { + _levelConfig = value; + _copyConstantSpawn = new List(); + foreach (EnemyType enemy in _levelConfig.ConstantSpawn) + { + _copyConstantSpawn.Add(enemy.Count); + } + } + } public void Attach(SpawnerTile spawnerSubject) { spawnerSubject.Prefab = _levelConfig.GetRandomSpawn().GetEnemyObject(); - WaveUpdate(spawnerSubject); + spawnerSubject.InitialSpawnSpeed(_levelConfig.GetInterval()); _subjects.Add(spawnerSubject); } @@ -23,52 +31,25 @@ public class WaveObserver : Singleton { if (spawnerSubject.Prefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject())) { - int currentCount = _levelConfig.ConstantSpawn[0].Count; - if (currentCount == 0) + int currentCount = 0; + for (int i = 0; i < _copyConstantSpawn.Count; i++) + { + if(_levelConfig.ConstantSpawn[i].GetEnemyObject() == spawnerSubject.Prefab) + { + currentCount = _copyConstantSpawn[i]--; + break; + } + } + if (currentCount <= 0) { foreach (SpawnerTile spawner in _subjects) { if (spawner.Prefab.Equals(spawnerSubject.Prefab)) { - //spawner.SpawnSpeed = 0.0f; + spawner.StopSpawn(); } } } } } - - public void WaveUpdate(SpawnerTile spawnerSubject) - { - //Lottery of order. Reducing maxSync increases the chances team spawning - int spawningOrder = Random.Range(1, _maxSync); - Debug.Log("Je suis " + spawningOrder + "e de la liste."); - switch (spawningOrder) - { - case 1: - spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[0]; - break; - case 2: - spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[1]; - break; - case 3: - spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[2]; - break; - case 4: - spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[3]; - break; - case 5: - spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[4]; - break; - case 6: - spawnerSubject.SpawnSpeed = _levelConfig.GameDuration + _levelConfig.GameDuration * _delay[5]; - break; - } - _gameProgress++; - - if(_gameProgress == _maxSync) - { - _maxSync--; - _gameProgress = 0; - } - } } diff --git a/Assets/Scripts/LevelManager/LevelManager.cs b/Assets/Scripts/LevelManager/LevelManager.cs index 620c494..25a161d 100644 --- a/Assets/Scripts/LevelManager/LevelManager.cs +++ b/Assets/Scripts/LevelManager/LevelManager.cs @@ -138,6 +138,8 @@ public class LevelManager : Singleton } _currentLevel = level; + _waveObserver = WaveObserver.Instance; + _waveObserver.LevelConfig = _currentLevel.WaveConfig; Grid grid = Object.FindObjectOfType(); //create new grid if there is none if (!grid) @@ -163,10 +165,6 @@ public class LevelManager : Singleton tilemap.transform.SetParent(grid.transform); } Debug.Log("level loaded successfully"); - - Debug.Log("Decompte = " + _currentLevel.WaveConfig.GameDuration); - _waveObserver = WaveObserver.Instance; - _waveObserver.LevelConfig = _currentLevel.WaveConfig; } /// diff --git a/Assets/Scripts/Tiles/SpawnerTile.cs b/Assets/Scripts/Tiles/SpawnerTile.cs index 7890ec7..6fe7d09 100644 --- a/Assets/Scripts/Tiles/SpawnerTile.cs +++ b/Assets/Scripts/Tiles/SpawnerTile.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; [CreateAssetMenu(menuName = "Gather And Defend/Spawner Tile")] -public class SpawnerTile : LevelTile, IWaveSubject +public class SpawnerTile : LevelTile { [SerializeField] private GameObject _prefab; @@ -14,6 +14,9 @@ public class SpawnerTile : LevelTile, IWaveSubject [SerializeField, Range(0, 1.001f)] private float _spawnCounter = 0; private WaveObserver _observer; + private float _initialSpawnSpeed; + private const float MAX_SPAWN_SPEED = 0.01f; + private const float RANDOM_MODIFIER = 5.0f; public override void LevelStart() @@ -23,7 +26,6 @@ public class SpawnerTile : LevelTile, IWaveSubject if (_spawnOnStart && _lifetime <= 0) { _prefab.Create(Position, parent: LevelManager.Instance.LevelTransform); - _observer.NotifySpawned(this); } } @@ -35,6 +37,7 @@ public class SpawnerTile : LevelTile, IWaveSubject _spawnCounter = 0; _prefab.Create(Position, parent: LevelManager.Instance.LevelTransform); + _spawnSpeed = Mathf.Max(_initialSpawnSpeed / Random.Range(0.0f, RANDOM_MODIFIER), MAX_SPAWN_SPEED); _observer.NotifySpawned(this); } public override bool Equals(ILevelObject other) @@ -55,6 +58,12 @@ public class SpawnerTile : LevelTile, IWaveSubject dict[nameof(_spawnOnStart)] = _spawnOnStart; return dict; } + + internal void StopSpawn() + { + _spawnSpeed = 0.0f; + } + public override void LoadDictionary(Dictionary dict) { base.LoadDictionary(dict); @@ -79,5 +88,9 @@ public class SpawnerTile : LevelTile, IWaveSubject } } - public float SpawnSpeed { set { _spawnSpeed = value; } } + public void InitialSpawnSpeed(float value) + { + _initialSpawnSpeed = value; + _spawnSpeed = Mathf.Max(_initialSpawnSpeed / Random.Range(0.0f, RANDOM_MODIFIER - 2.0f), MAX_SPAWN_SPEED); + } } \ No newline at end of file From b57efc49a8f4ad8105a85f55e0e45b1b8b17f813 Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sat, 22 Jul 2023 14:21:44 -0400 Subject: [PATCH 04/12] Ajout d'instructions pour la configuration de la vague d'ennemi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changé le nom de classe de LevelConfig vers WaveConfig afin d'éviter une confusion avec le LevelEditor --- Assets/Editor/WaveConfigCustomInspector.cs | 22 +++++++++++++++++++ .../Editor/WaveConfigCustomInspector.cs.meta | 11 ++++++++++ Assets/LevelEditor/Levels/TestGame.asset | 1 + .../{LevelConfig.cs => WaveConfig.cs} | 8 +++---- ...LevelConfig.cs.meta => WaveConfig.cs.meta} | 0 Assets/Scripts/LevelConfig/WaveObserver.cs | 14 ++++++------ Assets/Scripts/LevelEditor/Level.cs | 4 ++-- Assets/Scripts/Opponent/EnemyType.cs | 2 -- 8 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 Assets/Editor/WaveConfigCustomInspector.cs create mode 100644 Assets/Editor/WaveConfigCustomInspector.cs.meta rename Assets/Scripts/LevelConfig/{LevelConfig.cs => WaveConfig.cs} (82%) rename Assets/Scripts/LevelConfig/{LevelConfig.cs.meta => WaveConfig.cs.meta} (100%) diff --git a/Assets/Editor/WaveConfigCustomInspector.cs b/Assets/Editor/WaveConfigCustomInspector.cs new file mode 100644 index 0000000..0a74656 --- /dev/null +++ b/Assets/Editor/WaveConfigCustomInspector.cs @@ -0,0 +1,22 @@ +using UnityEditor; + +namespace GatherAndDefend.LevelEditor +{ + [CustomEditor(typeof(WaveConfig))] + public class WaveConfigCustomInspector : Editor + { + + public override void OnInspectorGUI() + { + EditorGUILayout.HelpBox(@"How to use : +Créer élément de la liste ConstantSpawn. +Drag l'ennemi choisi dans Enemy et insérer le nombre à créer dans Count +Choisir la durée du jeux en terme de minutes dans GameDuration +L'intervalle de création est déterminé d'après la durée du jeux et le nombre d'ennemi à créer + +Importante consideration : +- Il faut assigner au moins un ennemi avec un Count d'au moins 1 pour jouer.", MessageType.None); + base.OnInspectorGUI(); + } + } +} \ No newline at end of file diff --git a/Assets/Editor/WaveConfigCustomInspector.cs.meta b/Assets/Editor/WaveConfigCustomInspector.cs.meta new file mode 100644 index 0000000..2edbb5e --- /dev/null +++ b/Assets/Editor/WaveConfigCustomInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8c38e7df17e51a6448682caeaba0f29e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/LevelEditor/Levels/TestGame.asset b/Assets/LevelEditor/Levels/TestGame.asset index 887d9f2..3819cd6 100644 --- a/Assets/LevelEditor/Levels/TestGame.asset +++ b/Assets/LevelEditor/Levels/TestGame.asset @@ -220,3 +220,4 @@ MonoBehaviour: _renderLayer: Default _position: {x: 0, y: 0} _scale: {x: 1, y: 1} + _waveConfig: {fileID: 11400000, guid: 21b0f85f7c746974db1e72f2df646f5d, type: 2} diff --git a/Assets/Scripts/LevelConfig/LevelConfig.cs b/Assets/Scripts/LevelConfig/WaveConfig.cs similarity index 82% rename from Assets/Scripts/LevelConfig/LevelConfig.cs rename to Assets/Scripts/LevelConfig/WaveConfig.cs index 288da83..960f433 100644 --- a/Assets/Scripts/LevelConfig/LevelConfig.cs +++ b/Assets/Scripts/LevelConfig/WaveConfig.cs @@ -1,15 +1,15 @@ -using System.Collections; using System.Collections.Generic; using UnityEngine; -[CreateAssetMenu(menuName = "Gather And Defend/Levels/LevelConfig")] -public class LevelConfig : ScriptableObject +[CreateAssetMenu(menuName = "Gather And Defend/Levels/WaveConfig")] +public class WaveConfig : ScriptableObject { + [SerializeField] private List _constantSpawn = new List(); [SerializeField] private float _gameDuration = 0; - public List ConstantSpawn + public List ConstantSpawn { get { diff --git a/Assets/Scripts/LevelConfig/LevelConfig.cs.meta b/Assets/Scripts/LevelConfig/WaveConfig.cs.meta similarity index 100% rename from Assets/Scripts/LevelConfig/LevelConfig.cs.meta rename to Assets/Scripts/LevelConfig/WaveConfig.cs.meta diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs index 5c70b21..c4bbed6 100644 --- a/Assets/Scripts/LevelConfig/WaveObserver.cs +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -6,8 +5,8 @@ public class WaveObserver : Singleton { private List _subjects = new List(); private List _copyConstantSpawn; - private LevelConfig _levelConfig; - public LevelConfig LevelConfig + private WaveConfig _levelConfig; + public WaveConfig LevelConfig { set { @@ -29,14 +28,15 @@ public class WaveObserver : Singleton public void NotifySpawned(SpawnerTile spawnerSubject) { - if (spawnerSubject.Prefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject())) + GameObject paramPrefab = spawnerSubject.Prefab; + if (paramPrefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject())) { int currentCount = 0; for (int i = 0; i < _copyConstantSpawn.Count; i++) { - if(_levelConfig.ConstantSpawn[i].GetEnemyObject() == spawnerSubject.Prefab) + if(_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab) { - currentCount = _copyConstantSpawn[i]--; + currentCount = _copyConstantSpawn[i] - 1; break; } } @@ -44,7 +44,7 @@ public class WaveObserver : Singleton { foreach (SpawnerTile spawner in _subjects) { - if (spawner.Prefab.Equals(spawnerSubject.Prefab)) + if (spawner.Prefab.Equals(paramPrefab)) { spawner.StopSpawn(); } diff --git a/Assets/Scripts/LevelEditor/Level.cs b/Assets/Scripts/LevelEditor/Level.cs index 62505d5..0fc33b4 100644 --- a/Assets/Scripts/LevelEditor/Level.cs +++ b/Assets/Scripts/LevelEditor/Level.cs @@ -12,7 +12,7 @@ namespace GatherAndDefend.LevelEditor [SerializeField] private List _data = new List(); [SerializeField] - private LevelConfig _waveConfig; + private WaveConfig _waveConfig; public void SaveFromTilemap(Tilemap tilemap) { var data = new TilemapData(); @@ -26,7 +26,7 @@ namespace GatherAndDefend.LevelEditor data.LoadToTilemap(tilemap); } - public LevelConfig WaveConfig { get { return _waveConfig; } } + public WaveConfig WaveConfig { get { return _waveConfig; } } public IEnumerator GetEnumerator() { diff --git a/Assets/Scripts/Opponent/EnemyType.cs b/Assets/Scripts/Opponent/EnemyType.cs index a7f8e3f..8fbe2eb 100644 --- a/Assets/Scripts/Opponent/EnemyType.cs +++ b/Assets/Scripts/Opponent/EnemyType.cs @@ -1,5 +1,3 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; using System; From 7dcf3e8217a588b7df091e897da69c718813f3f6 Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sat, 22 Jul 2023 17:57:52 -0400 Subject: [PATCH 05/12] Changement du nom de dossier de LevelConfig vers WaveConfig Ajustement des instructions du WaveConfig --- Assets/Editor/WaveConfigCustomInspector.cs | 8 ++++---- Assets/{LevelConfig.meta => WaveConfig.meta} | 0 Assets/{LevelConfig => WaveConfig}/Config01.asset | 0 Assets/{LevelConfig => WaveConfig}/Config01.asset.meta | 0 4 files changed, 4 insertions(+), 4 deletions(-) rename Assets/{LevelConfig.meta => WaveConfig.meta} (100%) rename Assets/{LevelConfig => WaveConfig}/Config01.asset (100%) rename Assets/{LevelConfig => WaveConfig}/Config01.asset.meta (100%) diff --git a/Assets/Editor/WaveConfigCustomInspector.cs b/Assets/Editor/WaveConfigCustomInspector.cs index 0a74656..13bc681 100644 --- a/Assets/Editor/WaveConfigCustomInspector.cs +++ b/Assets/Editor/WaveConfigCustomInspector.cs @@ -9,10 +9,10 @@ namespace GatherAndDefend.LevelEditor public override void OnInspectorGUI() { EditorGUILayout.HelpBox(@"How to use : -Créer élément de la liste ConstantSpawn. -Drag l'ennemi choisi dans Enemy et insérer le nombre à créer dans Count -Choisir la durée du jeux en terme de minutes dans GameDuration -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 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 Importante consideration : - Il faut assigner au moins un ennemi avec un Count d'au moins 1 pour jouer.", MessageType.None); diff --git a/Assets/LevelConfig.meta b/Assets/WaveConfig.meta similarity index 100% rename from Assets/LevelConfig.meta rename to Assets/WaveConfig.meta diff --git a/Assets/LevelConfig/Config01.asset b/Assets/WaveConfig/Config01.asset similarity index 100% rename from Assets/LevelConfig/Config01.asset rename to Assets/WaveConfig/Config01.asset diff --git a/Assets/LevelConfig/Config01.asset.meta b/Assets/WaveConfig/Config01.asset.meta similarity index 100% rename from Assets/LevelConfig/Config01.asset.meta rename to Assets/WaveConfig/Config01.asset.meta From 3b9964debde3fca707ae847483cf21d596fbe5b6 Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sat, 22 Jul 2023 17:59:55 -0400 Subject: [PATCH 06/12] Ajout d'un WaveConfig aux niveaux du LevelSelect --- Assets/LevelEditor/Levels/Level1.asset | 1 + Assets/LevelEditor/Levels/Level2.asset | 1 + Assets/LevelEditor/Levels/Level3.asset | 1 + Assets/LevelEditor/Levels/Level4.asset | 1 + Assets/LevelEditor/Levels/Level5.asset | 1 + Assets/LevelEditor/Levels/Level6.asset | 1 + 6 files changed, 6 insertions(+) diff --git a/Assets/LevelEditor/Levels/Level1.asset b/Assets/LevelEditor/Levels/Level1.asset index 2fd9e7d..7f0fdca 100644 --- a/Assets/LevelEditor/Levels/Level1.asset +++ b/Assets/LevelEditor/Levels/Level1.asset @@ -246,3 +246,4 @@ MonoBehaviour: _renderLayer: Default _position: {x: 0, y: 0} _scale: {x: 1, y: 1} + _waveConfig: {fileID: 11400000, guid: 21b0f85f7c746974db1e72f2df646f5d, type: 2} diff --git a/Assets/LevelEditor/Levels/Level2.asset b/Assets/LevelEditor/Levels/Level2.asset index 9ab0e48..38d9c27 100644 --- a/Assets/LevelEditor/Levels/Level2.asset +++ b/Assets/LevelEditor/Levels/Level2.asset @@ -198,3 +198,4 @@ MonoBehaviour: _renderLayer: Default _position: {x: 0, y: 0} _scale: {x: 1, y: 1} + _waveConfig: {fileID: 11400000, guid: 21b0f85f7c746974db1e72f2df646f5d, type: 2} diff --git a/Assets/LevelEditor/Levels/Level3.asset b/Assets/LevelEditor/Levels/Level3.asset index 5bc3d2e..e834439 100644 --- a/Assets/LevelEditor/Levels/Level3.asset +++ b/Assets/LevelEditor/Levels/Level3.asset @@ -196,3 +196,4 @@ MonoBehaviour: _renderLayer: Default _position: {x: 0, y: 0} _scale: {x: 1, y: 1} + _waveConfig: {fileID: 11400000, guid: 21b0f85f7c746974db1e72f2df646f5d, type: 2} diff --git a/Assets/LevelEditor/Levels/Level4.asset b/Assets/LevelEditor/Levels/Level4.asset index 30ce5a1..01582a4 100644 --- a/Assets/LevelEditor/Levels/Level4.asset +++ b/Assets/LevelEditor/Levels/Level4.asset @@ -228,3 +228,4 @@ MonoBehaviour: _renderLayer: Default _position: {x: 0, y: 0} _scale: {x: 1, y: 1} + _waveConfig: {fileID: 11400000, guid: 21b0f85f7c746974db1e72f2df646f5d, type: 2} diff --git a/Assets/LevelEditor/Levels/Level5.asset b/Assets/LevelEditor/Levels/Level5.asset index 91f7bcf..70774fa 100644 --- a/Assets/LevelEditor/Levels/Level5.asset +++ b/Assets/LevelEditor/Levels/Level5.asset @@ -204,3 +204,4 @@ MonoBehaviour: _renderLayer: Default _position: {x: 0, y: 0} _scale: {x: 1, y: 1} + _waveConfig: {fileID: 11400000, guid: 21b0f85f7c746974db1e72f2df646f5d, type: 2} diff --git a/Assets/LevelEditor/Levels/Level6.asset b/Assets/LevelEditor/Levels/Level6.asset index 6a0ddf9..1e96254 100644 --- a/Assets/LevelEditor/Levels/Level6.asset +++ b/Assets/LevelEditor/Levels/Level6.asset @@ -202,3 +202,4 @@ MonoBehaviour: _renderLayer: Default _position: {x: 0, y: 0} _scale: {x: 1, y: 1} + _waveConfig: {fileID: 11400000, guid: 21b0f85f7c746974db1e72f2df646f5d, type: 2} From c9c47f1417b9a47fb9fc3d88b6602fce3264798f Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sun, 30 Jul 2023 11:56:13 -0400 Subject: [PATCH 07/12] Fix enemy count bug where the number of enemies spawned was inconsistent with the amount desired --- Assets/Scripts/LevelConfig/WaveObserver.cs | 3 ++- Assets/Scripts/Opponent/EnemyType.cs | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs index c4bbed6..2ff5a79 100644 --- a/Assets/Scripts/LevelConfig/WaveObserver.cs +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -36,7 +36,8 @@ public class WaveObserver : Singleton { if(_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab) { - currentCount = _copyConstantSpawn[i] - 1; + currentCount = _copyConstantSpawn[i]--; + Debug.Log("nbr " + currentCount); break; } } diff --git a/Assets/Scripts/Opponent/EnemyType.cs b/Assets/Scripts/Opponent/EnemyType.cs index 8fbe2eb..1bb9e02 100644 --- a/Assets/Scripts/Opponent/EnemyType.cs +++ b/Assets/Scripts/Opponent/EnemyType.cs @@ -23,7 +23,6 @@ public class EnemyType public int Count { get { return _count; } - set { _count = value; } } } From a0aa9cfb644739f4fba7436997e82c3ff2232ac5 Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sun, 6 Aug 2023 18:27:23 -0400 Subject: [PATCH 08/12] Changed comments to english Added a limit to how many monsters are created per lane Unfixed issue where SpawnOnStart breaks the system --- Assets/Editor/WaveConfigCustomInspector.cs | 12 ++++----- Assets/Scripts/LevelConfig/WaveObserver.cs | 31 ++++++++++++++++++++++ Assets/Scripts/Opponent/Opponent.cs | 3 +++ Assets/Scripts/Tiles/SpawnerTile.cs | 19 ++++++++++--- 4 files changed, 55 insertions(+), 10 deletions(-) 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 From fcc29ad88a2281c54f778e366322a25db4a51b29 Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sun, 6 Aug 2023 18:51:27 -0400 Subject: [PATCH 09/12] Removed debuging comments Fixed the behavior of WaveObserver when a monster dies --- Assets/Scripts/LevelConfig/WaveObserver.cs | 3 --- Assets/Scripts/Opponent/Opponent.cs | 8 +++++++- Assets/Scripts/Tiles/SpawnerTile.cs | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs index 060d5cf..fced3ae 100644 --- a/Assets/Scripts/LevelConfig/WaveObserver.cs +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -40,7 +40,6 @@ public class WaveObserver : Singleton if(_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab) { currentCount = _copyConstantSpawn[i]--; - Debug.Log("nbr " + currentCount); break; } } @@ -68,7 +67,6 @@ public class WaveObserver : Singleton { _subjects[i].StopSpawn(); } - Debug.Log("Made in: " + i + ". In count of : " + _aliveEnemyCount[i]); return i; } } @@ -82,6 +80,5 @@ public class WaveObserver : Singleton _subjects[position].StartSpawn(); } _aliveEnemyCount[position]--; - Debug.Log("RIP"); } } diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index 4e2dd35..25de0fd 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -8,6 +8,7 @@ public class Opponent : Entity private Vector2 _movementVector = Vector2.zero; private Rigidbody2D _rigidbody; private WaveObserver _observer; + private int _index; public override void Start() { @@ -16,7 +17,7 @@ public class Opponent : Entity _rigidbody = GetComponent(); Animation = gameObject.AddComponent(); _observer = WaveObserver.Instance; - _observer.NotifyEnemy(transform.position.y); + _index = _observer.NotifyEnemy(transform.position.y); } void Update() @@ -49,4 +50,9 @@ public class Opponent : Entity AttackSpeedWait += Time.deltaTime; } + private void OnDisable() + { + _observer.NotifyDies(_index); + } + } diff --git a/Assets/Scripts/Tiles/SpawnerTile.cs b/Assets/Scripts/Tiles/SpawnerTile.cs index 3cd94d4..e12f99c 100644 --- a/Assets/Scripts/Tiles/SpawnerTile.cs +++ b/Assets/Scripts/Tiles/SpawnerTile.cs @@ -66,7 +66,6 @@ public class SpawnerTile : LevelTile internal void StopSpawn() { stopped = true; - Debug.Log("I STOPPED, GAWSH!!!"); } internal void StartSpawn() From 6345febb355ee9639d96c9101314169f7b1be0fc Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sun, 10 Sep 2023 15:39:19 -0400 Subject: [PATCH 10/12] Start reworking constant spawn Made interval between spawns adapt to enemies spawned at the Start Removed the random factor of interval to respect the game duration Made max spawn per row dependent of enemy toughness on that row --- Assets/Scripts/LevelConfig/WaveConfig.cs | 18 +++-- Assets/Scripts/LevelConfig/WaveObserver.cs | 76 ++++++++++++++-------- Assets/Scripts/Opponent/Opponent.cs | 8 ++- Assets/Scripts/Tiles/SpawnerTile.cs | 14 ++-- 4 files changed, 72 insertions(+), 44 deletions(-) diff --git a/Assets/Scripts/LevelConfig/WaveConfig.cs b/Assets/Scripts/LevelConfig/WaveConfig.cs index 960f433..e4bc275 100644 --- a/Assets/Scripts/LevelConfig/WaveConfig.cs +++ b/Assets/Scripts/LevelConfig/WaveConfig.cs @@ -9,6 +9,8 @@ public class WaveConfig : ScriptableObject private List _constantSpawn = new List(); [SerializeField] private float _gameDuration = 0; + private float _enemySpawndOnStart = 0; + private int _enemySum = 0; public List ConstantSpawn { get @@ -18,7 +20,13 @@ public class WaveConfig : ScriptableObject } public float GetInterval() { - float interval = SumCount().ToFloat() / _gameDuration * 0.01f; + float interval = _gameDuration * 60.0f / (_enemySum > 0 ? _enemySum.ToFloat() : SumCount()) ; + return interval; + } + public float GetUpdatedInterval() + { + _enemySpawndOnStart++; + float interval = Mathf.Max(_gameDuration * 60.0f / (_enemySum - _enemySpawndOnStart).ToFloat(), 0); return interval; } public EnemyType GetRandomSpawn() @@ -29,15 +37,13 @@ public class WaveConfig : ScriptableObject } return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)]; } - - private int SumCount() + private float SumCount() { - int sum = 0; foreach (EnemyType enemy in _constantSpawn) { - sum += enemy.Count; + _enemySum += enemy.Count; } - return sum; + return _enemySum.ToFloat(); } } diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs index fced3ae..04eda44 100644 --- a/Assets/Scripts/LevelConfig/WaveObserver.cs +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -4,40 +4,44 @@ using UnityEngine; public class WaveObserver : Singleton { private List _subjects = new List(); - private List _aliveEnemyCount = new List(); + private List _aliveEnemyCount = new List(); private List _copyConstantSpawn; private WaveConfig _levelConfig; - private const int MAXENEMYCOUNT = 3; - public WaveConfig LevelConfig - { - set - { + private const int MAXTOUGHNESS = 10; + private int _spawnerTiming = 0; + public WaveConfig LevelConfig + { + set + { _levelConfig = value; _copyConstantSpawn = new List(); foreach (EnemyType enemy in _levelConfig.ConstantSpawn) { _copyConstantSpawn.Add(enemy.Count); } - } + } } - + public void Attach(SpawnerTile spawnerSubject) { + spawnerSubject.Prefab = _levelConfig.GetRandomSpawn().GetEnemyObject(); - spawnerSubject.InitialSpawnSpeed(_levelConfig.GetInterval()); + spawnerSubject.ChangeSpawnSpeed(_levelConfig.GetInterval() * ++_spawnerTiming); _subjects.Add(spawnerSubject); _aliveEnemyCount.Add(0); + Debug.Log("Je suis le " + _spawnerTiming + "e a agir!!!"); } public void NotifySpawned(SpawnerTile spawnerSubject) { GameObject paramPrefab = spawnerSubject.Prefab; + spawnerSubject.ChangeSpawnSpeed(_levelConfig.GetInterval() * _spawnerTiming); if (paramPrefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject())) { int currentCount = 0; for (int i = 0; i < _copyConstantSpawn.Count; i++) { - if(_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab) + if (_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab) { currentCount = _copyConstantSpawn[i]--; break; @@ -56,29 +60,49 @@ public class WaveObserver : Singleton } } - public int NotifyEnemy(float yPosition) + public int NotifyEnemy(float yPosition, float toughness) + { + int index = FindEnemyIndex(yPosition); + _aliveEnemyCount[index] += toughness; + if (_aliveEnemyCount[index] >= MAXTOUGHNESS) + { + _subjects[index].StopSpawn(); + } + return index; + } + + public void NotifyDies(int position, float toughness) + { + _aliveEnemyCount[position] -= toughness; + if (_aliveEnemyCount[position] < MAXTOUGHNESS) + { + _subjects[position].StartSpawn(); + } + Debug.Log("Fallen monster "); + } + + /** + * Called when an enemy is spawned automatically at the start of the game + * Adjusts the intervall between spawns + */ + public void NotifyOnStart() + { + float interval = _levelConfig.GetUpdatedInterval(); + foreach (var subject in _subjects) + { + subject.ChangeSpawnSpeed(interval); + } + } + + private int FindEnemyIndex(float yPosition) { for (int i = 0; i < _subjects.Count; i++) { - if(_subjects[i].Position.y == yPosition) + if (_subjects[i].Position.y == yPosition) { - _aliveEnemyCount[i]++; - if(_aliveEnemyCount[i] >= MAXENEMYCOUNT) - { - _subjects[i].StopSpawn(); - } return i; } } return -1; } - - public void NotifyDies(int position) - { - if(_aliveEnemyCount[position] >= MAXENEMYCOUNT) - { - _subjects[position].StartSpawn(); - } - _aliveEnemyCount[position]--; - } } diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index 25de0fd..e8b686e 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -8,7 +8,8 @@ public class Opponent : Entity private Vector2 _movementVector = Vector2.zero; private Rigidbody2D _rigidbody; private WaveObserver _observer; - private int _index; + private int _observerIndex; + private float _toughness; public override void Start() { @@ -17,7 +18,8 @@ public class Opponent : Entity _rigidbody = GetComponent(); Animation = gameObject.AddComponent(); _observer = WaveObserver.Instance; - _index = _observer.NotifyEnemy(transform.position.y); + _toughness = Mathf.Round((base.Hp / 10) / 2); + _observerIndex = _observer.NotifyEnemy(transform.position.y, _toughness); } void Update() @@ -52,7 +54,7 @@ public class Opponent : Entity private void OnDisable() { - _observer.NotifyDies(_index); + _observer.NotifyDies(_observerIndex, _toughness); } } diff --git a/Assets/Scripts/Tiles/SpawnerTile.cs b/Assets/Scripts/Tiles/SpawnerTile.cs index e12f99c..e79be65 100644 --- a/Assets/Scripts/Tiles/SpawnerTile.cs +++ b/Assets/Scripts/Tiles/SpawnerTile.cs @@ -14,9 +14,6 @@ public class SpawnerTile : LevelTile [SerializeField, Range(0, 1.001f)] private float _spawnCounter = 0; private WaveObserver _observer; - private float _initialSpawnSpeed; - private const float MAX_SPAWN_SPEED = 0.01f; - private const float RANDOM_MODIFIER = 5.0f; private bool stopped = false; @@ -27,6 +24,7 @@ public class SpawnerTile : LevelTile if (_spawnOnStart && _lifetime <= 0) { _prefab.Create(Position, parent: LevelManager.Instance.LevelTransform); + _observer.NotifyOnStart(); } } @@ -35,13 +33,12 @@ public class SpawnerTile : LevelTile _lifetime += Time.deltaTime; if (!stopped) { - _spawnCounter += Time.deltaTime * _spawnSpeed; + _spawnCounter += Time.deltaTime; } - if (_spawnCounter < 1) return; + if (_spawnCounter < _spawnSpeed) return; _spawnCounter = 0; _prefab.Create(Position, parent: LevelManager.Instance.LevelTransform); - _spawnSpeed = Mathf.Max(_initialSpawnSpeed / Random.Range(1.0f, RANDOM_MODIFIER), MAX_SPAWN_SPEED); _observer.NotifySpawned(this); } public override bool Equals(ILevelObject other) @@ -98,9 +95,8 @@ public class SpawnerTile : LevelTile } } - public void InitialSpawnSpeed(float value) + public void ChangeSpawnSpeed(float value) { - _initialSpawnSpeed = value; - _spawnSpeed = Mathf.Max(_initialSpawnSpeed / Random.Range(1.0f, RANDOM_MODIFIER - 2.0f), MAX_SPAWN_SPEED); + _spawnSpeed = value; } } \ No newline at end of file From 56410139fd9b03904676b4dd9bf95d5a4d6fd05d Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sun, 17 Sep 2023 18:56:30 -0400 Subject: [PATCH 11/12] Reworked constant spawn One row will spawn at a set interval Maximum enemy per row determined by active toughness on that row --- Assets/Scripts/LevelConfig/WaveObserver.cs | 44 +++++++++++++++++++--- Assets/Scripts/Opponent/Opponent.cs | 2 +- Assets/Scripts/Tiles/SpawnerTile.cs | 23 ++++++++--- Assets/WaveConfig/Config01.asset | 4 +- 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs index 04eda44..f1ee0e3 100644 --- a/Assets/Scripts/LevelConfig/WaveObserver.cs +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using UnityEngine; +using System; public class WaveObserver : Singleton { @@ -9,6 +10,7 @@ public class WaveObserver : Singleton private WaveConfig _levelConfig; private const int MAXTOUGHNESS = 10; private int _spawnerTiming = 0; + private List _intervalTiming = new List(); public WaveConfig LevelConfig { set @@ -22,16 +24,23 @@ public class WaveObserver : Singleton } } + /** + * Called by spawner at the start of the game + * Assigns enemy to spawn and registers them + */ public void Attach(SpawnerTile spawnerSubject) { spawnerSubject.Prefab = _levelConfig.GetRandomSpawn().GetEnemyObject(); - spawnerSubject.ChangeSpawnSpeed(_levelConfig.GetInterval() * ++_spawnerTiming); _subjects.Add(spawnerSubject); _aliveEnemyCount.Add(0); - Debug.Log("Je suis le " + _spawnerTiming + "e a agir!!!"); + _intervalTiming.Add(++_spawnerTiming); } + /** + * Called by spawner when making enemies + * Assigns a new interval + */ public void NotifySpawned(SpawnerTile spawnerSubject) { GameObject paramPrefab = spawnerSubject.Prefab; @@ -43,7 +52,7 @@ public class WaveObserver : Singleton { if (_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab) { - currentCount = _copyConstantSpawn[i]--; + currentCount = --_copyConstantSpawn[i]; break; } } @@ -60,6 +69,10 @@ public class WaveObserver : Singleton } } + /** + * Called by enemy when they spawn + * Keeps track of their row + */ public int NotifyEnemy(float yPosition, float toughness) { int index = FindEnemyIndex(yPosition); @@ -71,6 +84,10 @@ public class WaveObserver : Singleton return index; } + /** + * Called when an enemy dies + * Reactivates spawning on that row if disabled before + */ public void NotifyDies(int position, float toughness) { _aliveEnemyCount[position] -= toughness; @@ -78,22 +95,23 @@ public class WaveObserver : Singleton { _subjects[position].StartSpawn(); } - Debug.Log("Fallen monster "); } /** * Called when an enemy is spawned automatically at the start of the game * Adjusts the intervall between spawns */ - public void NotifyOnStart() + public void NotifyOnStart(SpawnerTile spawnerSubject) { float interval = _levelConfig.GetUpdatedInterval(); foreach (var subject in _subjects) { subject.ChangeSpawnSpeed(interval); } + NotifySpawned(spawnerSubject); } + // To find which spawner an ennemy came from. private int FindEnemyIndex(float yPosition) { for (int i = 0; i < _subjects.Count; i++) @@ -105,4 +123,20 @@ public class WaveObserver : Singleton } return -1; } + + /** + * Spawners wait 1 second to have time to register them all + * Then gets assigned a random spawn interval + */ + public void NotifyEndCooldown(SpawnerTile spawnerTile) + { + System.Random rand = new System.Random(); + int index; + do + { + index = rand.Next(_subjects.Count); + } while (_intervalTiming.Count <= index); + spawnerTile.ChangeSpawnSpeed(_levelConfig.GetInterval() * _intervalTiming[index]); + _intervalTiming.Remove(index); + } } diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index e8b686e..24cd742 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -52,7 +52,7 @@ public class Opponent : Entity AttackSpeedWait += Time.deltaTime; } - private void OnDisable() + private void OnDestroy() { _observer.NotifyDies(_observerIndex, _toughness); } diff --git a/Assets/Scripts/Tiles/SpawnerTile.cs b/Assets/Scripts/Tiles/SpawnerTile.cs index e79be65..38450a7 100644 --- a/Assets/Scripts/Tiles/SpawnerTile.cs +++ b/Assets/Scripts/Tiles/SpawnerTile.cs @@ -10,11 +10,12 @@ public class SpawnerTile : LevelTile private bool _spawnOnStart; private float _lifetime; [SerializeField] - private float _spawnSpeed = 0; + private float _spawnSpeed = 1.0f; [SerializeField, Range(0, 1.001f)] private float _spawnCounter = 0; private WaveObserver _observer; - private bool stopped = false; + private bool _stopped = false; + private bool _cooldownEnded = false; public override void LevelStart() @@ -24,20 +25,26 @@ public class SpawnerTile : LevelTile if (_spawnOnStart && _lifetime <= 0) { _prefab.Create(Position, parent: LevelManager.Instance.LevelTransform); - _observer.NotifyOnStart(); + _observer.NotifyOnStart(this); } } public override void LevelUpdate() { _lifetime += Time.deltaTime; - if (!stopped) + if (!_stopped) { _spawnCounter += Time.deltaTime; } if (_spawnCounter < _spawnSpeed) return; _spawnCounter = 0; + if (!_cooldownEnded) + { + _observer.NotifyEndCooldown(this); + _cooldownEnded = true; + return; + } _prefab.Create(Position, parent: LevelManager.Instance.LevelTransform); _observer.NotifySpawned(this); } @@ -62,12 +69,12 @@ public class SpawnerTile : LevelTile internal void StopSpawn() { - stopped = true; + _stopped = true; } internal void StartSpawn() { - stopped = false; + _stopped = false; } @@ -95,6 +102,10 @@ public class SpawnerTile : LevelTile } } + /** + * Called by observer + * Assigns a new spawn interval + */ public void ChangeSpawnSpeed(float value) { _spawnSpeed = value; diff --git a/Assets/WaveConfig/Config01.asset b/Assets/WaveConfig/Config01.asset index 827612f..371055b 100644 --- a/Assets/WaveConfig/Config01.asset +++ b/Assets/WaveConfig/Config01.asset @@ -14,5 +14,5 @@ MonoBehaviour: m_EditorClassIdentifier: _constantSpawn: - _enemy: {fileID: 313037212318601125, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3} - _count: 20 - _gameDuration: 3 + _count: 5 + _gameDuration: 1 From 0ce0acae5e21971dab1a72d87f5d151b7bcc3058 Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sun, 17 Sep 2023 20:45:11 -0400 Subject: [PATCH 12/12] Fix MissingRefException when monster calls method OnDestroy Changes to Entity.cs to override Death method --- Assets/Scripts/Entity.cs | 2 +- Assets/Scripts/Opponent/Opponent.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 5fc8a74..9886edf 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -35,7 +35,7 @@ public abstract class Entity : LevelObject Animation.SpeedMultiplier = SpeedMultiplier; } //Start the animation of death and the fading of the entity - public void Death() + public virtual void Death() { _animation.PlayDieAnim(); Invoke("Dying", 0.1f); diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index 6846178..a8ca40f 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -23,7 +23,7 @@ public class Opponent : Entity _rigidbody = GetComponent(); Animation = gameObject.AddComponent(); _observer = WaveObserver.Instance; - _toughness = Mathf.Round((base.Hp / 10) / 2); + _toughness = Mathf.Round((Hp / 10) / 2); _observerIndex = _observer.NotifyEnemy(transform.position.y, _toughness); } @@ -61,9 +61,10 @@ public class Opponent : Entity AttackSpeedWait += Time.deltaTime; } - private void OnDestroy() + public override void Death() { _observer.NotifyDies(_observerIndex, _toughness); + base.Death(); } }