| @@ -0,0 +1,92 @@ | ||
| using UnityEngine; | ||
| using UnityEngine.UI; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
|
|
||
| public class GameManager : MonoBehaviour | ||
| { | ||
| private Vector3 m_GroupStartPos; | ||
|
|
||
| [SerializeField] | ||
| private float m_DistanceMade; | ||
| public float GetDistanceMade | ||
| { | ||
| get { return m_DistanceMade; } | ||
| } | ||
|
|
||
| private float m_CurrentCurrency; | ||
| private int m_CurrencyUsed; | ||
|
|
||
| private List<GameObject> m_CrusadeGroup = new List<GameObject>(); | ||
| public List<GameObject> SetCrusadeGroup | ||
| { | ||
| get { return m_CrusadeGroup; } | ||
| set { m_CrusadeGroup = value; } | ||
| } | ||
|
|
||
| private GameObject m_CrusadeLeader; | ||
|
|
||
| private GroupController m_GroupController; | ||
| [SerializeField] | ||
| private GameObject m_EndScreen; | ||
| [SerializeField] | ||
| private GameObject m_InGameScreen; | ||
|
|
||
| [SerializeField] | ||
| private Text m_Distance; | ||
| [SerializeField] | ||
| private Text m_Currency; | ||
| [SerializeField] | ||
| private Text m_EndScore; | ||
|
|
||
| void Start() | ||
| { | ||
| Application.targetFrameRate = 30; | ||
| m_CrusadeLeader = GameObject.Find("CrusadeLeader"); | ||
|
|
||
| m_GroupController = GetComponent<GroupController>(); | ||
| //m_GroupStartPos = m_CrusadeGroup[0].transform.position; | ||
| } | ||
|
|
||
| void Update() | ||
| { | ||
| m_DistanceMade = m_CrusadeLeader.transform.position.x; | ||
| m_Distance.text = "Meters: " + Mathf.Round(m_DistanceMade); | ||
|
|
||
| m_CurrentCurrency = m_DistanceMade / 10; | ||
| m_CurrentCurrency = Mathf.Round(m_CurrentCurrency); | ||
| m_Currency.text = "Currency: " + (m_CurrentCurrency - m_CurrencyUsed); | ||
| GameOver(); | ||
|
|
||
| if(Input.GetKeyDown(KeyCode.R)) | ||
| { | ||
| Replay(); | ||
| } | ||
| //m_DistanceMade = m_CrusadeGroup[0].transform.position.x - m_GroupStartPos.x; | ||
| } | ||
|
|
||
| public bool Buy() | ||
| { | ||
| if ((m_CurrentCurrency - m_CurrencyUsed) >= 1) | ||
| { | ||
| m_CurrencyUsed += 1; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private void GameOver() | ||
| { | ||
| if(m_GroupController.m_Group.Count <= 0) | ||
| { | ||
| m_EndScore.text = "Score: " + m_DistanceMade; | ||
| m_InGameScreen.SetActive(false); | ||
| m_EndScreen.SetActive(true); | ||
| } | ||
| } | ||
|
|
||
| public void Replay() | ||
| { | ||
| Application.LoadLevel(0); | ||
| } | ||
| } |
| @@ -0,0 +1,22 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
|
|
||
| public class KnightThreatProtector : MonoBehaviour | ||
| { | ||
| private int m_Uses; | ||
|
|
||
| private string m_KnightType; | ||
|
|
||
| void Start() | ||
| { | ||
| if(m_KnightType == "SpearKnight") | ||
| { | ||
|
|
||
| } | ||
|
|
||
| if (m_KnightType == "HammerKnight") | ||
| { | ||
|
|
||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,108 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
|
|
||
| public class MeasureShaking : MonoBehaviour | ||
| { | ||
| public float avrgTime = 0.5f; | ||
| public float peakLevel = 0.6f; | ||
| public float endCountTime = 0.6f; | ||
| public int shakeDir; | ||
| public int shakeCount; | ||
|
|
||
| Vector3 avrgAcc = Vector3.zero; | ||
| int countPos; | ||
| int countNeg; | ||
| int lastPeak; | ||
| int firstPeak; | ||
| bool counting; | ||
| float timer; | ||
|
|
||
| bool ShakeDetector() | ||
| { | ||
|
|
||
| Vector3 curAcc = Input.acceleration; | ||
|
|
||
| avrgAcc = Vector3.Lerp(avrgAcc, curAcc, avrgTime * Time.deltaTime); | ||
|
|
||
| curAcc -= avrgAcc; | ||
|
|
||
| int peak = 0; | ||
|
|
||
| if (curAcc.y > peakLevel) | ||
| { | ||
| peak = 1; | ||
| } | ||
| if (curAcc.y < -peakLevel) | ||
| { | ||
| peak = -1; | ||
| } | ||
|
|
||
| if (peak == lastPeak) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| lastPeak = peak; | ||
|
|
||
| if (peak != 0) | ||
| { | ||
| timer = 0; | ||
|
|
||
| if (peak > 0) | ||
| { | ||
| countPos++; | ||
| } | ||
| else | ||
| { | ||
| countNeg++; | ||
| } | ||
|
|
||
| if (!counting) | ||
| { | ||
| counting = true; | ||
| firstPeak = peak; | ||
| } | ||
| } | ||
| else if (counting) | ||
| { | ||
| timer += Time.deltaTime; | ||
| if (timer > endCountTime) | ||
| { | ||
| counting = false; | ||
| shakeDir = firstPeak; | ||
| if (countPos > countNeg) | ||
| { | ||
| shakeCount = countPos; | ||
| } | ||
| else | ||
| { | ||
| shakeCount = countNeg; | ||
| } | ||
|
|
||
| countPos = 0; | ||
| countNeg = 0; | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| void Update() | ||
| { | ||
| //Debug.Log(counting); | ||
| if (ShakeDetector()) | ||
| { // call ShakeDetector every Update! | ||
| // the device was shaken up and the count is in shakeCount | ||
| // the direction of the first shake is in shakeDir (1 or -1) | ||
| } | ||
| // the variable counting tells when the device is being shaken: | ||
| if (counting) | ||
| { | ||
| GameObject go = GameObject.Find("Hazard_Type_1"); | ||
| Destroy(go); | ||
|
|
||
| //Debug.Log("Shaking up device"); | ||
| counting = false; | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,62 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
|
|
||
| public class Meteor : MonoBehaviour | ||
| { | ||
| private Rigidbody2D m_Rigidbody; | ||
| private GameObject m_CrusadeLeader; | ||
| private Vector2 m_StartPos = new Vector2(0, 0); | ||
| private Vector2 m_NormalizedDir; | ||
| private bool m_NoHit = true; | ||
|
|
||
| private bool m_Destroy = false; | ||
| private float m_DestroyTimer = 1; | ||
|
|
||
| void Update() | ||
| { | ||
| m_CrusadeLeader = GameObject.Find("CrusadeLeader"); | ||
| Vector2 dir = new Vector2(m_CrusadeLeader.transform.position.x, m_CrusadeLeader.transform.position.y) - m_StartPos; | ||
| if (m_NoHit) | ||
| { | ||
| m_NormalizedDir = dir.normalized; | ||
| } | ||
|
|
||
| if (m_StartPos == new Vector2(0, 0)) | ||
| { | ||
| m_StartPos = transform.position; | ||
| m_Rigidbody = gameObject.GetComponent<Rigidbody2D>(); | ||
|
|
||
| Debug.Log(m_NormalizedDir); | ||
|
|
||
| //int Force = Random.Range(0, 10); | ||
| //m_Rigidbody.AddForce(new Vector2((normalizedDir.x + Random.Range(-0.1f, 0.1f)) * Force, normalizedDir.y * Force), ForceMode2D.Impulse); | ||
| } | ||
|
|
||
| //if (m_NoHit) | ||
| //{ | ||
| transform.position += new Vector3(m_NormalizedDir.x, m_NormalizedDir.y, 0) * Time.deltaTime * 4; | ||
| //} | ||
| //else | ||
| //{ | ||
| //transform.position += new Vector3(m_NormalizedDir.x, m_NormalizedDir.y, 0) * Time.deltaTime * 4; | ||
| //} | ||
|
|
||
| if(m_Destroy) | ||
| { | ||
| m_DestroyTimer -= Time.deltaTime; | ||
|
|
||
| if(m_DestroyTimer <= 0) | ||
| { | ||
| Destroy(gameObject); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void ShootMeteor(Vector2 dir, float force) | ||
| { | ||
| m_NormalizedDir = dir * force; | ||
| //Debug.Log(m_NormalizedDir); | ||
| m_NoHit = false; | ||
| m_Destroy = true; | ||
| } | ||
| } |
| @@ -0,0 +1,101 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
|
|
||
| public class SpawnController : MonoBehaviour | ||
| { | ||
| [SerializeField] | ||
| private GameObject[] m_Units; | ||
| private GameObject m_CrusadeLeader; | ||
|
|
||
| [SerializeField] | ||
| private GameObject[] m_Hazard; | ||
| [SerializeField] | ||
| private Vector2 m_HazardSpawnLoc; | ||
|
|
||
| private GameObject m_GameManagerObj; | ||
| private GameManager m_GameManager; | ||
| private GroupController m_GroupController; | ||
|
|
||
| private Coroutine m_ThreatController; | ||
| private float m_ThreatLevel; | ||
| private float m_HazardCooldown = 10; | ||
|
|
||
| void Start() | ||
| { | ||
| m_CrusadeLeader = GameObject.Find("CrusadeLeader"); | ||
| //m_GameManagerObj.GetComponent<GameManager>().m_CrusadeGroup.Add(m_CrusadeLeader); | ||
|
|
||
| m_GameManagerObj = GameObject.Find("GameManager"); | ||
| m_GameManager = m_GameManagerObj.GetComponent<GameManager>(); | ||
| m_GroupController = m_GameManagerObj.GetComponent<GroupController>(); | ||
|
|
||
| StartThreats(); | ||
|
|
||
| for (int i = 0; i < 10; i++) | ||
| { | ||
| SpawnUnit(0); | ||
| SpawnUnit(1); | ||
| } | ||
| } | ||
|
|
||
| void Update() | ||
| { | ||
| if (Input.GetKeyDown(KeyCode.Alpha1)) | ||
| { | ||
| BuyUnit(0); | ||
| } | ||
|
|
||
| if (Input.GetKeyDown(KeyCode.Alpha2)) | ||
| { | ||
| BuyUnit(1); | ||
| } | ||
|
|
||
| if (Input.GetKeyDown(KeyCode.Alpha3)) | ||
| { | ||
| BuyUnit(2); | ||
| } | ||
| } | ||
|
|
||
| public void BuyUnit(int unit) | ||
| { | ||
| if (m_GameManager.Buy() == true) | ||
| { | ||
| GameObject clone = Instantiate(m_Units[unit], new Vector3(m_CrusadeLeader.transform.position.x, m_CrusadeLeader.transform.position.y, 0), Quaternion.identity) as GameObject; | ||
| clone.name = "Knight_Type_" + unit; | ||
| m_GroupController.AddToGroupList(clone); | ||
| } | ||
| //m_GameManagerObj.GetComponent<GameManager>().m_CrusadeGroup.Add(clone); | ||
| } | ||
| public void SpawnUnit(int unit) | ||
| { | ||
| GameObject clone = Instantiate(m_Units[unit], new Vector3(m_CrusadeLeader.transform.position.x, m_CrusadeLeader.transform.position.y, 0), Quaternion.identity) as GameObject; | ||
| clone.name = "Knight_Type_" + unit; | ||
| m_GroupController.AddToGroupList(clone); | ||
| //m_GameManagerObj.GetComponent<GameManager>().m_CrusadeGroup.Add(clone); | ||
| } | ||
| public void SpawnThreat(int hazard) | ||
| { | ||
| GameObject clone = Instantiate(m_Hazard[hazard], m_HazardSpawnLoc + new Vector2(m_CrusadeLeader.transform.position.x + Random.Range(-4f, 4f), 7), Quaternion.identity) as GameObject; | ||
| clone.name = "Hazard_Type_" + hazard; | ||
|
|
||
| if (hazard == 0) | ||
| { | ||
| m_GameManagerObj.GetComponent<Swipe>().SetOTI.Add(clone); | ||
| } | ||
| } | ||
|
|
||
| public void StartThreats() | ||
| { | ||
| m_ThreatController = StartCoroutine(ThreatCaller(10)); | ||
| } | ||
|
|
||
| IEnumerator ThreatCaller(float waitTime) | ||
| { | ||
| yield return new WaitForSeconds(waitTime); | ||
|
|
||
| m_ThreatLevel = m_GameManagerObj.GetComponent<GameManager>().GetDistanceMade / 10; | ||
| SpawnThreat(Random.Range(0, m_Hazard.Length)); | ||
|
|
||
| m_ThreatController = StartCoroutine(ThreatCaller(10 - m_ThreatLevel));//m_HazardCooldown / m_ThreatLevel)); | ||
| } | ||
| } |
| @@ -0,0 +1,86 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
|
|
||
| public class Swipe : MonoBehaviour | ||
| { | ||
| [SerializeField] | ||
| private int m_SwipePower; | ||
| private bool m_Count = false; | ||
| private float m_SwipeForce = 1; | ||
|
|
||
| [SerializeField] | ||
| private List<GameObject> m_ObjectToInteract = new List<GameObject>(); | ||
| public List<GameObject> SetOTI | ||
| { | ||
| get { return m_ObjectToInteract; } | ||
| set { m_ObjectToInteract = value; } | ||
| } | ||
| private GameObject m_SelectedObj; | ||
| private Vector2 m_FirstPosition; | ||
| private Vector2 m_LastPosition; | ||
|
|
||
| void Update() | ||
| { | ||
| foreach (Touch touch in Input.touches) | ||
| { | ||
| if(touch.phase == TouchPhase.Began) | ||
| { | ||
| m_Count = true; | ||
| m_FirstPosition = touch.position; | ||
| m_LastPosition = touch.position; | ||
|
|
||
| } | ||
|
|
||
| if(touch.phase == TouchPhase.Moved) | ||
| { | ||
| m_LastPosition = touch.position; | ||
|
|
||
| Ray ray = Camera.main.ScreenPointToRay(m_FirstPosition); | ||
| RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction); | ||
|
|
||
| for (int i = 0; i < m_ObjectToInteract.Count; i++) | ||
| { | ||
| if (hit.collider != null && hit.collider.gameObject.tag == "Meteor") | ||
| { | ||
| m_SelectedObj = hit.collider.gameObject; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if(touch.phase == TouchPhase.Ended) | ||
| { | ||
| Vector2 dir = m_LastPosition - m_FirstPosition; | ||
| Vector2 normalizedDir = dir.normalized; | ||
|
|
||
| float distance = Vector2.Distance(m_LastPosition, m_FirstPosition); | ||
| Debug.Log(distance); | ||
|
|
||
| //Debug.Log(normalizedDir); | ||
|
|
||
| if (m_SelectedObj != null && distance > 30f) | ||
| { | ||
| //m_SelectedObj.GetComponent<Rigidbody2D>().AddForce(normalizedDir * m_SwipePower * m_SwipeForce * (distance / 10), ForceMode2D.Force); | ||
| //m_SelectedObj.transform.position += new Vector3(normalizedDir.x, normalizedDir.y, 0) * m_SwipePower * m_SwipeForce; | ||
| m_SelectedObj.GetComponent<Meteor>().ShootMeteor(normalizedDir, m_SwipePower * m_SwipeForce); | ||
| m_SelectedObj = null; | ||
| } | ||
|
|
||
| m_Count = false; | ||
| } | ||
| } | ||
|
|
||
| if (m_Count && m_SwipeForce > 0) | ||
| { | ||
| m_SwipeForce -= 1 * Time.deltaTime; | ||
| } | ||
| else | ||
| { | ||
| if (m_SwipeForce != 1) | ||
| { | ||
| m_SwipeForce = 1; | ||
| } | ||
| m_Count = false; | ||
| } | ||
| } | ||
| } |