Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #80 from synap5e/run-submission-fix
Browse files Browse the repository at this point in the history
Properly merged Goal.cs
  • Loading branch information
synap5e committed Jun 23, 2015
2 parents aefc745 + f3577a7 commit ff70d4a
Showing 1 changed file with 115 additions and 77 deletions.
192 changes: 115 additions & 77 deletions Assets/Scripts/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public enum Mode { Normal, Speedrun, Practice };

public GameObject ghostPrefab;

static public bool paused = false;

private float countdownRemaining;
private float time;

Expand All @@ -30,6 +32,12 @@ public enum Mode { Normal, Speedrun, Practice };

private int playerIndex = 0;

private GameObject player;

private GameObject gui;



RigidbodyFPSController playerController
{
get
Expand All @@ -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<Recorder>().StartRecording();
gui.SetActive(false);
}
playerController.GetComponent<Recorder>().StartLoggingKeys();

Expand All @@ -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<RespawnController>().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<Rigidbody>().velocity = Vector3.zero;
playerController.transform.position = spos;
playerController.transform.rotation = srot;
if (Input.GetKeyDown(KeyCode.Home))
{
playerController.GetComponent<Rigidbody>().velocity = Vector3.zero;
playerController.transform.position = spos;
playerController.transform.rotation = srot;

playerController.GetComponent<Recorder>().StopRecording();
playerController.GetComponent<Recorder>().StopRecording();

if (submitRuns)
{
string run = playerController.GetComponent<Recorder>().SaveToString();
StartCoroutine(PostRun(run));
}

playerController.GetComponent<Recorder>().ResetRecording();
}
if (Input.GetKeyDown(KeyCode.End))
{
playerController.GetComponent<Recorder>().StopRecording();
if (submitRuns)
{
StartCoroutine(PostRun(run));
}

if (submitRuns)
playerController.GetComponent<Recorder>().ResetRecording();
}
if (Input.GetKeyDown(KeyCode.End))
{
playerController.GetComponent<Recorder>().StopRecording();

string run = playerController.GetComponent<Recorder>().SaveToString();
StartCoroutine(PostRun(run));
}
if (submitRuns)
{
StartCoroutine(PostRun(run));
}

playerController.GetComponent<Recorder>().ResetRecording();
}
playerController.GetComponent<Recorder>().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<Rigidbody>().velocity = Vector3.zero;
playerController.transform.position = spos;
playerController.transform.rotation = srot;

playerController.GetComponent<Recorder>().ResetRecording();
if (playMode == Mode.Speedrun)
{
countdownRemaining = speedrunCountdownTime;
playerController.enableInput = false;
complete = false;
time = 0;
playerController.GetComponent<Rigidbody>().velocity = Vector3.zero;
playerController.transform.position = spos;
playerController.transform.rotation = srot;
playerController.GetComponent<Recorder>().ResetRecording();
}
}

void OnCollisionEnter(Collision collision)
Expand All @@ -165,13 +193,22 @@ void OnCollisionEnter(Collision collision)
complete = true;
playerController.GetComponent<Recorder>().StopRecording();

string run = playerController.GetComponent<Recorder>().SaveToString();

if (playMode == Mode.Speedrun)
{
player.GetComponent<Pause>().setEndLevelText("Time " + playerController.GetComponent<Recorder>().getTimeString());
}
else
player.GetComponent<Pause>().setEndLevelText("Finish");
player.GetComponent<Pause>().EndLevel();

if (submitRuns)
{
string run = playerController.GetComponent<Recorder>().SaveToString();
StartCoroutine(PostRun(run));
}

playerController.GetComponent<Recorder>().ResetRecording();

}
}

Expand All @@ -181,8 +218,8 @@ private string LevelHash()
GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType<GameObject>();
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();
}
Expand All @@ -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;
}

}

}

0 comments on commit ff70d4a

Please sign in to comment.