Skip to content

Commit

Permalink
Finished Scripts for Game jam submission
Browse files Browse the repository at this point in the history
The coding is a bit messy on account of limited time... But it works
well!
  • Loading branch information
DrSharky committed Oct 30, 2018
1 parent 848b71a commit d8056f8
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 62 deletions.
53 changes: 18 additions & 35 deletions ClickHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@ public class ClickHandler : MonoBehaviour
GameObject pointPos;
GameObject pointPosInstance;

private bool disableControl = false;

Action toggleDotListener;
Action finishListener;

void Start()
{
toggleDotListener = new Action(ToggleDot);
finishListener = new Action(DeleteDots);
EventManager.StartListening("ToggleDots", toggleDotListener);
EventManager.StartListening("Finish", finishListener);
}

//void Update()
//{
// if (Input.GetKeyDown(KeyCode.F))
// {
// EventManager.TriggerEvent("ToggleDots");
// }
//}

void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(transform.position);
Expand All @@ -40,43 +37,29 @@ void OnMouseDown()

void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
if (!disableControl)
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
}

// -- CREATED FOR DEBUG PURPOSES!!! -- DELETE LATER --
//private void OnMouseUp()
//{
// Vector3 screenPt = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
// Debug.Log("Screen Pos: " + screenPt);
// Debug.Log("World Pos: " + transform.position);
//}
// -- DEBUG ONLY!! -- DELETE AFTER USE --

void ToggleDot()
{
if (redDotInstance == null)
redDotInstance = Instantiate(redDot, transform);
else
Destroy(redDotInstance);

//TogglePositionDisplay();
}

// -- CREATED FOR DEBUG PURPOSES!!! -- DELETE LATER --
void TogglePositionDisplay()
void DeleteDots()
{
Vector3 screenPosition;
if (pointPosInstance == null)
{
screenPosition = Camera.main.WorldToScreenPoint(transform.position);
pointPosInstance = Instantiate(pointPos, screenPosition, new Quaternion());
pointPosInstance.GetComponent<Text>().text = "(" + transform.position.x + ", " + transform.position.y + ", " + transform.position.z + ")";
pointPosInstance.transform.parent = GameObject.Find("Canvas").transform;
}
else
Destroy(pointPosInstance);
disableControl = true;
GameObject[] dots = GameObject.FindGameObjectsWithTag("Reddot");
for(int i = 0; i < dots.Length; i++)
{
Destroy(dots[i]);
}
}
// -- DEBUG ONLY!! -- DELETE AFTER USE --
}
21 changes: 18 additions & 3 deletions Clicker.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class Clicker : MonoBehaviour
{
bool toggleOn = false;
private bool toggleOn = false;
private bool controlsEnabled = false;
private Action disableControlsListener;
private Action enableControlsListener;

void Start()
{
enableControlsListener = new Action(() => { controlsEnabled = true; });
disableControlsListener = new Action(() => { controlsEnabled = false; });
EventManager.StartListening("EnableControls", enableControlsListener);
EventManager.StartListening("DisableControls", disableControlsListener);
}


void Update ()
{
if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0)) && !toggleOn)
if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0)) && !toggleOn && controlsEnabled)
{
EventManager.TriggerEvent("ToggleDots");
}

