diff --git a/Assets/Scripts/WindowSpawner.cs b/Assets/Scripts/WindowSpawner.cs index 0dcc41d..d7080c7 100644 --- a/Assets/Scripts/WindowSpawner.cs +++ b/Assets/Scripts/WindowSpawner.cs @@ -1,5 +1,6 @@ using System; using Ext.B83.Unity.Attributes; +using InterfaceOff.WorldScene; using UnityEngine; using UnityEngine.SceneManagement; using Random = UnityEngine.Random; @@ -28,6 +29,8 @@ namespace InterfaceOff [field: SerializeField] public bool AutoSpawn { get; private set; } = true; private int TimeTillNextSpawn { get; set; } + public static float DifficultyMultiplier = 1f; + private void Awake() { /* Logs the amount of types found and errors if there is none */ @@ -97,15 +100,19 @@ namespace InterfaceOff /* Spawns new windows whilst active */ if (AutoSpawn) { - const int TICKS_PER_SECOND = 20; - const int MINIMUM_SPAWN_TIME = 2 * TICKS_PER_SECOND; - const int MAXIMUM_SPAWN_TIME = 5 * TICKS_PER_SECOND; + const int TICKS_PER_SECOND = 20; // Unity constant + const int MIN_SPAWN_TIME = 2 * TICKS_PER_SECOND; + const int MAX_SPAWN_TIME = 5 * TICKS_PER_SECOND; + + int currentMaxSpawnTime = MAX_SPAWN_TIME - (int)ScoreTracker.CurrentScore(); + currentMaxSpawnTime = Math.Clamp(currentMaxSpawnTime, MIN_SPAWN_TIME + 1, MAX_SPAWN_TIME); + Debug.Log(currentMaxSpawnTime); /* Decreases the spawn counter and spawns if at 0 */ TimeTillNextSpawn = Math.Max(0, TimeTillNextSpawn - 1); if (TimeTillNextSpawn == 0) { - TimeTillNextSpawn = Random.Range(MINIMUM_SPAWN_TIME, MAXIMUM_SPAWN_TIME); + TimeTillNextSpawn = Random.Range((int)(MIN_SPAWN_TIME * DifficultyMultiplier), (int)(currentMaxSpawnTime * DifficultyMultiplier)); SpawnNewRandomWindow(); } }