From f3577a7d3f05052f8bd532fea41ab73344018a7d Mon Sep 17 00:00:00 2001 From: Simon Pinfold Date: Tue, 23 Jun 2015 15:48:48 +1200 Subject: [PATCH] Properly merged Goal.cs --- Assets/Scripts/Goal.cs | 192 ++++++++++++++++++++++++----------------- 1 file changed, 115 insertions(+), 77 deletions(-) diff --git a/Assets/Scripts/Goal.cs b/Assets/Scripts/Goal.cs index 1233a23..80a7a77 100644 --- a/Assets/Scripts/Goal.cs +++ b/Assets/Scripts/Goal.cs @@ -18,6 +18,8 @@ public enum Mode { Normal, Speedrun, Practice }; public GameObject ghostPrefab; + static public bool paused = false; + private float countdownRemaining; private float time; @@ -30,6 +32,12 @@ public enum Mode { Normal, Speedrun, Practice }; private int playerIndex = 0; + private GameObject player; + + private GameObject gui; + + + RigidbodyFPSController playerController { get @@ -40,17 +48,32 @@ RigidbodyFPSController playerController void Start() { + player = GameObject.FindGameObjectWithTag("Player"); this.spos = playerController.transform.position; this.srot = playerController.transform.rotation; + if (MainMenu_Controller.currentMode == 0) + { + Debug.Log("Playing Normal Mode"); + playMode = Mode.Normal; + } + else + { + Debug.Log("Playing Speedrun Mode"); + playMode = Mode.Speedrun; + } + + gui = GameObject.FindGameObjectWithTag("GUI"); if (playMode == Mode.Speedrun) { playerController.enableInput = false; RestartSpeedrun(); + gui.SetActive(true); } else { playerController.GetComponent().StartRecording(); + gui.SetActive(false); } playerController.GetComponent().StartLoggingKeys(); @@ -60,102 +83,107 @@ void Start() } } - void OnGUI() - { - // copy the "label" style from the current skin - Rect s = new Rect(0, 0, Screen.width, Screen.height); - - if (playMode == Mode.Speedrun) - { - if (complete) - { - GUI.Label(s, time.ToString("#.###") + "s", announceText); - } - else if (playerController.enableInput) - { - GUI.Label(s, time.ToString("#.##") + "s", timeText); - } - else - { - GUI.Label(s, countdownRemaining.ToString("#.##") + "s", announceText); - } - } - } + // void OnGUI() + // { + // // copy the "label" style from the current skin + // Rect s = new Rect(0, 0, Screen.width, Screen.height); + // + // if (playMode == Mode.Speedrun) + // { + // if (complete) + // { + // GUI.Label(s, time.ToString("#.###") + "s", announceText); + // } + // else if (playerController.enableInput) + // { + // GUI.Label(s, time.ToString("#.##") + "s", timeText); + // } + // else + // { + // GUI.Label(s, countdownRemaining.ToString("#.##") + "s", announceText); + // } + // } + // } void Update() { - if (playMode == Mode.Speedrun) + if (!paused) { - if (Input.GetButtonDown("Restart Level")) - { - RestartSpeedrun(); - } - if (playerController.enableInput) + if (playMode == Mode.Speedrun) { - if (!complete) + if (Input.GetButtonDown("Restart Level")) { - time += Time.deltaTime; + player.GetComponent().Restart(); + RestartSpeedrun(); } - } - else - { - countdownRemaining -= Time.deltaTime; - if (countdownRemaining <= 0) + if (playerController.enableInput) { - playerController.enableInput = true; + if (!complete) + { + time += Time.deltaTime; + } } + else + { + countdownRemaining -= Time.deltaTime; + if (countdownRemaining <= 0) + { + playerController.enableInput = true; + } + } } - } - if (Input.GetKeyDown(KeyCode.Home)) - { - playerController.GetComponent().velocity = Vector3.zero; - playerController.transform.position = spos; - playerController.transform.rotation = srot; + if (Input.GetKeyDown(KeyCode.Home)) + { + playerController.GetComponent().velocity = Vector3.zero; + playerController.transform.position = spos; + playerController.transform.rotation = srot; - playerController.GetComponent().StopRecording(); + playerController.GetComponent().StopRecording(); - if (submitRuns) - { string run = playerController.GetComponent().SaveToString(); - StartCoroutine(PostRun(run)); - } - - playerController.GetComponent().ResetRecording(); - } - if (Input.GetKeyDown(KeyCode.End)) - { - playerController.GetComponent().StopRecording(); + if (submitRuns) + { + StartCoroutine(PostRun(run)); + } - if (submitRuns) + playerController.GetComponent().ResetRecording(); + } + if (Input.GetKeyDown(KeyCode.End)) { + playerController.GetComponent().StopRecording(); + string run = playerController.GetComponent().SaveToString(); - StartCoroutine(PostRun(run)); - } + if (submitRuns) + { + StartCoroutine(PostRun(run)); + } - playerController.GetComponent().ResetRecording(); - } + playerController.GetComponent().ResetRecording(); + } - if (Input.GetKeyDown(KeyCode.PageUp) || Input.GetKeyDown(KeyCode.PageDown)) - { - playerIndex++; + if (Input.GetKeyDown(KeyCode.PageUp) || Input.GetKeyDown(KeyCode.PageDown)) + { + playerIndex++; + } } - } - private void RestartSpeedrun() + public void RestartSpeedrun() { - countdownRemaining = speedrunCountdownTime; - playerController.enableInput = false; - complete = false; - time = 0; - - playerController.GetComponent().velocity = Vector3.zero; - playerController.transform.position = spos; - playerController.transform.rotation = srot; - playerController.GetComponent().ResetRecording(); + if (playMode == Mode.Speedrun) + { + countdownRemaining = speedrunCountdownTime; + playerController.enableInput = false; + complete = false; + time = 0; + playerController.GetComponent().velocity = Vector3.zero; + playerController.transform.position = spos; + playerController.transform.rotation = srot; + playerController.GetComponent().ResetRecording(); + } } void OnCollisionEnter(Collision collision) @@ -165,13 +193,22 @@ void OnCollisionEnter(Collision collision) complete = true; playerController.GetComponent().StopRecording(); + string run = playerController.GetComponent().SaveToString(); + + if (playMode == Mode.Speedrun) + { + player.GetComponent().setEndLevelText("Time " + playerController.GetComponent().getTimeString()); + } + else + player.GetComponent().setEndLevelText("Finish"); + player.GetComponent().EndLevel(); + if (submitRuns) { - string run = playerController.GetComponent().SaveToString(); StartCoroutine(PostRun(run)); } - playerController.GetComponent().ResetRecording(); + } } @@ -181,8 +218,8 @@ private string LevelHash() GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType(); foreach (GameObject go in allObjects) { - if (go.layer == LayerMask.NameToLayer("Ground")) - accum += (int)Mathf.Round((go.transform.position.x + go.transform.position.y + go.transform.position.z + go.transform.rotation.w + go.transform.rotation.x + go.transform.rotation.y + go.transform.rotation.z)*100); + if (go.layer == LayerMask.NameToLayer("Ground")) + accum += (int)Mathf.Round((go.transform.position.x + go.transform.position.y + go.transform.position.z + go.transform.rotation.w + go.transform.rotation.x + go.transform.rotation.y + go.transform.rotation.z) * 100); } return accum.ToString(); } @@ -208,9 +245,10 @@ private IEnumerator PostRun(string run) if (postRunURL != null) { WWW w = new WWW(postRunURL, form); - yield return w; // Better thread non-block? + yield return w; // Better thread non-block? } yield return null; } -} + +} \ No newline at end of file