diff --git a/T3-Unity/Assets/Scenes/Map_Tests1.unity b/T3-Unity/Assets/Scenes/Map_Tests1.unity index 805bba549518524193377dc39ffb3687e5cfd8cb..a390d9e1453cd95d1c4de257467c2f23f1344e4f 100644 --- a/T3-Unity/Assets/Scenes/Map_Tests1.unity +++ b/T3-Unity/Assets/Scenes/Map_Tests1.unity @@ -852,6 +852,8 @@ MonoBehaviour: nbJoueur: 15 parent: {fileID: 313702767} copy: {fileID: 114736490466060796, guid: 4256cfb91b73ae34aab9be42e6a067de, type: 3} + _listRunners: [] + moyenneMotivation: 0 --- !u!4 &313702767 Transform: m_ObjectHideFlags: 0 diff --git a/T3-Unity/Assets/Scripts/IA/Runners.cs b/T3-Unity/Assets/Scripts/IA/Runners.cs index f18b3d06b39c35be2bee7aa2f02b15849777a698..39712e4e5f5174c8f07b88121abf7addb92b899e 100644 --- a/T3-Unity/Assets/Scripts/IA/Runners.cs +++ b/T3-Unity/Assets/Scripts/IA/Runners.cs @@ -8,6 +8,7 @@ public class Runners : MonoBehaviour { public float speed = 10f; + public float motivation; private AbstractMap _map; private Vector3 target; @@ -15,6 +16,7 @@ void Start() { + motivation = 50f; _map = GameObject.Find("Map").GetComponent<AbstractMap>(); Debug.Log("JE SUIS CREE !"); @@ -33,6 +35,19 @@ { GetNextWaypoint(); } + + if (Ui.difficulty < MotivScale.diff_min) + {//0.01 0.010 | 1 10 + motivation = motivation - ((float.Parse(RunnersFactory.getInstance().getRandom().Next(1, 10).ToString()) / 500f) * (MotivScale.diff_min - Ui.difficulty)); + } + else if (Ui.difficulty > MotivScale.diff_max) + { + motivation = motivation - ((float.Parse(RunnersFactory.getInstance().getRandom().Next(1, 10).ToString()) / 500f) * (Ui.difficulty - MotivScale.diff_max)); + } + else + { + motivation = motivation + (float.Parse(RunnersFactory.getInstance().getRandom().Next(1, 10).ToString()) / 500f); + } } private void GetNextWaypoint() diff --git a/T3-Unity/Assets/Scripts/IA/RunnersFactory.cs b/T3-Unity/Assets/Scripts/IA/RunnersFactory.cs index 0e18c7e81b0940346b5b5817ab5defe8dda54c30..21460fdf48f3088a79154a6e3390e294ce073789 100644 --- a/T3-Unity/Assets/Scripts/IA/RunnersFactory.cs +++ b/T3-Unity/Assets/Scripts/IA/RunnersFactory.cs @@ -3,6 +3,7 @@ using UnityEngine; using Scripts.Waypoints; using Mapbox.Unity.Map; + using System.Collections.Generic; public class RunnersFactory : MonoBehaviour { @@ -12,16 +13,51 @@ private System.Random rdn; private static RunnersFactory instance; private AbstractMap _map; + public List<GameObject> _listRunners; + public float moyenneMotivation = 0; void Start() { + _listRunners = new List<GameObject>(); _map = GameObject.Find("Map").GetComponent<AbstractMap>(); instance = this; rdn = new System.Random(); + + nbJoueur = 5 + Ui.rep * 2; + for (int i = 0; i < nbJoueur; i++) { - Instantiate(copy, _map.GeoToWorldPosition(WaypointsFactory.getInstance().getWp()[0]), - new Quaternion(0, 0, 0, 0), parent); + _listRunners.Add(Instantiate(copy, _map.GeoToWorldPosition(WaypointsFactory.getInstance().getWp()[0]), + new Quaternion(0, 0, 0, 0), parent).gameObject); + moyenneMotivation += _listRunners[i].GetComponent<Runners>().motivation; + } + + moyenneMotivation /= float.Parse(_listRunners.Count.ToString()); + } + + private void Update() + { + _listRunners.Clear(); + moyenneMotivation = 0; + for (int i = 0; i<GameObject.Find("Sportifs").transform.childCount; i++) + { + _listRunners.Add(GameObject.Find("Sportifs").transform.GetChild(i).gameObject); + moyenneMotivation += _listRunners[i].GetComponent<Runners>().motivation; + } + moyenneMotivation /= float.Parse(_listRunners.Count.ToString()); + + if (GameObject.Find("Sportifs").transform.childCount != 0) + { + Ui.motiv = moyenneMotivation; + + if (Ui.motiv < 0) + { + Ui.motiv = 0; + } + else if (Ui.motiv > 100) + { + Ui.motiv = 100; + } } } diff --git a/T3-Unity/Assets/Scripts/UI/MotivScale.cs b/T3-Unity/Assets/Scripts/UI/MotivScale.cs index 9afd48000c35bd0e032b8eb0ad240eaa9c8a0e62..7d7b954943191d88cd4da47cbed843461c881b1b 100644 --- a/T3-Unity/Assets/Scripts/UI/MotivScale.cs +++ b/T3-Unity/Assets/Scripts/UI/MotivScale.cs @@ -4,8 +4,8 @@ using UnityEngine; public class MotivScale : MonoBehaviour { - int diff_max; - int diff_min; + public static int diff_max; + public static int diff_min; void Start() { @@ -21,81 +21,48 @@ public class MotivScale : MonoBehaviour else { - float ech = Ui.motiv / 10; + float ech = Ui.motiv / 100f; transform.localScale = new Vector3(ech, 1, 1); - if (Ui.fame == 0) + if (Ui.fame < 10) { diff_max = 4; diff_min = 2; } - else if (Ui.fame >= 10) + else if (Ui.fame >= 10 && Ui.fame < 20) { diff_max = 5; diff_min = 3; } - else if (Ui.fame >= 20) + else if (Ui.fame >= 20 && Ui.fame < 40) { diff_max = 6; diff_min = 4; } - else if (Ui.fame >= 40) + else if (Ui.fame >= 40 && Ui.fame < 60) { diff_max = 7; diff_min = 5; } - - else if (Ui.fame >= 60) + else if (Ui.fame >= 60 && Ui.fame < 80) { diff_max = 8; diff_min = 6; } - - else if (Ui.fame >= 80) + else if (Ui.fame >= 80 && Ui.fame < 100) { diff_max = 9; diff_min = 7; } - else if (Ui.fame >= 100) { diff_max = 10; diff_min = 8; } - - - if (Ui.motiv < 0) - { - Ui.motiv = 0; - } - - if (Ui.motiv > 10) - { - Ui.motiv = 10; - } - - if (Ui.difficulty < diff_min) - { - Ui.motiv = Ui.motiv - 0.003f; - } - - else if (Ui.difficulty > diff_max) - { - Ui.motiv = Ui.motiv - 0.003f; - } - - else - { - Ui.motiv = Ui.motiv + 0.003f; - } - } - - - } }