diff --git a/Assets/Scripts/AsteroidSpawner.cs b/Assets/Scripts/AsteroidSpawner.cs index cb84664..3812775 100644 --- a/Assets/Scripts/AsteroidSpawner.cs +++ b/Assets/Scripts/AsteroidSpawner.cs @@ -43,25 +43,37 @@ public class AsteroidSpawner : TimerFunctionsClass public void SpawnAsteroidEvent() { + + + var planet = FindObjectOfType(); + if (!GenerationVersLesjoueurs) { // Random entre 10 et 20, * 1 ou -1 - var x = UnityEngine.Random.Range(30.0f, 40.0f)*(Mathf.Floor(UnityEngine.Random.Range(0.0f, 1.99f))*2 - 1); - var y = UnityEngine.Random.Range(20.0f, 30.0f)*(Mathf.Floor(UnityEngine.Random.Range(0.0f, 1.99f))*2 - 1); + //var x = UnityEngine.Random.Range(30.0f, 40.0f)*(Mathf.Floor(UnityEngine.Random.Range(0.0f, 1.99f))*2 - 1); + //var y = UnityEngine.Random.Range(20.0f, 30.0f)*(Mathf.Floor(UnityEngine.Random.Range(0.0f, 1.99f))*2 - 1); + + + var angleRandom = UnityEngine.Random.Range(0, 359.9f); //0-3 var AsteroidType = Mathf.RoundToInt(Mathf.Floor(UnityEngine.Random.Range(0f, 3.999f))); //instantiate as child of AsteroidSpawner - var a = Instantiate(AsteroidPrefabTypes[AsteroidType], new Vector3(x, y, 0.0f), Quaternion.identity); + //var a = Instantiate(AsteroidPrefabTypes[AsteroidType], new Vector3(x, y, 0.0f), Quaternion.identity); + + Instantiate(AsteroidPrefabTypes[AsteroidType], + planet.GetPlanetCoordinatesFromPlayerXY(angleRandom, UnityEngine.Random.Range(15f, 25f)), + Quaternion.identity); + //a.tranform.parent = this.transform; } else { var players = GameObject.FindGameObjectsWithTag("Player"); - var planet = FindObjectOfType(); + foreach (var p in players) { diff --git a/Assets/Scripts/Earthquake.cs b/Assets/Scripts/Earthquake.cs index d79a7f0..b07acc3 100644 --- a/Assets/Scripts/Earthquake.cs +++ b/Assets/Scripts/Earthquake.cs @@ -28,7 +28,7 @@ public class Earthquake : MonoBehaviour { // Update is called once per frame public void Update () { - if(!isExploding) return; + if(isExploding) return; float disbalance = pmgr.GetDisbalance(); float val = Mathf.Clamp((disbalance-CriticalMin) / (CriticalMax-CriticalMin),0,1); @@ -38,7 +38,7 @@ public class Earthquake : MonoBehaviour { core.color = new Color(1f, 1f - val, 1f - val); - if (val2 >= 1f) + if (val2 >= CriticalMax + 0.05f) { EarthquakeBoom(); } diff --git a/Assets/Scripts/PlanetManager.cs b/Assets/Scripts/PlanetManager.cs index 45cf612..0ed76bc 100644 --- a/Assets/Scripts/PlanetManager.cs +++ b/Assets/Scripts/PlanetManager.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; public class PlanetManager : MonoBehaviour { + public int _NbActivePlayersRemaining = 0; public int NbCartiers = 10; public float TailleCartiersEnDegres = 0; //radian -> valeurs 0 a 360 public float CartierResetRatioSpeedFactor = 0.23f; //Entre 0.05 et 1 ou plus on aime que ca restore lentement, randomnly @@ -114,7 +115,31 @@ public class PlanetManager : MonoBehaviour w.sprite.transform.localScale = new Vector3(w.offset, w.offset,1.0f); } - //TODO_SR For each player + //TODO_SR For each player + VerifierPlayersActif(); + + if (_NbActivePlayersRemaining <= 1) + { + //TODO Call WorldManger.EndGame ou whatever + } + + } + + private void VerifierPlayersActif() + { + + int nbJoueursTrouves = 0; + var players = GameObject.FindGameObjectsWithTag("Player"); + + foreach (var p in players) + { + if (p.GetComponent().State < Astronaut.AstronautState.Ejecting) + { + nbJoueursTrouves++; + } + } + + _NbActivePlayersRemaining = nbJoueursTrouves; } public void PushWedge(float thetaPlayerX)