|
|
|
@ -11,18 +11,7 @@ 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 BalanceValues balanceValues; |
|
|
|
|
|
|
|
|
|
public Object ballPrefab; |
|
|
|
|
public Object playerPrefab; |
|
|
|
@ -34,6 +23,8 @@ namespace Game { |
|
|
|
|
|
|
|
|
|
public static GameManager Singleton { get; private set; } |
|
|
|
|
|
|
|
|
|
public static BalanceValues BalanceValues => Singleton.balanceValues; |
|
|
|
|
|
|
|
|
|
public List<Ball> Balls { get; } = new(); |
|
|
|
|
|
|
|
|
|
public Player Player1 { get; private set; } |
|
|
|
@ -41,22 +32,22 @@ namespace Game { |
|
|
|
|
public Player Player2 { get; private set; } |
|
|
|
|
|
|
|
|
|
private void Awake() { |
|
|
|
|
Singleton = this; |
|
|
|
|
|
|
|
|
|
SetupPlayers(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void OnEnable() { |
|
|
|
|
Singleton = this; |
|
|
|
|
|
|
|
|
|
// Move this to settings |
|
|
|
|
Application.targetFrameRate = 144; |
|
|
|
|
QualitySettings.vSyncCount = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private IEnumerator SpawnLoop(Spawnable spawnable) { |
|
|
|
|
SpawnRate required = Settings.SpawnRates[spawnable]; |
|
|
|
|
SpawnRate required = RoomSettings.SpawnRates[spawnable]; |
|
|
|
|
if (required == SpawnRate.Never) |
|
|
|
|
yield break; |
|
|
|
|
float baseSeconds = spawnRates.First(s => s.spawnable == spawnable).values.First(v => v.spawnRate == required).baseSeconds; |
|
|
|
|
float baseSeconds = balanceValues.spawnRates.First(s => s.spawnable == spawnable).values.First(v => v.spawnRate == required).baseSeconds; |
|
|
|
|
while (Application.isPlaying) { |
|
|
|
|
yield return new WaitForSeconds(baseSeconds); |
|
|
|
|
switch (spawnable) { |
|
|
|
@ -89,12 +80,12 @@ namespace Game { |
|
|
|
|
var p2Obj = Instantiate(playerPrefab); |
|
|
|
|
|
|
|
|
|
Player p1, p2; |
|
|
|
|
switch (Settings.Type) { |
|
|
|
|
switch (RoomSettings.Type) { |
|
|
|
|
case Type.AI: |
|
|
|
|
p1 = p1Obj.AddComponent<AIPlayer>(); |
|
|
|
|
p2 = p2Obj.AddComponent<AIPlayer>(); |
|
|
|
|
((AIPlayer) p1).Difficulty = Settings.AIDifficulty; |
|
|
|
|
((AIPlayer) p2).Difficulty = Settings.AIDifficulty; |
|
|
|
|
((AIPlayer) p1).Difficulty = RoomSettings.AIDifficulty; |
|
|
|
|
((AIPlayer) p2).Difficulty = RoomSettings.AIDifficulty; |
|
|
|
|
break; |
|
|
|
|
case Type.RealOnline: |
|
|
|
|
p1 = p1Obj.AddComponent<RealPlayer>(); |
|
|
|
@ -111,7 +102,7 @@ namespace Game { |
|
|
|
|
p1 = p1Obj.AddComponent<RealPlayer>(); |
|
|
|
|
p2 = p2Obj.AddComponent<AIPlayer>(); |
|
|
|
|
((RealPlayer) p1).isThisClient = true; |
|
|
|
|
((AIPlayer) p2).Difficulty = Settings.AIDifficulty; |
|
|
|
|
((AIPlayer) p2).Difficulty = RoomSettings.AIDifficulty; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
throw new ArgumentOutOfRangeException(); |
|
|
|
@ -126,25 +117,29 @@ namespace Game { |
|
|
|
|
p1.borderZonePrefab = p2.borderZonePrefab = borderZonePrefab; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Vector2 GetSpawnPosition() { |
|
|
|
|
Vector2 area = balanceValues.spawnArea * Dimensions.Singleton.playGroundSize * 0.5f; |
|
|
|
|
float x = Random.Range(-area.x, area.x); |
|
|
|
|
float y = Random.Range(-area.y, area.y); |
|
|
|
|
return new Vector2(x, y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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<NewBall>().IsPermanent = permanent; |
|
|
|
|
Instantiate(newBallPrefab, GetSpawnPosition(), Quaternion.identity).GetComponent<NewBall>().IsPermanent = permanent; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void SpawnWormhole() { |
|
|
|
|
var pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-5, 5)); |
|
|
|
|
Instantiate(wormholePrefab, pos, Quaternion.identity); |
|
|
|
|
Instantiate(wormholePrefab, GetSpawnPosition(), Quaternion.identity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void SpawnModification() { |
|
|
|
|
var pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-2, 2)); |
|
|
|
|
var properties = modifications[Random.Range(0, modifications.Length)]; |
|
|
|
|
var mod = Instantiate(modificationPrefab, pos, Quaternion.identity).GetComponent<Modification>(); |
|
|
|
|
var mod = Instantiate(modificationPrefab, GetSpawnPosition(), Quaternion.identity).GetComponent<Modification>(); |
|
|
|
|
mod.Properties = properties; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void SpawnBall(Player towards, bool isPermanent) { |
|
|
|
|
const float startSpeed = 15; |
|
|
|
|
float startSpeed = balanceValues.ballSpeed; |
|
|
|
|
var position = new Vector2(0, -towards.transform.position.y * 0.5f); |
|
|
|
|
var ball = Instantiate(ballPrefab, position, Quaternion.identity).GetComponent<Ball>(); |
|
|
|
|
ball.Rb.velocity = RandomDirectionTowards(towards) * startSpeed; |
|
|
|
|