diff --git a/Assets/Prefabs/Pop-up Panel.prefab b/Assets/Prefabs/Pop-up Panel.prefab index 1788ead..7b1e0cb 100644 Binary files a/Assets/Prefabs/Pop-up Panel.prefab and b/Assets/Prefabs/Pop-up Panel.prefab differ diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index c490b9a..de0ce7a 100644 Binary files a/Assets/Scenes/Main.unity and b/Assets/Scenes/Main.unity differ diff --git a/Assets/Scripts/ExperienceBar.cs b/Assets/Scripts/ExperienceBar.cs index 6200c9c..f437b62 100644 --- a/Assets/Scripts/ExperienceBar.cs +++ b/Assets/Scripts/ExperienceBar.cs @@ -29,7 +29,8 @@ public class ExperienceBar : MonoBehaviour { private float previousExpRequired; private float barMovement; private float barPosition; - private float Increment = 10; + [SerializeField] + public float expIncrement = 10.0f; private string notify; // Use this for initialization @@ -41,7 +42,7 @@ public class ExperienceBar : MonoBehaviour { // Update is called once per frame void Update () { fillAmount = currentExp / currentRequirement; - + this.gameObject.GetComponentInChildren().text = (int)currentExp + " / " + (int)currentRequirement; if (currentLevelText.GetComponent().text != currentLevel.ToString()){ currentLevelText.GetComponent().text = currentLevel.ToString(); @@ -56,7 +57,7 @@ public class ExperienceBar : MonoBehaviour { if (expBarSprite.fillAmount >= 1.0f) { LevelUp(); - clicksNeeded = (currentRequirement - currentExp) / Increment; + clicksNeeded = (currentRequirement - currentExp) / expIncrement; fillAmount = 0; } } @@ -64,10 +65,10 @@ public class ExperienceBar : MonoBehaviour { public void ExpMore() { ++clicks; - currentExp = currentExp + Increment; + currentExp = currentExp + expIncrement; fillAmount = currentExp / currentRequirement; - notify = "+" + Increment + "EXP"; - eventSystem.GetComponent().MakePopup(notify); + notify = "+" + expIncrement + "EXP"; + eventSystem.GetComponent().RewardPopup(expIncrement, 1); //Debug.Log("fillAmount = " + fillAmount); } @@ -75,11 +76,15 @@ public class ExperienceBar : MonoBehaviour { public void LevelUp() { ++currentLevel; + expIncrement += 10; currentLevelText.GetComponent().text = currentLevel.ToString(); previousExpRequired = currentRequirement; currentExp -= previousExpRequired; currentRequirement = Mathf.Pow(currentRequirement, 1.05f); GameObject.FindGameObjectWithTag("Player").GetComponent().RaiseRotationSpeed(); + notify = "Level " + currentLevel + "!"; + eventSystem.GetComponent().RewardPopup(currentLevel, 2); + } public void ResetExp() @@ -88,17 +93,24 @@ public class ExperienceBar : MonoBehaviour { currentLevelText.GetComponent().text = currentLevel.ToString(); currentExp = 0; fillAmount = 0; + expIncrement = 10.0f; currentRequirement = 100; clicksNeeded = 10; clicks = 0; + notify = "EXP Reset"; + eventSystem.GetComponent().MakeStringPopup(notify, 1); + } public void ExpLess() { --clicks; - currentExp = currentExp - Increment; + currentExp = currentExp - expIncrement; fillAmount = (currentExp / currentRequirement); Debug.Log("fillAmount = " + fillAmount); + notify = "-" + expIncrement + "EXP"; + eventSystem.GetComponent().RewardPopup(-expIncrement, 1); + } public float GetExperience() diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index d2a5cbd..4949b87 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -18,7 +18,8 @@ public class GameManager : MonoBehaviour { public float experience; public float requirement; public float speed; - public float increment; + public float speedIncrement; + public float expIncrement; public float rotationsPerSec; public DateTime currentTime; @@ -61,13 +62,15 @@ public class GameManager : MonoBehaviour { float rotationPerSec = GameObject.FindGameObjectWithTag("Player").GetComponent().rotationPerSec; float currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent().currentSpeed; float currentIncrement = GameObject.FindGameObjectWithTag("Player").GetComponent().currentIncrement; + float currentExpIncrement = GameObject.FindGameObjectWithTag("ExpGained").GetComponent().expIncrement; PlayerData data = new PlayerData(); data.level = currentLevel; data.experience = currentExp; data.requirement = currentRequirement; data.speed = currentSpeed; - data.increment = currentIncrement; + data.speedIncrement = currentIncrement; + data.expIncrement = currentExpIncrement; data.rotationsPerSec = rotationPerSec; data.currentTime = System.DateTime.Now; @@ -87,20 +90,20 @@ public class GameManager : MonoBehaviour { GameObject.FindGameObjectWithTag("Player").GetComponent().rotationPerSec = data.rotationsPerSec; GameObject.FindGameObjectWithTag("Player").GetComponent().currentSpeed = data.speed; - GameObject.FindGameObjectWithTag("Player").GetComponent().currentIncrement = data.increment; + GameObject.FindGameObjectWithTag("Player").GetComponent().currentIncrement = data.speedIncrement; + GameObject.FindGameObjectWithTag("ExpGained").GetComponent().expIncrement = data.expIncrement; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentLevel = data.level; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentExp = data.experience; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentRequirement = data.requirement; DateTime loadTime = System.DateTime.Now; int secondsPassed = GetIdleTime(data.currentTime, loadTime); - idleExp = (data.rotationsPerSec * secondsPassed) * data.increment; + idleExp = (data.rotationsPerSec * secondsPassed) * data.expIncrement; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentExp += idleExp; if (idleExp >= 0.0f) { - string notification = ("+" + idleExp + "EXP"); - MakePopup(notification); + RewardPopup(idleExp, 1); } Debug.Log("Loaded"); @@ -134,16 +137,31 @@ public class GameManager : MonoBehaviour { return secondsPassed; } - public void MakePopup(string content) + + public int notificationType; + public float noteValue; + /* + * type 1 = exp + * type 2 = level + * + * + * + * + */ + public void RewardPopup(float value, int type) { - notify = content; + notificationType = type; + noteValue = value; Instantiate(popup, popupSpawn.transform.position, popupSpawn.transform.rotation, GameObject.Find("Notification Panel").gameObject.transform ); Debug.Log("Popup Created"); } - public string GetNotify() + public void MakeStringPopup(string content, int type) { - return notify; + notify = content; + notificationType = type; + Instantiate(popup, popupSpawn.transform.position, popupSpawn.transform.rotation, GameObject.Find("Notification Panel").gameObject.transform); + Debug.Log("Popup Created"); } } diff --git a/Assets/Scripts/PopupNotification.cs b/Assets/Scripts/PopupNotification.cs index 4ec8742..aaa7d31 100644 --- a/Assets/Scripts/PopupNotification.cs +++ b/Assets/Scripts/PopupNotification.cs @@ -6,20 +6,33 @@ using UnityEngine.UI; public class PopupNotification : MonoBehaviour { + public bool move = false; public bool active = false; public Vector3 origin; public float timer = 0.0f; + public float maxTimer = 3.0f; + public float speed = 50.0f; public string localNotify; + public int notificationType; + public float localValue; + // Use this for initialization void OnEnable () { active = true; + + //Get & set random rotation double randomRotation = GetRandomNumber(-4.0, 4.0); transform.Rotate(0.0f, 0.0f, (float)randomRotation); - Debug.Log("Rotation set to :" + randomRotation); - origin = this.transform.localPosition; - localNotify = GameObject.Find("EventSystem").GetComponent().GetNotify(); + //Debug.Log("Rotation set to :" + randomRotation); + + // + notificationType = GameObject.Find("EventSystem").GetComponent().notificationType; + //localNotify = GameObject.Find("EventSystem").GetComponent().notify; + localValue = GameObject.Find("EventSystem").GetComponent().noteValue; + + CheckNotificationType(); } // Update is called once per frame @@ -28,15 +41,70 @@ public class PopupNotification : MonoBehaviour { timer += 0.02f; - this.gameObject.transform.Translate(new Vector3(0, 50f * Time.deltaTime, 0)); - this.gameObject.GetComponentInChildren().text = localNotify; - if (timer >= 3) + if (timer >= maxTimer) { active = false; timer = 0.0f; + Destroy(this.gameObject); } + + if(move == true) + { + this.gameObject.transform.Translate(new Vector3(-5.0f, speed * Time.deltaTime, 0)); + this.gameObject.GetComponentInChildren().text = localNotify; + } + else + { + this.gameObject.transform.Translate(new Vector3(0, speed * Time.deltaTime, 0)); + this.gameObject.GetComponentInChildren().text = localNotify; + } + } + + void OnCollisionEnter (Collision col) + { + if(col.gameObject.GetComponent().notificationType == 1 && notificationType == 1) + { + //if both colliding popus are EXP related + + + if ((maxTimer - timer) > (col.gameObject.GetComponent().maxTimer - col.gameObject.GetComponent().timer)) + { + //If this Popup has more time left than colliding popup + localValue += col.gameObject.GetComponent().localValue; + maxTimer += 0.5f; + CheckNotificationType(); + Destroy(col.gameObject); + }//else do nothing, let other popup handle it + } + else if (col.gameObject.GetComponent().notificationType == 2 && notificationType == 2) + { + //if both colliding popus are level related + + + if (localValue > col.gameObject.GetComponent().localValue) + { + //If this popup is of higher level + Destroy(col.gameObject); + }//Destroy collider, show most recent level + maxTimer += 1.0f; + CheckNotificationType(); + + } + else if (col.gameObject.GetComponent().notificationType != notificationType) + { + //if both colliding popus are not related + + + if (notificationType == 2) + { + move = true; + }//else do nothing, let other popup handle it + } + + + } public double GetRandomNumber(double min, double max) @@ -45,5 +113,39 @@ public class PopupNotification : MonoBehaviour { return random.NextDouble() * (max - min) + min; } + public void CheckNotificationType() + { + //If notification is of type EXP + if (notificationType == 1) + { + + if (localValue == 0) + { + Debug.Log("Null EXP value, popup discarded :" + localValue); + Destroy(this.gameObject); + } + + if (localValue > 0) + { + //If adding EXP + localNotify = "+" + localValue + "EXP"; + + } + else if (localValue < 0) + { + //If subtracting EXP + localNotify = localValue + "EXP"; + } + + } + else if (notificationType == 2) + { + //If notification is of type Level Gained + localNotify = "Level " + localValue + "!"; + } + + this.gameObject.GetComponentInChildren().text = localNotify; + } + }