Fixed difficulty stuff

This commit is contained in:
Pasha Bibko
2026-01-27 09:46:22 +00:00
parent 879d74da61
commit 195e1a5a46
3 changed files with 10 additions and 9 deletions

View File

@@ -5,7 +5,7 @@ namespace InterfaceOff.MainMenu
{ {
public class DifficultyManager : MonoBehaviour public class DifficultyManager : MonoBehaviour
{ {
public static float DifficultyMultiplier { get; private set; } = 1; public static float DifficultyMultiplier { get; private set; } = 0.75f;
public static float DifficultyEffect => Mathf.Pow(f: DifficultyMultiplier, p: 2); public static float DifficultyEffect => Mathf.Pow(f: DifficultyMultiplier, p: 2);
[SerializeField] private Slider DifficultySlider; [SerializeField] private Slider DifficultySlider;

View File

@@ -7,7 +7,8 @@ using UnityEngine.UI;
namespace InterfaceOff.WorldScene namespace InterfaceOff.WorldScene
{ {
[System.Serializable] public struct PlayerScore [System.Serializable]
public struct PlayerScore
{ {
public string PlayerName; public string PlayerName;
public float Score; public float Score;
@@ -27,7 +28,7 @@ namespace InterfaceOff.WorldScene
[field: SerializeField] private WindowSpawner Spawner { get; set; } [field: SerializeField] private WindowSpawner Spawner { get; set; }
[field: SerializeField] private GameObject LeaderboardObject { get; set; } [field: SerializeField] private GameObject LeaderboardObject { get; set; }
[field: SerializeField] private GameObject LeaderboardEntryPrefab { get; set; } [field: SerializeField] private GameObject LeaderboardEntryPrefab { get; set; }
[field: SerializeField] private InputField PlayerTextNameInput { get; set; } [field: SerializeField] private InputField PlayerTextNameInput { get; set; }
[field: SerializeField] private Button IDRKWhatToCallThis { get; set; } [field: SerializeField] private Button IDRKWhatToCallThis { get; set; }
@@ -37,9 +38,8 @@ namespace InterfaceOff.WorldScene
private string CurrentPlayerName { get; set; } = string.Empty; private string CurrentPlayerName { get; set; } = string.Empty;
private bool StoredCurrentScore = false; private bool StoredCurrentScore = false;
private float Score; private float Score;
#if UNITY_STANDALONE_WIN
#if UNITY_STANDALONE_WIN
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void OnStart() private static void OnStart()
{ {
@@ -66,7 +66,6 @@ namespace InterfaceOff.WorldScene
string json = JsonUtility.ToJson(dmp, prettyPrint: false); string json = JsonUtility.ToJson(dmp, prettyPrint: false);
File.WriteAllText(Path.Combine(Application.persistentDataPath, "scores.json"), contents: json); File.WriteAllText(Path.Combine(Application.persistentDataPath, "scores.json"), contents: json);
} }
#endif // UNITY_STANDALONE_WIN #endif // UNITY_STANDALONE_WIN
public static float CurrentScore() public static float CurrentScore()
@@ -113,7 +112,7 @@ namespace InterfaceOff.WorldScene
if (Spawner.AutoSpawn) if (Spawner.AutoSpawn)
{ {
StoredCurrentScore = false; StoredCurrentScore = false;
Score = Time.timeSinceLevelLoad * DifficultyManager.DifficultyEffect; Score = Time.timeSinceLevelLoad * DifficultyManager.DifficultyEffect;
ScoreText.text = $"Score: {Score:F1}"; ScoreText.text = $"Score: {Score:F1}";
} }
@@ -144,4 +143,4 @@ namespace InterfaceOff.WorldScene
public void SetPlayerName(string input) => CurrentPlayerName = input; public void SetPlayerName(string input) => CurrentPlayerName = input;
} }
} }

View File

@@ -104,13 +104,15 @@ namespace InterfaceOff
int currentMaxSpawnTime = MAX_SPAWN_TIME - (int)(ScoreTracker.CurrentScore() * DifficultyManager.DifficultyEffect); int currentMaxSpawnTime = MAX_SPAWN_TIME - (int)(ScoreTracker.CurrentScore() * DifficultyManager.DifficultyEffect);
currentMaxSpawnTime = Math.Clamp(currentMaxSpawnTime, MIN_SPAWN_TIME + 1, MAX_SPAWN_TIME); currentMaxSpawnTime = Math.Clamp(currentMaxSpawnTime, MIN_SPAWN_TIME + 1, MAX_SPAWN_TIME);
Debug.Log($"Max: [{currentMaxSpawnTime}] with difficulty [{DifficultyManager.DifficultyEffect}]");
/* Decreases the spawn counter and spawns if at 0 */ /* Decreases the spawn counter and spawns if at 0 */
TimeTillNextSpawn = Math.Max(0, TimeTillNextSpawn - 1); TimeTillNextSpawn = Math.Max(0, TimeTillNextSpawn - 1);
if (TimeTillNextSpawn == 0) if (TimeTillNextSpawn == 0)
{ {
float difficulty = DifficultyManager.DifficultyMultiplier; float difficulty = DifficultyManager.DifficultyMultiplier;
TimeTillNextSpawn = Random.Range((int)(MIN_SPAWN_TIME * difficulty), (int)(currentMaxSpawnTime * difficulty)); TimeTillNextSpawn = Random.Range((int)(MIN_SPAWN_TIME * difficulty), (int)(currentMaxSpawnTime / difficulty));
SpawnNewRandomWindow(); SpawnNewRandomWindow();
} }
} }