if (Input.GetKeyDown(KeyCode.F))
if (Input.GetMouseButtonDown(1) && controlsEnabled)
{
EventManager.TriggerEvent("ToggleDots");
toggleOn = !toggleOn;
Expand Down
122 changes: 122 additions & 0 deletions Countdown.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;

public class Countdown : MonoBehaviour
{
[SerializeField]
private RawImage refImage;
[SerializeField]
private GameObject finishText;

[SerializeField]
private GameObject tryAgainButton;
[SerializeField]
private GameObject quitButton;

private Vector2 refImagePos;
private Vector2 cornerPos;
[SerializeField]
private GameObject countdownText;


private bool movedToCorner = false;
private bool cornerWaitTime = false;
private bool doneMoving = false;
private bool counting = false;
private float countdownTime = 45.0f;

private Action startTimerListener;

// Use this for initialization
void Start()
{
cornerPos = new Vector2(-152.0f, -100.0f);
startTimerListener = new Action(() => { StartCoroutine(CountStart()); });
EventManager.StartListening("StartTimer", startTimerListener);
StartCoroutine(ShowRefImage());
}

IEnumerator ShowRefImage()
{
yield return new WaitForSeconds(0.25f);
refImage.texture = PositionComparison.refImage;
refImage.gameObject.SetActive(true);
}

// Update is called once per frame
void Update()
{
if (!movedToCorner)
{
StartCoroutine(MoveToCorner());
movedToCorner = true;
}

if (cornerWaitTime)
{
refImage.rectTransform.anchorMax = new Vector2(1.0f, 1.0f);
refImage.rectTransform.anchorMin = new Vector2(1.0f, 1.0f);
refImage.rectTransform.anchoredPosition = cornerPos;
EventManager.TriggerEvent("StartTimer");
EventManager.TriggerEvent("ToggleControls");
}
if (counting)
{
countdownTime -= Time.deltaTime;
countdownText.GetComponent<Text>().text = Mathf.FloorToInt(countdownTime).ToString();
}


if(countdownTime < 0.2 && countdownTime != -1)
{
EventManager.TriggerEvent("DisableControls");
countdownTime = -1;
counting = false;
EventManager.TriggerEvent("Finish");
countdownText.SetActive(false);
StartCoroutine(Finish());
return;
}

}

IEnumerator Finish()
{
finishText.SetActive(true);
yield return new WaitForSeconds(3.0f);
Text finishTextComp = finishText.GetComponent<Text>();
if (PositionComparison.scoreFinal < 35)
finishTextComp.color = new Color(255, 0, 0);
else if (PositionComparison.scoreFinal > 35 && PositionComparison.scoreFinal < 75)
{
finishTextComp.color = new Color(255.0f, 255.0f, 0);
}
else
{
finishTextComp.color = new Color(0, 255, 0);
}
finishText.GetComponent<Text>().text = "Your Score: " + PositionComparison.scoreFinal.ToString();

yield return new WaitForSeconds(4.0f);
quitButton.SetActive(true);
tryAgainButton.SetActive(true);

}

IEnumerator MoveToCorner()
{
yield return new WaitForSeconds(3.0f);
cornerWaitTime = true;
}

IEnumerator CountStart()
{
countdownText.GetComponent<Text>().text = "GO!";
EventManager.TriggerEvent("EnableControls");
yield return new WaitForSeconds(1.0f);
counting = true;
}
}
56 changes: 56 additions & 0 deletions GameUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GameUI : MonoBehaviour
{
[SerializeField]
private GameObject resumeButton;
[SerializeField]
private GameObject pauseText;
[SerializeField]
private GameObject quitButton;

public void TryAgainClick()
{
SceneManager.LoadScene(1);
}

public void ResumeClick()
{
Time.timeScale = 1.0f;
EventManager.TriggerEvent("EnableControls");
resumeButton.SetActive(false);
pauseText.SetActive(false);
quitButton.SetActive(false);


}

public void QuitClick()
{
Application.Quit();
}

public void Update()
{
if (Input.GetKeyDown(KeyCode.Escape) && Time.timeScale == 1.0f)
{
Time.timeScale = 0.0f;
EventManager.TriggerEvent("DisableControls");
resumeButton.SetActive(true);
pauseText.SetActive(true);
quitButton.SetActive(true);
}
else if (Input.GetKeyDown(KeyCode.Escape) && Time.timeScale == 0.0f)
{
Time.timeScale = 1.0f;
EventManager.TriggerEvent("EnableControls");
resumeButton.SetActive(false);
pauseText.SetActive(false);
quitButton.SetActive(false);
}
}
}
44 changes: 27 additions & 17 deletions PositionComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,46 @@
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;

public class PositionComparison : MonoBehaviour
{
[SerializeField]
GameObject armature;
private GameObject armature;

const float MAX_POINTS = 100.0f;
int boneCount = 0;
float pointTotal = 0.0f;
private const float MAX_POINTS = 100.0f;
private int boneCount = 0;
private float pointTotal = 0.0f;
private int refImageIndex;

[SerializeField]
RefPositions refPositions;
private RefPositions refPositions;

List<Vector3> currentPositions;
Vector3[] selectedRef;
private List<Vector3> currentPositions;
private Vector3[] selectedRef;

private Action calculateScoreListener;

public static double scoreFinal = 0.0;

public static Texture2D refImage;

// Use this for initialization
void Start ()
{
//Use -1 to exclude the base bone.
boneCount = armature.transform.childCount - 1;
selectedRef = refPositions.vectorList[UnityEngine.Random.Range(0,1)].vectorSet;
Debug.Log(selectedRef);
refImageIndex = UnityEngine.Random.Range(0,5);
selectedRef = refPositions.vectorList[refImageIndex].vectorSet;
refImage = refPositions.vectorList[refImageIndex].image;

calculateScoreListener = new Action(Compare);
EventManager.StartListening("Finish", calculateScoreListener);
}

// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Return))
Compare();
}

void Compare ()
{
Debug.Log("Compare");
double xTotalDiff = 0;
double yTotalDiff = 0;
for (int i = 0; i < boneCount; i++)
Expand All @@ -56,9 +62,13 @@ void Compare ()
Debug.Log("X Total Diff: " + xTotalDiff);
Debug.Log("Y Total Diff: " + yTotalDiff);
double boneFloat = boneCount;
if (xTotalDiff > 10)
xTotalDiff -= 10;
if (yTotalDiff > 10)
yTotalDiff -= 10;
double combinedDiff = (xTotalDiff + yTotalDiff) * (1 / (boneFloat / (100 / (boneFloat * 2))));
Debug.Log("Combined Diff: " + combinedDiff);
double scoreFinal = Math.Round((MAX_POINTS - combinedDiff), 1);
scoreFinal = Math.Round((MAX_POINTS - combinedDiff), 1);
if (scoreFinal < 0)
scoreFinal = 0;
Debug.Log("Score: " + scoreFinal);
Expand Down
Loading

0 comments on commit d8056f8

Please sign in to comment.