[Refactor] General cleanup
This commit is contained in:
@@ -6,20 +6,6 @@ using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
public class PlayerController : OrbitalPositionBehaviour
|
||||
{
|
||||
public static int s_PlayerScore;
|
||||
private static int s_HighScore = 20;
|
||||
|
||||
private static PlayerController s_Instance;
|
||||
public static bool IsPlayerAttached => s_Instance.m_OrbitalPosition.m_IsAttachedToRings;
|
||||
public static void AttachPlayer() { s_Instance.m_OrbitalPosition.m_IsAttachedToRings = true; }
|
||||
|
||||
private Vector3 m_SuicidePoint;
|
||||
private bool m_KillingItself;
|
||||
private float m_DeathLerp;
|
||||
|
||||
private bool m_HasFreeHitActive;
|
||||
private bool m_HasInvicibility;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private MeshRenderer m_Renderer;
|
||||
[SerializeField] private Text m_ScoreText;
|
||||
@@ -27,9 +13,22 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
[SerializeField] private Material m_FreeHitMaterial;
|
||||
[SerializeField] private PostProcessVolume m_PostProcessVolume;
|
||||
|
||||
private static PlayerController Instance;
|
||||
public static bool IsPlayerAttached => Instance.m_OrbitalPosition.m_IsAttachedToRings;
|
||||
|
||||
private static int s_HighScore = 20;
|
||||
public static int s_PlayerScore;
|
||||
|
||||
private Vector3 m_SuicidePoint;
|
||||
private float m_DeathLerp;
|
||||
|
||||
private bool m_HasFreeHitActive;
|
||||
private bool m_HasInvincibility;
|
||||
private bool m_KillingItself;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
s_Instance = this;
|
||||
Instance = this;
|
||||
s_HighScore = Mathf.Max(s_HighScore, PlayerPrefs.GetInt("HighScore", 0));
|
||||
Debug.Log($"Loaded high score of [{s_HighScore}]");
|
||||
|
||||
@@ -42,15 +41,9 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
public void Update()
|
||||
{
|
||||
m_ScoreText.text = s_PlayerScore.ToString();
|
||||
if (s_PlayerScore > s_HighScore)
|
||||
m_ScoreText.color = Color.yellow;
|
||||
else
|
||||
m_ScoreText.color = Color.white;
|
||||
|
||||
if (m_HasFreeHitActive)
|
||||
m_Renderer.material = m_FreeHitMaterial;
|
||||
else
|
||||
m_Renderer.material = m_DefaultMaterial;
|
||||
|
||||
m_ScoreText.color = s_PlayerScore > s_HighScore ? Color.yellow : Color.white;
|
||||
m_Renderer.material = m_HasFreeHitActive ? m_FreeHitMaterial : m_DefaultMaterial;
|
||||
|
||||
if (GlobalInput.IsScreenClicked && GlobalOrbitalPositionManager.AllowPlayerInput)
|
||||
{
|
||||
@@ -63,6 +56,11 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
transform.position = Vector3.Lerp(m_SuicidePoint, m_SuicidePoint.normalized * 20f, m_DeathLerp);
|
||||
m_DeathLerp += Time.deltaTime;
|
||||
}
|
||||
|
||||
public static void AttachPlayer()
|
||||
{
|
||||
Instance.m_OrbitalPosition.m_IsAttachedToRings = true;
|
||||
}
|
||||
|
||||
private IEnumerator OnGrowPlayerModifier()
|
||||
{
|
||||
@@ -86,14 +84,14 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
m_OrbitalPosition.m_ObjectRadius /= 0.6f;
|
||||
}
|
||||
|
||||
private IEnumerator TriggerInvicibility()
|
||||
private IEnumerator TriggerInvincibility()
|
||||
{
|
||||
m_HasFreeHitActive = false;
|
||||
m_HasInvicibility = true;
|
||||
m_HasInvincibility = true;
|
||||
|
||||
yield return new WaitForSecondsRealtime(1f);
|
||||
|
||||
m_HasInvicibility = false;
|
||||
m_HasInvincibility = false;
|
||||
}
|
||||
|
||||
public override void OnCollision(OrbitalPositionBehaviour other)
|
||||
@@ -103,14 +101,14 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
|
||||
if (other.CompareTag("Enemy"))
|
||||
{
|
||||
if (m_HasInvicibility)
|
||||
if (m_HasInvincibility)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_HasFreeHitActive)
|
||||
{
|
||||
StartCoroutine(TriggerInvicibility());
|
||||
StartCoroutine(TriggerInvincibility());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -122,34 +120,34 @@ public class PlayerController : OrbitalPositionBehaviour
|
||||
|
||||
else if (other.CompareTag("PlayerMod"))
|
||||
{
|
||||
switch (((PlayerModifier)other).HeldModifier)
|
||||
switch (((PlayerModifier)other).Modifier)
|
||||
{
|
||||
case PlayerModifier.Modifier.GainPoints:
|
||||
case PlayerModifier.Modifiers.GainPoints:
|
||||
s_PlayerScore += 100;
|
||||
break;
|
||||
|
||||
case PlayerModifier.Modifier.FreeHit:
|
||||
case PlayerModifier.Modifiers.FreeHit:
|
||||
m_HasFreeHitActive = true;
|
||||
break;
|
||||
|
||||
case PlayerModifier.Modifier.GrowPlayer:
|
||||
case PlayerModifier.Modifiers.GrowPlayer:
|
||||
StartCoroutine(OnGrowPlayerModifier());
|
||||
break;
|
||||
|
||||
case PlayerModifier.Modifier.ShrinkPlayer:
|
||||
case PlayerModifier.Modifiers.ShrinkPlayer:
|
||||
StartCoroutine(OnShrinkPlayerModifier());
|
||||
break;
|
||||
|
||||
case PlayerModifier.Modifier.SpeedUp:
|
||||
case PlayerModifier.Modifiers.SpeedUp:
|
||||
StartCoroutine(GlobalOrbitalPositionManager.Instance.StartPlayerSpeedupModifier());
|
||||
break;
|
||||
|
||||
case PlayerModifier.Modifier.ClearAllEnemies:
|
||||
case PlayerModifier.Modifiers.ClearAllEnemies:
|
||||
EnemyController.KillAllEnemies();
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.Log($"Collision with unknown modifier occured [{((PlayerModifier)other).HeldModifier}]");
|
||||
Debug.Log($"Collision with unknown modifier occured [{((PlayerModifier)other).Modifier}]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user