From a32a0807403e2c02fbd5e25778c401b9b30f412f Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Mon, 17 Apr 2023 13:10:03 +0200 Subject: [PATCH] controlled spawning with settings --- .../Modifications/BorderBuff.asset | 4 +- .../Modifications/BorderNerf.asset | 2 +- .../Modifications/SpeedBuff.asset | 4 +- .../Modifications/SpeedNerf.asset | 2 +- .../Modifications/WidthBuff.asset | 4 +- .../Modifications/WidthNerf.asset | 2 +- Assets/Scenes/Game.unity | 33 ++++++++++++ Assets/Scripts/Game/GameManager.cs | 54 +++++++++++++++---- Assets/Scripts/Game/Settings.cs | 14 ++++- 9 files changed, 98 insertions(+), 21 deletions(-) diff --git a/Assets/Prefabs/Collectables/Modifications/BorderBuff.asset b/Assets/Prefabs/Collectables/Modifications/BorderBuff.asset index 8d139b1..e3e1051 100644 --- a/Assets/Prefabs/Collectables/Modifications/BorderBuff.asset +++ b/Assets/Prefabs/Collectables/Modifications/BorderBuff.asset @@ -14,6 +14,6 @@ MonoBehaviour: m_EditorClassIdentifier: type: 1 effect: 1 - pickupDuration: 10 - activeDuration: 10 + pickupDuration: 15 + activeDuration: 15 image: {fileID: 21300000, guid: 500c6690dd1efa237973d86a4232f5c0, type: 3} diff --git a/Assets/Prefabs/Collectables/Modifications/BorderNerf.asset b/Assets/Prefabs/Collectables/Modifications/BorderNerf.asset index d99a5a3..c49cccd 100644 --- a/Assets/Prefabs/Collectables/Modifications/BorderNerf.asset +++ b/Assets/Prefabs/Collectables/Modifications/BorderNerf.asset @@ -15,5 +15,5 @@ MonoBehaviour: type: 0 effect: 1 pickupDuration: 10 - activeDuration: 10 + activeDuration: 5 image: {fileID: 21300000, guid: 555c4207622e3e429bea3c98ad8ae3f5, type: 3} diff --git a/Assets/Prefabs/Collectables/Modifications/SpeedBuff.asset b/Assets/Prefabs/Collectables/Modifications/SpeedBuff.asset index 1834f74..54dfa1d 100644 --- a/Assets/Prefabs/Collectables/Modifications/SpeedBuff.asset +++ b/Assets/Prefabs/Collectables/Modifications/SpeedBuff.asset @@ -14,6 +14,6 @@ MonoBehaviour: m_EditorClassIdentifier: type: 1 effect: 0 - pickupDuration: 10 - activeDuration: 10 + pickupDuration: 15 + activeDuration: 15 image: {fileID: 21300000, guid: c9633c24081701c6c9ce9884d6524530, type: 3} diff --git a/Assets/Prefabs/Collectables/Modifications/SpeedNerf.asset b/Assets/Prefabs/Collectables/Modifications/SpeedNerf.asset index ee1e38a..122e86f 100644 --- a/Assets/Prefabs/Collectables/Modifications/SpeedNerf.asset +++ b/Assets/Prefabs/Collectables/Modifications/SpeedNerf.asset @@ -15,5 +15,5 @@ MonoBehaviour: type: 0 effect: 0 pickupDuration: 10 - activeDuration: 10 + activeDuration: 5 image: {fileID: 21300000, guid: 24ca60336f20aee73b5b211b6f6e1a44, type: 3} diff --git a/Assets/Prefabs/Collectables/Modifications/WidthBuff.asset b/Assets/Prefabs/Collectables/Modifications/WidthBuff.asset index 5558ac4..0bfecb6 100644 --- a/Assets/Prefabs/Collectables/Modifications/WidthBuff.asset +++ b/Assets/Prefabs/Collectables/Modifications/WidthBuff.asset @@ -14,6 +14,6 @@ MonoBehaviour: m_EditorClassIdentifier: type: 1 effect: 2 - pickupDuration: 10 - activeDuration: 10 + pickupDuration: 15 + activeDuration: 15 image: {fileID: 21300000, guid: f09eae8c0ea04254b90c5386a034a225, type: 3} diff --git a/Assets/Prefabs/Collectables/Modifications/WidthNerf.asset b/Assets/Prefabs/Collectables/Modifications/WidthNerf.asset index b41bf5c..df444f1 100644 --- a/Assets/Prefabs/Collectables/Modifications/WidthNerf.asset +++ b/Assets/Prefabs/Collectables/Modifications/WidthNerf.asset @@ -15,5 +15,5 @@ MonoBehaviour: type: 0 effect: 2 pickupDuration: 10 - activeDuration: 10 + activeDuration: 5 image: {fileID: 21300000, guid: f9161c6c9e06dc445ada3ee16d991f90, type: 3} diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 8cde563..e0287e1 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -1017,6 +1017,39 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 52712ba5190f247fcab14f6d688872ba, type: 3} m_Name: m_EditorClassIdentifier: + spawnRates: + - spawnable: 0 + values: + - spawnRate: 1 + baseSeconds: 20 + - spawnRate: 2 + baseSeconds: 10 + - spawnRate: 3 + baseSeconds: 5 + - spawnable: 1 + values: + - spawnRate: 1 + baseSeconds: 30 + - spawnRate: 2 + baseSeconds: 20 + - spawnRate: 3 + baseSeconds: 10 + - spawnable: 2 + values: + - spawnRate: 1 + baseSeconds: 10 + - spawnRate: 2 + baseSeconds: 7 + - spawnRate: 3 + baseSeconds: 3 + - spawnable: 3 + values: + - spawnRate: 1 + baseSeconds: 40 + - spawnRate: 2 + baseSeconds: 30 + - spawnRate: 3 + baseSeconds: 15 ballPrefab: {fileID: 7041796185663956342, guid: d67d5f2db5f0b3d9d8298731f423a9b6, type: 3} playerPrefab: {fileID: 5402279313309450415, guid: 32b3bb87d3699d314ace59ddb1674875, type: 3} borderZonePrefab: {fileID: 4827788429173683660, guid: 50e7c76b45ba22fb18c0012e23b4b34c, type: 3} diff --git a/Assets/Scripts/Game/GameManager.cs b/Assets/Scripts/Game/GameManager.cs index 1dc91ad..cf152f8 100644 --- a/Assets/Scripts/Game/GameManager.cs +++ b/Assets/Scripts/Game/GameManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using Unity.Netcode; using Unity.VisualScripting; using UnityEngine; @@ -10,6 +11,19 @@ using Random = UnityEngine.Random; namespace Game { public class GameManager : NetworkBehaviour { + [Serializable] + public struct SpawnRatesValue { + public SpawnRate spawnRate; + public float baseSeconds; + } + [Serializable] + public struct SpawnableSpawnRates { + public Spawnable spawnable; + public SpawnRatesValue[] values; + } + + public SpawnableSpawnRates[] spawnRates; + public Object ballPrefab; public Object playerPrefab; public Object borderZonePrefab; @@ -28,7 +42,6 @@ namespace Game { private void Awake() { SetupPlayers(); - SpawnBall(Player1, true); } private void OnEnable() { @@ -39,17 +52,38 @@ namespace Game { QualitySettings.vSyncCount = 0; } - private IEnumerator Start() { + private IEnumerator SpawnLoop(Spawnable spawnable) { + SpawnRate required = SpawnRate.Normal; //Settings.SpawnRates[spawnable]; + if (required == SpawnRate.Never) + yield break; + float baseSeconds = spawnRates.First(s => s.spawnable == spawnable).values.First(v => v.spawnRate == required).baseSeconds; while (Application.isPlaying) { - yield return new WaitForSeconds(1); - SpawnModification(); - yield return new WaitForSeconds(2); - SpawnWormhole(); - yield return new WaitForSeconds(1); - SpawnNewBall(); + yield return new WaitForSeconds(baseSeconds); + switch (spawnable) { + case Spawnable.NewBallTemporary: + SpawnNewBall(false); + break; + case Spawnable.NewBallPermanent: + SpawnNewBall(true); + break; + case Spawnable.Modification: + SpawnModification(); + break; + case Spawnable.Wormhole: + SpawnWormhole(); + break; + } } } + private void Start() { + SpawnBall(Player1, true); + StartCoroutine(SpawnLoop(Spawnable.NewBallTemporary)); + StartCoroutine(SpawnLoop(Spawnable.NewBallPermanent)); + StartCoroutine(SpawnLoop(Spawnable.Modification)); + StartCoroutine(SpawnLoop(Spawnable.Wormhole)); + } + private void SetupPlayers() { Settings.Type = Type.Hybrid; Settings.AIDifficulty = Difficulty.VeryHard; @@ -95,9 +129,9 @@ namespace Game { p1.borderZonePrefab = p2.borderZonePrefab = borderZonePrefab; } - private void SpawnNewBall() { + private void SpawnNewBall(bool permanent) { var pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-5, 5)); - Instantiate(newBallPrefab, pos, Quaternion.identity).GetComponent().IsPermanent = Random.value > 0.8f; + Instantiate(newBallPrefab, pos, Quaternion.identity).GetComponent().IsPermanent = permanent; } private void SpawnWormhole() { diff --git a/Assets/Scripts/Game/Settings.cs b/Assets/Scripts/Game/Settings.cs index e9e1a80..9c27659 100644 --- a/Assets/Scripts/Game/Settings.cs +++ b/Assets/Scripts/Game/Settings.cs @@ -1,10 +1,20 @@ +using System; +using System.Collections.Generic; + namespace Game { - public enum Type { RealOnline, RealOffline, Hybrid, AI } + public enum Type { RealOnline, RealOffline, Hybrid, AI, RealOnlineRanked } public enum Difficulty { VeryEasy, Easy, Medium, Hard, VeryHard } - + [Serializable] + public enum SpawnRate {Never, Few, Normal, Many} + [Serializable] + public enum Spawnable {NewBallTemporary, NewBallPermanent, Modification, Wormhole} + public enum WinScore {Default, Custom} public struct Settings { public static Type Type; public static Difficulty AIDifficulty; + public static Dictionary SpawnRates; + public static WinScore WinScore; + public static int CustomWinScore; } }