Added experience gain while idle

- Might be off, could understand radians better
- Add popup for displaying idle exp gained
This commit is contained in:
Shaun Reed 2017-09-03 21:46:47 -04:00
parent 90948610cd
commit ea55db656d
2 changed files with 40 additions and 9 deletions

View File

@ -18,6 +18,8 @@ public class GameManager : MonoBehaviour {
public float requirement; public float requirement;
public float speed; public float speed;
public float increment; public float increment;
public DateTime currentTime;
} }
// Update is called once per frame // Update is called once per frame
@ -25,12 +27,6 @@ public class GameManager : MonoBehaviour {
} }
// Use this for initialization
void Start () {
Load();
}
void OnEnable() void OnEnable()
{ {
Load(); Load();
@ -63,6 +59,7 @@ public class GameManager : MonoBehaviour {
data.requirement = currentRequirement; data.requirement = currentRequirement;
data.speed = currentSpeed; data.speed = currentSpeed;
data.increment = currentIncrement; data.increment = currentIncrement;
data.currentTime = DateTime.Now;
bf.Serialize(file, data); bf.Serialize(file, data);
file.Close(); file.Close();
@ -83,7 +80,42 @@ public class GameManager : MonoBehaviour {
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentLevel = data.level; GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentLevel = data.level;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp = data.experience; GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp = data.experience;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentRequirement = data.requirement; GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentRequirement = data.requirement;
DateTime loadTime = DateTime.Now;
int secondsPassed = GetIdleRewards(data.currentTime, loadTime);
float radianSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed * Mathf.Deg2Rad;
float idleExp = radianSpeed * secondsPassed;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp += idleExp;
Debug.Log("Loaded"); Debug.Log("Loaded");
Debug.Log("idleExp: " + idleExp);
} }
} }
public int GetIdleRewards(DateTime saveTime, DateTime loadTime)
{
int daysPassed = 0;
int hoursPassed = 0;
int minutesPassed = 0;
int secondsPassed = 0;
for (int monthSaved = saveTime.Month; monthSaved < loadTime.Month; ++monthSaved)
{
daysPassed += 30;
}
daysPassed += loadTime.Day - saveTime.Day;
hoursPassed = daysPassed * 24;
hoursPassed += loadTime.Hour - saveTime.Hour;
minutesPassed = hoursPassed * 60;
minutesPassed += loadTime.Minute - saveTime.Minute;
secondsPassed = minutesPassed * 60;
secondsPassed += loadTime.Second - saveTime.Second;
Debug.Log("Seconds Passed: " + secondsPassed);
return secondsPassed;
}
} }

View File

@ -8,7 +8,6 @@ public class SpinningCube : MonoBehaviour
public float currentSpeed = 20f; public float currentSpeed = 20f;
public float currentIncrement = 10f; public float currentIncrement = 10f;
private string RotationDirection = "Up"; private string RotationDirection = "Up";
private Vector3 m_RotationDirection = Vector3.up; private Vector3 m_RotationDirection = Vector3.up;
private Vector3 rotationOrigin; private Vector3 rotationOrigin;