From c1582a88a1842e8e4524b70929df63891392eac1 Mon Sep 17 00:00:00 2001 From: RosimInc Date: Sat, 9 Apr 2016 16:11:22 -0400 Subject: [PATCH] Applied earthquake --- Assets/Prefabs/P_Shockwave.prefab | 2 +- Assets/Scripts/Astronaut.cs | 12 ++-- Assets/Scripts/Earthquake.cs | 100 ++++++++++++++--------------- Assets/Scripts/PlanetManager.cs | 18 ++++-- Assets/Test/EarthquakeTest.cs | 39 +++++++++++ Assets/Test/EarthquakeTest.cs.meta | 12 ++++ Assets/_Scenes/Main.unity | 58 +++++++++++++++++ 7 files changed, 177 insertions(+), 64 deletions(-) create mode 100644 Assets/Test/EarthquakeTest.cs create mode 100644 Assets/Test/EarthquakeTest.cs.meta diff --git a/Assets/Prefabs/P_Shockwave.prefab b/Assets/Prefabs/P_Shockwave.prefab index 24c63c4..48b9642 100644 --- a/Assets/Prefabs/P_Shockwave.prefab +++ b/Assets/Prefabs/P_Shockwave.prefab @@ -74,7 +74,7 @@ ParticleSystem: minMaxState: 0 speed: 1 randomSeed: 0 - looping: 1 + looping: 0 prewarm: 0 playOnAwake: 1 moveWithTransform: 1 diff --git a/Assets/Scripts/Astronaut.cs b/Assets/Scripts/Astronaut.cs index d3cf048..bbf9b0e 100644 --- a/Assets/Scripts/Astronaut.cs +++ b/Assets/Scripts/Astronaut.cs @@ -14,8 +14,8 @@ public class Astronaut : MonoBehaviour { public SpriteRenderer SpriteWalk; public GameObject SpriteDash; - public float Width; - public float Height; + public float SpriteWidth; + public float SpriteHeight; public float DashTime = 0.4f; //Temps de l'animation et rate limiting private float lastDashTime = 0f; public float StepTime; @@ -66,6 +66,10 @@ public class Astronaut : MonoBehaviour { private float theta = 0; private float height = 0; + public float Height + { + get { return height; } + } private float vSpeed = 0; private bool grounded = false; private bool walkRight = false; @@ -105,7 +109,7 @@ public class Astronaut : MonoBehaviour { private void UpdatePosition() { //float heightAtPos = planet.GetPlanetRadius(theta); - transform.localPosition = new Vector3(0, height + Height / 2, 0); + transform.localPosition = new Vector3(0, height + SpriteHeight / 2, 0); Rotator.transform.localRotation = Quaternion.Euler(0, 0, theta - 108); } @@ -116,7 +120,7 @@ public class Astronaut : MonoBehaviour { private float GetGroundRadius(float theta) { - float displacement = PlanetUtilities.GetDisplacementAngle(Width / 2, height); + float displacement = PlanetUtilities.GetDisplacementAngle(SpriteWidth / 2, height); float radius1 = planet.GetPlanetRadius(Repeat(theta + displacement, 360)); float radius2 = planet.GetPlanetRadius(Repeat(theta - displacement, 360)); //float x1, y1, x2, y2; diff --git a/Assets/Scripts/Earthquake.cs b/Assets/Scripts/Earthquake.cs index 6b68835..1fe03f4 100644 --- a/Assets/Scripts/Earthquake.cs +++ b/Assets/Scripts/Earthquake.cs @@ -6,75 +6,69 @@ public class Earthquake : MonoBehaviour { public float CriticalMin; public float CriticalMax; - //public float testValue; - - //public float gaugeLevel; - //public int gaugeMax=100; + public float ExplosionTime; + public GameObject ExplosionParticle; + private const float WaveSpeed = 1f; + private const float WaveOffset = 1.3f; + private SpriteRenderer core; - PlanetManager pmgr; + PlanetManager pmgr; + + bool isExploding; // Use this for initialization public void Start() { - pmgr = FindObjectOfType(); - //gaugeLevel = 0; + isExploding = false; + pmgr = FindObjectOfType(); core = this.GetComponent(); - //InvokeRepeating("FillGauge", 1, 1F); - } // Update is called once per frame public void Update () { + + if(!isExploding) return; + float disbalance = pmgr.GetDisbalance(); float val = Mathf.Clamp((disbalance-CriticalMin) / (CriticalMax-CriticalMin),0,1); float val2 = Mathf.Clamp((val - 0.6f) / 0.4f, 0, 1); pmgr.setColor(val2); - core.color = new Color(1f, 1f - val, 1f - val); - + core.color = new Color(1f, 1f - val, 1f - val); + + if (val2 >= 1f) + { + EarthquakeBoom(); + } + } + + void OnGUI() + { + if (GUI.Button(new Rect(100, 100, 50, 50), "BOOM")) + { + Debug.Log("Clicked the button with an image"); + EarthquakeBoom(); + } + } + + private void EarthquakeBoom() + { + isExploding = true; + StartCoroutine(Explode()); + Instantiate(ExplosionParticle); + } + + IEnumerator Explode() + { + float realPosition; + for (float i = 0; i < ExplosionTime; i += Time.deltaTime) + { + realPosition = WaveSpeed * i + WaveOffset; + Debug.Log(realPosition); + pmgr.EjectPlayers(realPosition); + yield return null; + } } - - /// - /// Actualiser l'affichage de la gauge - /// - public void UpdateFixed() - { - } - - /// - /// à être Appelé à chaque fois qu'on enfonce un plateau, le gage se remplis plus vite. (et par le temps) - /// - public void FillGauge() - { - - /*if (gaugeLevel < gaugeMax) - { - gaugeLevel += 1; - - //anim state [0-90] normale, rotation - - //color hue de plus en plus vers le rouge - - //[90-100] - //anim avec les ripples - - - } - else - { - - var planet = FindObjectOfType(); - - planet.CallEarthQuake(); - - gaugeLevel = 0; - - } - print("gauge is at: " + gaugeLevel);*/ - } - - - } diff --git a/Assets/Scripts/PlanetManager.cs b/Assets/Scripts/PlanetManager.cs index dc40528..45cf612 100644 --- a/Assets/Scripts/PlanetManager.cs +++ b/Assets/Scripts/PlanetManager.cs @@ -172,15 +172,21 @@ public class PlanetManager : MonoBehaviour v.sprite.transform.localScale = new Vector3(v.offset, v.offset, 1); // } - - - - // call fill gauge after every hit. - var earthQuakeGauge = FindObjectOfType(); - earthQuakeGauge.FillGauge(); + //var earthQuakeGauge = FindObjectOfType(); + //earthQuakeGauge.FillGauge(); } + public void EjectPlayers(float range) + { + Astronaut[] players = FindObjectsOfType(); + foreach (Astronaut p in players) + { + if (p.State < Astronaut.AstronautState.Ejecting && p.Height <= range) + p.Eject(); + } + } + /// /// On a earthquake, everything expands by a step /// diff --git a/Assets/Test/EarthquakeTest.cs b/Assets/Test/EarthquakeTest.cs new file mode 100644 index 0000000..eaef8d4 --- /dev/null +++ b/Assets/Test/EarthquakeTest.cs @@ -0,0 +1,39 @@ +using UnityEngine; +using System.Collections; + +public class EarthquakeTest : MonoBehaviour { + + public GameObject particle; + private GameObject obj; + + public float Mod1, Mod2; + + float timeSinceStart = 0; + + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update() + { + timeSinceStart += Time.deltaTime; + + if (Input.GetKeyDown(KeyCode.Space)) + { + if(obj!=null) + Destroy(obj); + obj = (GameObject)Instantiate(particle); + timeSinceStart = 0f; + } + + if( Input.GetKeyDown(KeyCode.C)) + { + Destroy(obj); + obj = null; + } + + Debug.DrawLine(Vector3.zero, new Vector3(Mod1 * timeSinceStart + Mod2, 0f, 0f)); + } +} diff --git a/Assets/Test/EarthquakeTest.cs.meta b/Assets/Test/EarthquakeTest.cs.meta new file mode 100644 index 0000000..5a23d3b --- /dev/null +++ b/Assets/Test/EarthquakeTest.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b478dc9d54d60fe4cb0b8a261ec5f65b +timeCreated: 1460226796 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scenes/Main.unity b/Assets/_Scenes/Main.unity index 4e03f69..3b1e178 100644 --- a/Assets/_Scenes/Main.unity +++ b/Assets/_Scenes/Main.unity @@ -316,6 +316,56 @@ Prefab: m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 158e745881137e04ca2086294f44d74c, type: 2} m_IsPrefabParent: 0 +--- !u!1001 &1166215621 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + propertyPath: m_LocalPosition.z + value: 0.11 + objectReference: {fileID: 0} + - target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 494126, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + propertyPath: m_RootOrder + value: 8 + objectReference: {fileID: 0} + - target: {fileID: 11494368, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + propertyPath: SpriteWidth + value: 0.4 + objectReference: {fileID: 0} + - target: {fileID: 11494368, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + propertyPath: SpriteHeight + value: 0.3 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: acd71c7b2f995984d9033c9dc4e257dc, type: 2} + m_IsPrefabParent: 0 --- !u!1001 &1223268487 Prefab: m_ObjectHideFlags: 0 @@ -413,6 +463,14 @@ Prefab: propertyPath: CriticalMax value: 0.9 objectReference: {fileID: 0} + - target: {fileID: 11401034, guid: 198e988adacced646a19f757f6237ae1, type: 2} + propertyPath: ExplosionTime + value: 10 + objectReference: {fileID: 0} + - target: {fileID: 11401034, guid: 198e988adacced646a19f757f6237ae1, type: 2} + propertyPath: ExplosionParticle + value: + objectReference: {fileID: 143434, guid: a63c057a7a113a349b55d0ae61d0c936, type: 2} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 198e988adacced646a19f757f6237ae1, type: 2} m_IsPrefabParent: 0