Commit 53d9eba4 authored by mthiele2's avatar mthiele2
Browse files
parents bd5a8e1c 9b6a1b80
...@@ -8,14 +8,20 @@ using _Game.Scripts.Scriptable_Object; ...@@ -8,14 +8,20 @@ using _Game.Scripts.Scriptable_Object;
public class PlayerAnimation : MonoBehaviour public class PlayerAnimation : MonoBehaviour
{ {
[Header("Scaling")] public AnimationCurve m_AirScale; [Header("Scaling")] public AnimationCurve m_AirScale;
public bool m_ScalingActive = true;
public float m_Time = 10f; public float m_Time = 10f;
public float m_SizePerCharge = 0.2f; public float m_SizePerCharge = 0.2f;
private Vector3 m_OriginScale;
private int m_PreviousAirCharges = 0;
private int m_CurrentAirCharges = 0;
[Header("Rotation")] public float m_Speed = 3f; [Header("Rotation")] public float m_Speed = 3f;
public bool m_RotationActive = false;
public float m_Radius = 1f; public float m_Radius = 1f;
public float m_RadiusSinDifference = 0.3f; public float m_RadiusSinDifference = 0.3f;
public float m_MaxScale = 0.3f; public float m_MaxScale = 0.3f;
public GameObject m_ElementPrefab; public GameObject m_ElementPrefab;
public Transform m_ElementOrbParent;
public Transform m_RotationOrigin; public Transform m_RotationOrigin;
public Vector2 m_RotationOriginOffset; public Vector2 m_RotationOriginOffset;
public Sprite m_AirSprite; public Sprite m_AirSprite;
...@@ -36,11 +42,7 @@ public class PlayerAnimation : MonoBehaviour ...@@ -36,11 +42,7 @@ public class PlayerAnimation : MonoBehaviour
private bool m_isAnimating = false; private bool m_isAnimating = false;
private bool m_isScaled = false; private bool m_isScaled = false;
private bool m_isRotating = false; private bool m_isRotating = false;
private int m_PreviousCharges = 0;
private Vector3 m_OriginSize;
private Vector2 m_OriginOffset;
private float m_OriginCheckDistance;
// Start is called before the first frame update // Start is called before the first frame update
...@@ -49,9 +51,7 @@ public class PlayerAnimation : MonoBehaviour ...@@ -49,9 +51,7 @@ public class PlayerAnimation : MonoBehaviour
r_Controller = GetComponent<MovementController>(); r_Controller = GetComponent<MovementController>();
r_Collider2D = GetComponent<CapsuleCollider2D>(); r_Collider2D = GetComponent<CapsuleCollider2D>();
m_OriginSize = transform.localScale; m_OriginScale = transform.localScale;
m_OriginOffset = r_Controller.GroundCheckOffset;
m_OriginCheckDistance = r_Controller.GroundCheckDistance;
m_ElementOrbTransforms = new List<GameObject>(); m_ElementOrbTransforms = new List<GameObject>();
m_ElementOrbRenderer = new List<SpriteRenderer>(); m_ElementOrbRenderer = new List<SpriteRenderer>();
...@@ -75,48 +75,71 @@ public class PlayerAnimation : MonoBehaviour ...@@ -75,48 +75,71 @@ public class PlayerAnimation : MonoBehaviour
switch (r_State.GetCurrentElement()) switch (r_State.GetCurrentElement())
{ {
case InfusedElement.None: case InfusedElement.None:
m_isRotating = false; if (m_ScalingActive) ScalePlayer();
SetRotationOrbsActive(false, 5);
ScalePlayer(); if (m_RotationActive)
break;
case InfusedElement.Air:
ScalePlayer();
SetRotationOrbsActive(true, r_State.GetCharges());
SetRotationOrbSprite(m_AirSprite);
if (!m_isRotating)
{ {
m_isRotating = true; m_isRotating = false;
StartCoroutine(RotatingElements()); SetRotationOrbsActive(false, 5);
} }
break;
case InfusedElement.Air:
m_CurrentAirCharges = r_State.GetCharges();
if (m_ScalingActive) ScalePlayer();
/*if(m_isRotating) {
SetRotationOrbsActive(true, r_State.GetCharges());
SetRotationOrbSprite(m_AirSprite);
if (!m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
}
}*/
break; break;
case InfusedElement.Fire: case InfusedElement.Fire:
SetRotationOrbsActive(true, r_State.GetCharges()); if(m_ScalingActive)transform.localScale = m_OriginScale;
SetRotationOrbSprite(m_FireSprite);
if (!m_isRotating) if (m_isRotating)
{ {
m_isRotating = true; SetRotationOrbsActive(true, r_State.GetCharges());
StartCoroutine(RotatingElements()); SetRotationOrbSprite(m_FireSprite);
if (!m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
}
} }
break; break;
case InfusedElement.Earth: case InfusedElement.Earth:
SetRotationOrbsActive(true, r_State.GetCharges()); if(m_ScalingActive)transform.localScale = m_OriginScale;
SetRotationOrbSprite(m_EarthSprite);
if (!m_isRotating) if (m_isRotating)
{ {
m_isRotating = true; SetRotationOrbsActive(true, r_State.GetCharges());
StartCoroutine(RotatingElements()); SetRotationOrbSprite(m_EarthSprite);
if (!m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
}
} }
break; break;
case InfusedElement.Water: case InfusedElement.Water:
SetRotationOrbsActive(true, r_State.GetCharges()); if(m_ScalingActive)transform.localScale = m_OriginScale;
SetRotationOrbSprite(m_WaterSprite);
if (!m_isRotating) if (m_isRotating)
{ {
m_isRotating = true; SetRotationOrbsActive(true, r_State.GetCharges());
StartCoroutine(RotatingElements()); SetRotationOrbSprite(m_WaterSprite);
if (!m_isRotating)
{
m_isRotating = true;
StartCoroutine(RotatingElements());
}
} }
break; break;
...@@ -126,24 +149,24 @@ public class PlayerAnimation : MonoBehaviour ...@@ -126,24 +149,24 @@ public class PlayerAnimation : MonoBehaviour
public void ScalePlayer() public void ScalePlayer()
{ {
int currentCharges = r_State.GetCharges(); int currentCharges = r_State.GetCharges();
int diff = currentCharges - m_PreviousCharges; int diff = currentCharges - m_PreviousAirCharges;
//Debug.Log("current: " + currentCharges + " previous: " + m_PreviousCharges + " difference: " + diff); //Debug.Log("current: " + currentCharges + " previous: " + m_PreviousCharges + " difference: " + diff);
if (!m_isAnimating || m_isAnimating) if (!m_isAnimating || m_isAnimating)
{ {
if (diff > 0) if (diff > 0)
{ {
StartCoroutine(ScaleUp(diff)); StartCoroutine(ScaleUp(m_PreviousAirCharges, currentCharges));
} }
else else
{ {
StartCoroutine(ScaleDown(diff)); StartCoroutine(ScaleDown(m_PreviousAirCharges, currentCharges));
} }
} }
m_PreviousCharges = currentCharges; m_PreviousAirCharges = currentCharges;
} }
private IEnumerator ScaleUp(int amount) private IEnumerator ScaleUp(int from, int to)
{ {
m_isAnimating = true; m_isAnimating = true;
m_isScaled = true; m_isScaled = true;
...@@ -151,20 +174,21 @@ public class PlayerAnimation : MonoBehaviour ...@@ -151,20 +174,21 @@ public class PlayerAnimation : MonoBehaviour
float step = 1 / m_Time; float step = 1 / m_Time;
float timer = 0.0f; float timer = 0.0f;
float x = 0f; float x = 0f;
float diff = to - from;
while (timer <= m_Time) while (timer <= m_Time)
{ {
x = m_SizePerCharge * Mathf.Abs(amount); x = m_SizePerCharge * Mathf.Abs(diff);
transform.localScale = Vector3.LerpUnclamped(s, s + new Vector3(x * Mathf.Sign(s.x), x, x), transform.localScale = Vector3.LerpUnclamped(s, s + new Vector3(x * Mathf.Sign(transform.localScale.x), x, x),
m_AirScale.Evaluate(timer / m_Time)); m_AirScale.Evaluate(timer / m_Time));
timer += Time.deltaTime; timer += Time.deltaTime;
yield return null; yield return null;
} }
transform.localScale = s + new Vector3(x * Mathf.Sign(s.x), x, x); transform.localScale = s + new Vector3(x * Mathf.Sign(transform.localScale.x), x, x);
m_isAnimating = false; m_isAnimating = false;
} }
private IEnumerator ScaleDown(int amount) private IEnumerator ScaleDown(int from, int to)
{ {
m_isAnimating = true; m_isAnimating = true;
m_isScaled = false; m_isScaled = false;
...@@ -172,10 +196,11 @@ public class PlayerAnimation : MonoBehaviour ...@@ -172,10 +196,11 @@ public class PlayerAnimation : MonoBehaviour
float step = 1 / m_Time; float step = 1 / m_Time;
float timer = 0.0f; float timer = 0.0f;
float x = 0; float x = 0;
float diff = to - from;
while (timer <= m_Time) while (timer <= m_Time)
{ {
x = m_SizePerCharge * Mathf.Abs(amount); x = m_SizePerCharge * Mathf.Abs(diff);
transform.localScale = Vector3.LerpUnclamped(s, s - new Vector3(x * Mathf.Sign(s.x), x, x), transform.localScale = Vector3.LerpUnclamped(s, s - new Vector3(x * Mathf.Sign(transform.localScale.x), x, x),
m_AirScale.Evaluate(timer / m_Time)); m_AirScale.Evaluate(timer / m_Time));
timer += Time.deltaTime; timer += Time.deltaTime;
yield return null; yield return null;
...@@ -183,11 +208,11 @@ public class PlayerAnimation : MonoBehaviour ...@@ -183,11 +208,11 @@ public class PlayerAnimation : MonoBehaviour
if (r_State.GetCharges() > 0) if (r_State.GetCharges() > 0)
{ {
transform.localScale = s - new Vector3(x * Mathf.Sign(s.x), x, x); transform.localScale = s - new Vector3(x * Mathf.Sign(transform.localScale.x), x, x);
} }
else else
{ {
transform.localScale = m_OriginSize; transform.localScale = m_OriginScale;
} }
m_isAnimating = false; m_isAnimating = false;
...@@ -202,15 +227,16 @@ public class PlayerAnimation : MonoBehaviour ...@@ -202,15 +227,16 @@ public class PlayerAnimation : MonoBehaviour
for (int i = 0; i < m_ElementOrbTransforms.Count; i++) for (int i = 0; i < m_ElementOrbTransforms.Count; i++)
{ {
pos = m_TimeCounter; pos = m_TimeCounter;
if(r_State.GetCharges() > 0) if (r_State.GetCharges() > 0)
pos = m_TimeCounter + i * Mathf.Deg2Rad * (360 / r_State.GetCharges()); pos = m_TimeCounter + i * Mathf.Deg2Rad * (360 / r_State.GetCharges());
float r = (m_Radius - m_RadiusSinDifference) + (m_RadiusSinDifference * Mathf.Sin(m_TimeCounter)); float r = (m_Radius - m_RadiusSinDifference) + (m_RadiusSinDifference * Mathf.Sin(m_TimeCounter));
float x = Mathf.Cos(pos) * r; float x = Mathf.Cos(pos) * r;
float y = Mathf.Sin(pos) * r; float y = Mathf.Sin(pos) * r;
Vector3 offset = m_RotationOriginOffset; Vector3 offset = m_RotationOriginOffset;
//Transform elem = m_ElementOrbTransforms[i].transform; //Transform elem = m_ElementOrbTransforms[i].transform;
m_ElementOrbTransforms[i].transform.position = m_RotationOrigin.position + offset + new Vector3(x, y, 0f); m_ElementOrbTransforms[i].transform.position =
m_RotationOrigin.position + offset + new Vector3(x, y, 0f);
yield return new WaitForFixedUpdate(); yield return new WaitForFixedUpdate();
} }
} }
...@@ -236,7 +262,6 @@ public class PlayerAnimation : MonoBehaviour ...@@ -236,7 +262,6 @@ public class PlayerAnimation : MonoBehaviour
for (int i = 0; i < m_ElementOrbRenderer.Count; i++) for (int i = 0; i < m_ElementOrbRenderer.Count; i++)
{ {
m_ElementOrbRenderer[i].sprite = s; m_ElementOrbRenderer[i].sprite = s;
} }
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment