using TMPro;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(AudioSource))]
public class Player : MonoBehaviour
{
	[Header("Controladores de Velocidade")]
	[SerializeField]
	private float limite;

	[SerializeField]
	private float valorReducao = 0.25f;

	[SerializeField]
	private float velocidade;

	[SerializeField]
	private float ReducaoBatida;

	[Space(10f)]
	[Header("Controladores de Pulo")]
	[SerializeField]
	private float forcaPulo;

	[SerializeField]
	private bool isGrounded = true;

	[SerializeField]
	private bool isJump = false;

	[SerializeField]
	private bool isRamp;

	[SerializeField]
	private bool isGrind;

	[SerializeField]
	private bool isDead;

	[Space(10f)]
	[Header("Rotação e Inclinação")]
	[SerializeField]
	private float velInclination = 3f;

	[SerializeField]
	private float velRotation = 90f;

	[SerializeField]
	private float latRot;

	[SerializeField]
	private float hRot = 0f;

	private Vector3 curNormal = Vector3.up;

	[SerializeField]
	private float rotX;

	[Space(10f)]
	[Header("Info")]
	[SerializeField]
	private Transform tr;

	[SerializeField]
	private Rigidbody rb;

	[SerializeField]
	private Transform CentroMass;

	[SerializeField]
	private GameObject CentroMassa;

	[SerializeField]
	private Transform raycastTr;

	[SerializeField]
	private Transform respawn;

	private float timer = 1.3f;

	private float inputX = 0f;

	private float inputY = 0f;

	[Space(10f)]
	[Header("Interface")]
	private int Pontos = 0;

	public static int pontuacao;

	public static bool reinicio = false;

	[SerializeField]
	private TextMeshProUGUI TextoPontos;

	[SerializeField]
	private TextMeshProUGUI TextoManobra;

	[SerializeField]
	private GameObject GManobras;

	[SerializeField]
	private Slider slider;

	[SerializeField]
	private GameObject Gslider;

	private VariableJoystick joystick;

	[SerializeField]
	private GameObject tutorial;

	[SerializeField]
	private TMP_Text tutorialText;

	private float tutorialTimer = 0f;

	[Space(10f)]
	[Header("Grind")]
	[SerializeField]
	private GameObject grind;

	[SerializeField]
	private Transform local;

	[SerializeField]
	private Transform pos;

	[SerializeField]
	private Transform inter;

	[SerializeField]
	private float velGrind = 0.1f;

	private float timeGrind = 0f;

	private float timeDead = 0f;

	private bool CR = false;

	private bool grindVer = false;

	private float equil = 0f;

	private float timeEquil = 4f;

	private bool seguirGrind = false;

	private bool intermedio = false;

	[Space(10f)]
	[Header("Animações e Audios")]
	[SerializeField]
	private float tempoRemadas;

	[SerializeField]
	private Animator m_Animator;

	[SerializeField]
	private AudioSource AS;

	[SerializeField]
	private AudioSource ABonus;

	private bool Goofy = false;

	[Space(10f)]
	[SerializeField]
	private AudioClip[] SAndando;

	[SerializeField]
	private AudioClip[] SPulo;

	[SerializeField]
	private AudioClip[] SAterrizando;

	[SerializeField]
	private AudioClip[] SManobras;

	[SerializeField]
	private AudioClip[] SRemada;

	[Space(10f)]
	[SerializeField]
	private AudioSource Agrind;

	[SerializeField]
	private AudioSource AmorteM;

	[SerializeField]
	private AudioSource AmorteF;

	private bool playgrind = false;

	private bool playmorte = false;

	private bool masc = true;

	[Space(10f)]
	[Header("Combos")]
	[SerializeField]
	private float timeX = 0f;

	[SerializeField]
	private float timeA = 0f;

	[SerializeField]
	private float timeB = 0f;

	[SerializeField]
	private float timeY = 0f;

	[SerializeField]
	private bool varX = false;

	[SerializeField]
	private bool varA = false;

	[SerializeField]
	private bool varB = false;

	[SerializeField]
	private bool varY = false;

	private float timeMan;

	[Space(10f)]
	[Header("Pontuações")]
	[SerializeField]
	private int flip;

	[SerializeField]
	private int popShoveIt;

	[SerializeField]
	private int flip360;

	[SerializeField]
	private int frontSideFlip;

	[SerializeField]
	private int grind50;

	[SerializeField]
	private int grindCrooked;

	[SerializeField]
	private int bonus;

	private bool grindou;

	private bool todos;

	[Space(10f)]
	[Header("Colecionaveis")]
	[SerializeField]
	private bool colect;

	[SerializeField]
	private GameObject colecionavel;

	[SerializeField]
	private TextMeshProUGUI TextoColecionaveis;

	[SerializeField]
	private int marca;

	[SerializeField]
	private int max;

	[SerializeField]
	private string[] marcas;

	[SerializeField]
	private GameManager m;

	private float timerColect;

	[SerializeField]
	private float multTimer = 20f;

	[SerializeField]
	private GameObject xDois;

	[SerializeField]
	private GameObject xQuatro;

	[SerializeField]
	private Image ImageDoisX;

	[SerializeField]
	private Image ImageQuatroX;

	private bool XDoisX = false;

	private bool XQuatroX = false;

	private int countFlip = 0;

	private int countPop = 0;

	private int countF360 = 0;

	private int countFrontf = 0;

	[SerializeField]
	private GameObject respMorte;

	private bool grama = false;

	private AreaMano areaMano;

	private bool mano = false;

	[SerializeField]
	private TMP_Text manoText;

	[SerializeField]
	private GameObject mano01;

	[SerializeField]
	private GameObject mano02;

	private void DoisX()
	{
		if (multTimer > 0f)
		{
			multTimer -= Time.deltaTime;
			ImageDoisX.fillAmount = multTimer / 20f;
		}
		else
		{
			xDois.SetActive(value: false);
			XDoisX = false;
		}
	}

	private void QuatroX()
	{
		if (multTimer > 0.5f)
		{
			multTimer -= Time.deltaTime;
			ImageQuatroX.fillAmount = multTimer / 20f;
		}
		else
		{
			xQuatro.SetActive(value: false);
			XQuatroX = false;
		}
	}

	private void Start()
	{
		joystick = GameObject.Find("Joystick").GetComponent<VariableJoystick>();
		if (PlayerPrefs.HasKey("tutorial"))
		{
			tutorial.SetActive(value: false);
		}
		else
		{
			Tutorial();
		}
	}

	private void Tutorial()
	{
		tutorialTimer += Time.deltaTime;
		if (tutorialTimer > 40f)
		{
			PlayerPrefs.SetInt("tutorial", 0);
		}
		else if (tutorialTimer > 30f)
		{
			tutorialText.text = "Dependo da manobra que você fizer, ganhará uma pontuação diferente. Vá em frente, divirta-se!";
		}
		else if (tutorialTimer > 20f)
		{
			tutorialText.text = "Para deslizar por corrimãos, enquanto estiver saltando por cima deles, aperte A ou Y. \nEquilibre-se no corrimão com o analógico.";
		}
		else if (tutorialTimer > 10f)
		{
			tutorialText.text = "Para pular (ollie) aperte o botão X. Para executar manobras, enquanto estiver pulando, aperte, \nA, B, Y ou X.";
		}
		else
		{
			tutorialText.text = "Para movimentar o personagem utilize o analógico à esquerda da tela, arrastando à frente acelera, \nà trás frea, e para os lados faz curvas.";
		}
	}

	private void Update()
	{
		if (PlayerPrefs.HasKey("tutorial"))
		{
			tutorial.SetActive(value: false);
		}
		else
		{
			Tutorial();
		}
		GroundCheck();
		AlignPlayerRamp();
		comandsPC();
		Timer();
		GrindAtt();
		Manobras();
		animacoesSons();
		textos();
		Outros();
		Morte();
		AreaManobra();
		if (!isDead)
		{
			if (!grindVer)
			{
				Movement();
				Aceleration();
				LatRotation();
				HorizRotation();
				equil = 0f;
			}
			else
			{
				GrindSlider();
				GrindControl();
				GrindInclin();
				AlignPlayerRamp();
			}
		}
		if (CentroMass.transform.rotation.z > 75f || CentroMass.transform.rotation.z < -75f)
		{
			CentroMass.rotation = new Quaternion(CentroMass.rotation.x, CentroMass.rotation.y, 0f, CentroMass.rotation.w);
		}
		if (CentroMass.transform.rotation.x > 75f || CentroMass.transform.rotation.x < -75f)
		{
			CentroMass.rotation = new Quaternion(0f, CentroMass.rotation.y, CentroMass.rotation.z, CentroMass.rotation.w);
		}
		if (CentroMass.transform.rotation.y > 75f || CentroMass.transform.rotation.y < -75f)
		{
			CentroMass.transform.rotation = new Quaternion(CentroMass.rotation.x, 0f, CentroMass.rotation.z, CentroMass.rotation.w);
		}
		if (XDoisX)
		{
			DoisX();
		}
		else if (XQuatroX)
		{
			QuatroX();
		}
		else
		{
			multTimer = 20f;
		}
		if (countFlip == 2)
		{
			countPop = 0;
			countF360 = 0;
			countFrontf = 0;
		}
		else if (countPop == 2)
		{
			countFlip = 0;
			countF360 = 0;
			countFrontf = 0;
		}
		else if (countF360 == 2)
		{
			countFlip = 0;
			countPop = 0;
			countFrontf = 0;
		}
		else if (countFrontf == 2)
		{
			countFlip = 0;
			countF360 = 0;
			countPop = 0;
		}
	}

	private void Morte()
	{
		if (isGrounded)
		{
			respMorte.transform.position = base.transform.position;
		}
		if (playgrind)
		{
			if (isGrind && !Agrind.isPlaying)
			{
				Agrind.Play();
			}
		}
		else if (Agrind.isPlaying)
		{
			Agrind.Stop();
		}
		if (playmorte)
		{
			if (masc)
			{
				if (isDead && !AmorteM.isPlaying)
				{
					AmorteM.Play();
				}
			}
			else if (isDead && !AmorteF.isPlaying)
			{
				AmorteF.Play();
			}
		}
		else if (masc)
		{
			if (AmorteM.isPlaying)
			{
				AmorteM.Stop();
			}
		}
		else if (AmorteF.isPlaying)
		{
			AmorteF.Stop();
		}
	}

	private void Movement()
	{
		velocidade = Mathf.Clamp(velocidade -= Time.deltaTime * valorReducao, 0f, limite);
		base.transform.Translate(0f, 0f, velocidade * Time.deltaTime);
	}

	private void AlignPlayerRamp()
	{
		if (!Physics.Raycast(raycastTr.position, -curNormal, out var hitInfo))
		{
			return;
		}
		curNormal = Vector3.Lerp(curNormal, hitInfo.normal, velInclination * Time.deltaTime);
		Quaternion quaternion = Quaternion.FromToRotation(Vector3.up, curNormal);
		if (!grindVer)
		{
			if (isGrounded)
			{
				CentroMass.rotation = quaternion * Quaternion.Euler(1f, hRot, 1f);
				if (isRamp)
				{
					base.transform.rotation = quaternion * Quaternion.Euler(1f, hRot, 0f);
				}
			}
		}
		else
		{
			CentroMass.rotation = quaternion * Quaternion.Euler(1f, hRot, 1f);
		}
	}

	private void HorizRotation()
	{
		if (Input.GetAxis("Horizontal") == 0f)
		{
			inputX = joystick.Horizontal;
		}
		else
		{
			inputX = Input.GetAxis("Horizontal");
		}
		if (inputX > 0.25f || inputX < -0.25f)
		{
			hRot += inputX * velRotation * Time.deltaTime;
		}
		if (!isRamp || !isGrounded)
		{
			base.transform.eulerAngles = new Vector3(0f, hRot, 0f);
		}
	}

	private void Aceleration()
	{
		if (Input.GetAxis("Vertical") == 0f)
		{
			inputY = joystick.Vertical;
		}
		else
		{
			inputY = Input.GetAxis("Vertical");
		}
		if (velocidade <= 17f && inputY > 0.5f)
		{
			Remada(8f);
		}
		if (inputY < -0.5f)
		{
			Freiar(5f);
		}
	}

	private void LatRotation()
	{
		m_Animator.SetFloat("InclinE", 0f - inputX);
		m_Animator.SetFloat("InclinD", inputX);
	}

	private void GroundCheck()
	{
		float maxDistance = 0.75f;
		if (Physics.Raycast(direction: new Vector3(0f, -1f), origin: raycastTr.position, hitInfo: out var hitInfo, maxDistance: maxDistance))
		{
			if (hitInfo.transform.tag == "chão")
			{
				isGrounded = true;
			}
			return;
		}
		isGrounded = false;
		if (!isJump && !isGrind && !isDead && !grindVer)
		{
			todos = true;
		}
	}

	private void Timer()
	{
		timer += Time.deltaTime;
		if (timer > 4f)
		{
			timer = 0f;
		}
	}

	private void comandsPC()
	{
		if (Input.GetKeyDown(KeyCode.Q))
		{
			A();
		}
		if (Input.GetKeyDown(KeyCode.E))
		{
			B();
		}
		if (Input.GetKeyDown(KeyCode.R))
		{
			Y();
		}
		if (Input.GetKeyDown(KeyCode.Space))
		{
			X();
		}
		if (Input.GetKeyDown(KeyCode.P))
		{
			Respawn();
		}
	}

	public void X()
	{
		if (!isJump)
		{
			if (seguirGrind && grindVer)
			{
				seguirGrind = false;
				grindVer = false;
				intermedio = false;
				hRot = base.transform.eulerAngles.y;
				Gslider.SetActive(value: false);
				timer = 4f;
				playgrind = false;
				Jump();
				velocidade += 8f;
				m_Animator.SetBool("Grind", value: false);
				m_Animator.SetBool("GrindCr", value: false);
			}
			else
			{
				Jump();
			}
		}
		else
		{
			FlipFrontSide();
		}
	}

	public void A()
	{
		if (isJump && isGrind)
		{
			Grind();
		}
		else if (!isGrind)
		{
			Flip();
		}
	}

	public void B()
	{
		Pop();
	}

	public void Y()
	{
		if (isJump && isGrind)
		{
			GrindCr();
		}
		else if (!isGrind)
		{
			Flip360();
		}
	}

	public void Respawn()
	{
		base.transform.position = respawn.position;
	}

	private void Freiar(float valor)
	{
		if (!isJump && isGrounded && timer >= tempoRemadas && !isDead)
		{
			timer = 0f;
			velocidade -= valor;
		}
	}

	private void Remada(float valor)
	{
		if (!isJump && isGrounded && timer >= tempoRemadas && !isDead)
		{
			if (!Goofy)
			{
				m_Animator.Play("Remando");
			}
			else
			{
				m_Animator.Play("Remando Goofy");
			}
			timer = 0f;
			AS.clip = SRemada[Random.Range(0, SRemada.Length)];
			AS.PlayOneShot(SRemada[Random.Range(0, SRemada.Length)]);
			velocidade += valor;
		}
	}

	private void Flip()
	{
		if (isJump && !m_Animator.GetBool("Flip") && !isDead)
		{
			AS.clip = SManobras[Random.Range(0, SManobras.Length)];
			AS.PlayOneShot(SManobras[Random.Range(0, SManobras.Length)]);
			m_Animator.SetBool("Flip", value: true);
		}
	}

	private void Pop()
	{
		if (isJump && !m_Animator.GetBool("Pop") && !isDead)
		{
			AS.clip = SManobras[Random.Range(0, SManobras.Length)];
			AS.PlayOneShot(SManobras[Random.Range(0, SManobras.Length)]);
			m_Animator.SetBool("Pop", value: true);
		}
	}

	private void Flip360()
	{
		if (isJump && !m_Animator.GetBool("Flip360") && !isDead)
		{
			AS.clip = SManobras[Random.Range(0, SManobras.Length)];
			AS.PlayOneShot(SManobras[Random.Range(0, SManobras.Length)]);
			m_Animator.SetBool("Flip360", value: true);
		}
	}

	private void FlipFrontSide()
	{
		if (isJump && !m_Animator.GetBool("FrontFlip") && !isDead)
		{
			AS.clip = SManobras[Random.Range(0, SManobras.Length)];
			AS.PlayOneShot(SManobras[Random.Range(0, SManobras.Length)]);
			m_Animator.SetBool("FrontFlip", value: true);
			if (!Goofy)
			{
				m_Animator.SetBool("Goofy", value: true);
				Goofy = true;
			}
			else
			{
				m_Animator.SetBool("Goofy", value: false);
				Goofy = false;
			}
		}
	}

	private void Jump()
	{
		if ((!isJump && isGrounded && !isDead) || (!isJump && isGrind && !isDead))
		{
			AS.clip = SPulo[Random.Range(0, SPulo.Length)];
			AS.PlayOneShot(SPulo[Random.Range(0, SPulo.Length)]);
			rb.velocity = Vector3.up * forcaPulo;
			velocidade += 3f;
			isJump = true;
			if (!Goofy)
			{
				m_Animator.Play("Ollie");
			}
			else
			{
				m_Animator.Play("Ollie Goofy");
			}
		}
	}

	private void Manobras()
	{
		if (m_Animator.GetBool("Flip"))
		{
			if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("AirM") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("AirM Goofy"))
			{
				m_Animator.SetBool("Flip", value: false);
				if (countFlip < 3)
				{
					if (XDoisX)
					{
						Pontos += flip * 2;
						GManobras.SetActive(value: true);
						TextoManobra.text = "FLIP +" + flip * 2;
						countFlip++;
					}
					else if (XQuatroX)
					{
						Pontos += flip * 4;
						GManobras.SetActive(value: true);
						TextoManobra.text = "FLIP +" + flip * 4;
						countFlip++;
					}
					else
					{
						Pontos += flip;
						GManobras.SetActive(value: true);
						TextoManobra.text = "FLIP +" + flip;
						countFlip++;
					}
				}
				else if (countFlip < 5)
				{
					if (XDoisX)
					{
						Pontos += flip / 2 * 2;
						GManobras.SetActive(value: true);
						TextoManobra.text = "FLIP +" + flip / 2 * 2;
						countFlip++;
					}
					else if (XQuatroX)
					{
						Pontos += flip / 2 * 4;
						GManobras.SetActive(value: true);
						TextoManobra.text = "FLIP +" + flip / 2 * 4;
						countFlip++;
					}
					else
					{
						Pontos += flip / 2;
						GManobras.SetActive(value: true);
						TextoManobra.text = "FLIP +" + flip / 2;
						countFlip++;
					}
				}
				else
				{
					GManobras.SetActive(value: true);
					TextoManobra.text = "FLIP +00";
				}
				if (mano)
				{
					areaMano.AttMano++;
				}
				timeMan = 0f;
			}
			else if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("TocandoChao") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("TocandoChao Goofy"))
			{
				m_Animator.SetBool("Caiu", value: true);
				m_Animator.SetBool("Flip", value: false);
				playmorte = true;
				isDead = true;
				velocidade = 0f;
			}
		}
		if (m_Animator.GetBool("Pop"))
		{
			if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("AirM") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("AirM Goofy"))
			{
				m_Animator.SetBool("Pop", value: false);
				if (countPop < 3)
				{
					if (XDoisX)
					{
						Pontos += popShoveIt * 2;
						GManobras.SetActive(value: true);
						TextoManobra.text = "POP SHOVE-IT +" + popShoveIt * 2;
						countPop++;
					}
					else if (XQuatroX)
					{
						Pontos += popShoveIt * 4;
						GManobras.SetActive(value: true);
						TextoManobra.text = "POP SHOVE-IT +" + popShoveIt * 4;
						countPop++;
					}
					else
					{
						Pontos += popShoveIt;
						GManobras.SetActive(value: true);
						TextoManobra.text = "POP SHOVE-IT +" + popShoveIt;
						countPop++;
					}
				}
				else if (countPop < 5)
				{
					if (XDoisX)
					{
						Pontos += popShoveIt / 2 * 2;
						GManobras.SetActive(value: true);
						TextoManobra.text = "POP SHOVE-IT +" + popShoveIt / 2 * 2;
						countPop++;
					}
					else if (XQuatroX)
					{
						Pontos += popShoveIt / 2 * 4;
						GManobras.SetActive(value: true);
						TextoManobra.text = "POP SHOVE-IT +" + popShoveIt / 2 * 4;
						countPop++;
					}
					else
					{
						Pontos += popShoveIt / 2;
						GManobras.SetActive(value: true);
						TextoManobra.text = "POP SHOVE-IT +" + popShoveIt / 2;
						countPop++;
					}
				}
				else
				{
					GManobras.SetActive(value: true);
					TextoManobra.text = "POP SHOVE-IT +00";
				}
				if (mano)
				{
					areaMano.AttMano++;
				}
				timeMan = 0f;
			}
			else if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("TocandoChao") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("TocandoChao Goofy"))
			{
				m_Animator.SetBool("Caiu", value: true);
				m_Animator.SetBool("Pop", value: false);
				playmorte = true;
				isDead = true;
				velocidade = 0f;
			}
		}
		if (m_Animator.GetBool("Flip360"))
		{
			if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("AirM") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("AirM Goofy"))
			{
				m_Animator.SetBool("Flip360", value: false);
				if (countF360 < 3)
				{
					if (XDoisX)
					{
						Pontos += flip360 * 2;
						GManobras.SetActive(value: true);
						TextoManobra.text = "360 FLIP +" + flip360 * 2;
						countF360++;
					}
					else if (XQuatroX)
					{
						Pontos += flip360 * 4;
						GManobras.SetActive(value: true);
						TextoManobra.text = "360 FLIP +" + flip360 * 4;
						countF360++;
					}
					else
					{
						Pontos += flip360;
						GManobras.SetActive(value: true);
						TextoManobra.text = "360 FLIP +" + flip360;
						countF360++;
					}
				}
				else if (countF360 < 5)
				{
					if (XDoisX)
					{
						Pontos += flip360 / 2 * 2;
						GManobras.SetActive(value: true);
						TextoManobra.text = "360 FLIP +" + flip360 / 2 * 2;
						countF360++;
					}
					else if (XQuatroX)
					{
						Pontos += flip360 / 2 * 4;
						GManobras.SetActive(value: true);
						TextoManobra.text = "360 FLIP +" + flip360 / 2 * 4;
						countF360++;
					}
					else
					{
						Pontos += flip360 / 2;
						GManobras.SetActive(value: true);
						TextoManobra.text = "360 FLIP +" + flip360 / 2;
						countF360++;
					}
				}
				else
				{
					GManobras.SetActive(value: true);
					TextoManobra.text = "360 FLIP +00";
				}
				if (mano)
				{
					areaMano.AttMano++;
				}
				timeMan = 0f;
			}
			else if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("TocandoChao") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("TocandoChao Goofy"))
			{
				m_Animator.SetBool("Caiu", value: true);
				m_Animator.SetBool("Flip360", value: false);
				playmorte = true;
				isDead = true;
				velocidade = 0f;
			}
		}
		if (!m_Animator.GetBool("FrontFlip"))
		{
			return;
		}
		if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("AirM") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("AirM Goofy"))
		{
			m_Animator.SetBool("FrontFlip", value: false);
			if (countFrontf < 3)
			{
				if (XDoisX)
				{
					Pontos += frontSideFlip * 2;
					GManobras.SetActive(value: true);
					TextoManobra.text = "FRONTSIDE FLIP +" + frontSideFlip * 2;
					countFrontf++;
				}
				else if (XQuatroX)
				{
					Pontos += frontSideFlip * 4;
					GManobras.SetActive(value: true);
					TextoManobra.text = "FRONTSIDE FLIP +" + frontSideFlip * 4;
					countFrontf++;
				}
				else
				{
					Pontos += frontSideFlip;
					GManobras.SetActive(value: true);
					TextoManobra.text = "FRONTSIDE FLIP +" + frontSideFlip;
					countFrontf++;
				}
			}
			else if (countFrontf < 5)
			{
				if (XDoisX)
				{
					Pontos += frontSideFlip / 2 * 2;
					GManobras.SetActive(value: true);
					TextoManobra.text = "FRONTSIDE FLIP +" + frontSideFlip / 2 * 2;
					countFrontf++;
				}
				else if (XQuatroX)
				{
					Pontos += frontSideFlip / 2 * 4;
					GManobras.SetActive(value: true);
					TextoManobra.text = "FRONTSIDE FLIP +" + frontSideFlip / 2 * 4;
					countFrontf++;
				}
				else
				{
					Pontos += frontSideFlip / 2;
					GManobras.SetActive(value: true);
					TextoManobra.text = "FRONTSIDE FLIP +" + frontSideFlip / 2;
					countFrontf++;
				}
			}
			else
			{
				GManobras.SetActive(value: true);
				TextoManobra.text = "FRONTSIDE FLIP +00";
			}
			if (mano)
			{
				areaMano.AttMano++;
			}
			timeMan = 0f;
		}
		else if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("TocandoChao") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("TocandoChao Goofy"))
		{
			m_Animator.SetBool("Caiu", value: true);
			m_Animator.SetBool("FrontFlip", value: false);
			playmorte = true;
			isDead = true;
			velocidade = 0f;
		}
	}

	private void animacoesSons()
	{
		if (!isJump && velocidade > 1f && !AS.isPlaying && !grindVer)
		{
			AS.clip = SAndando[Random.Range(0, SAndando.Length)];
			AS.Play();
		}
		if (!isJump && velocidade < 1f && AS.isPlaying)
		{
			AS.Stop();
		}
		if (isDead && timeDead < 5f)
		{
			timeDead += Time.deltaTime;
			if (masc)
			{
				if (timeDead >= AmorteM.clip.length)
				{
					playmorte = false;
				}
			}
			else if (timeDead >= AmorteF.clip.length)
			{
				playmorte = false;
			}
			if (timeDead > 2f && timeDead < 3f)
			{
				CentroMassa.SetActive(value: false);
			}
			else if (timeDead > 3f && timeDead < 4f)
			{
				m_Animator.SetBool("Caiu", value: false);
				base.transform.position = respMorte.transform.position;
				CentroMassa.SetActive(value: true);
				timeDead = 0f;
				isDead = false;
			}
		}
		if (todos)
		{
			if (!Goofy)
			{
				m_Animator.Play("Air");
			}
			else
			{
				m_Animator.Play("Air Goofy");
			}
		}
		if (Time.timeScale == 0f)
		{
			AS.Stop();
		}
	}

	private void textos()
	{
		if (Pontos < 10)
		{
			TextoPontos.text = "0000" + Pontos;
		}
		else if (Pontos < 100)
		{
			TextoPontos.text = "000" + Pontos;
		}
		else if (Pontos < 1000)
		{
			TextoPontos.text = "00" + Pontos;
		}
		else if (Pontos < 10000)
		{
			TextoPontos.text = "0" + Pontos;
		}
		else
		{
			TextoPontos.text = Pontos.ToString();
		}
		if (timeMan < 5f)
		{
			timeMan += Time.deltaTime;
			if (GManobras.activeSelf && timeMan >= 3f)
			{
				TextoManobra.text = null;
				GManobras.SetActive(value: false);
				timeMan = 0f;
			}
		}
		if (colect)
		{
			timerColect += Time.deltaTime;
			if (timerColect >= 3.5f)
			{
				colecionavel.SetActive(value: false);
				timerColect = 0f;
			}
		}
		if ((mano && mano01.activeSelf) || (mano && mano02.activeSelf))
		{
			timerColect += Time.deltaTime;
			if (timerColect >= 3.5f)
			{
				if (mano01.activeSelf)
				{
					mano01.SetActive(value: false);
					timerColect = 0f;
				}
				if (mano02.activeSelf)
				{
					mano02.SetActive(value: false);
					timerColect = 0f;
					mano = false;
				}
			}
		}
		if (pontuacao != Pontos)
		{
			pontuacao = Pontos;
		}
		if (reinicio && Pontos != 0)
		{
			Pontos = 0;
			reinicio = false;
		}
	}

	private void Outros()
	{
		if (base.transform.position.y < -15f)
		{
			base.transform.position = respawn.position;
		}
		if (m_Animator.GetCurrentAnimatorStateInfo(0).IsName("AirM") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("Air") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("AirM Goofy") || m_Animator.GetCurrentAnimatorStateInfo(0).IsName("Air Goofy"))
		{
			CentroMass.rotation = new Quaternion(0f, CentroMass.rotation.y, 0f, CentroMass.rotation.w);
		}
		if (!isGrind && Gslider.activeSelf)
		{
			Gslider.SetActive(value: false);
		}
	}

	private void Grind()
	{
		playgrind = true;
		velocidade = 0f;
		hRot = local.transform.eulerAngles.y;
		rb.velocity = Vector3.zero;
		base.transform.position = pos.position;
		base.transform.rotation = local.rotation;
		m_Animator.SetBool("Grind", value: true);
		seguirGrind = true;
		isJump = false;
		grindVer = true;
		Gslider.SetActive(value: true);
	}

	private void GrindCr()
	{
		playgrind = true;
		velocidade = 0f;
		hRot = local.transform.eulerAngles.y;
		rb.velocity = Vector3.zero;
		base.transform.position = pos.position;
		base.transform.rotation = local.rotation;
		m_Animator.SetBool("GrindCr", value: true);
		seguirGrind = true;
		isJump = false;
		grindVer = true;
		Gslider.SetActive(value: true);
	}

	private void GrindSlider()
	{
		timeEquil += Time.deltaTime;
		if (timeEquil >= 1.5f && equil == 0f)
		{
			equil = Random.Range(-30, 30);
			if (equil > 0f && equil != 0f)
			{
				equil = 30f;
			}
			else if (equil < 0f && equil != 0f)
			{
				equil = -30f;
			}
			else if (equil == 0f)
			{
				equil = 30f;
			}
		}
		if (timeEquil > 4f)
		{
			timeEquil = 0f;
		}
	}

	private void GrindAtt()
	{
		if (slider.value <= equil)
		{
			slider.value += 10f * Time.deltaTime;
		}
		else if (slider.value >= equil)
		{
			slider.value -= 10f * Time.deltaTime;
		}
		else if (slider.value - equil <= 1f || slider.value - equil >= -1f)
		{
			slider.value = equil;
		}
		else
		{
			slider.value = equil;
		}
	}

	private void GrindControl()
	{
		if (seguirGrind)
		{
			if (intermedio)
			{
				if (Vector3.Distance(base.transform.position, inter.position) <= 1.5f)
				{
					intermedio = false;
				}
				else
				{
					base.transform.position = Vector3.MoveTowards(base.transform.position, inter.position, velGrind * Time.deltaTime);
				}
			}
			else if (!intermedio)
			{
				base.transform.position = Vector3.MoveTowards(base.transform.position, local.position, velGrind * Time.deltaTime);
			}
		}
		timeGrind += Time.deltaTime;
		if (timeGrind > 1f)
		{
			if (!CR)
			{
				if (XDoisX)
				{
					Pontos += grind50 * 2;
					GManobras.SetActive(value: true);
					TextoManobra.text = "50-50 GRIND +" + grind50 * 2;
				}
				else if (XQuatroX)
				{
					Pontos += grind50 * 4;
					GManobras.SetActive(value: true);
					TextoManobra.text = "50-50 GRIND +" + grind50 * 4;
				}
				else
				{
					Pontos += grind50;
					GManobras.SetActive(value: true);
					TextoManobra.text = "50-50 GRIND +" + grind50;
				}
				timeMan = 0f;
				timeGrind = 0f;
			}
			else
			{
				if (XDoisX)
				{
					Pontos += grindCrooked * 2;
					GManobras.SetActive(value: true);
					TextoManobra.text = "CROOCKED GRIND +" + grindCrooked * 2;
				}
				else if (XQuatroX)
				{
					Pontos += grindCrooked * 4;
					GManobras.SetActive(value: true);
					TextoManobra.text = "CROOCKED GRIND +" + grindCrooked * 4;
				}
				else
				{
					Pontos += grindCrooked;
					GManobras.SetActive(value: true);
					TextoManobra.text = "CROOCKED GRIND +" + grindCrooked;
				}
				timeMan = 0f;
				timeGrind = 0f;
			}
		}
		if (Vector3.Distance(base.transform.position, local.position) <= 1.5f)
		{
			Pontos += grind50;
			seguirGrind = false;
			grindVer = false;
			intermedio = false;
			hRot = base.transform.eulerAngles.y;
			Gslider.SetActive(value: false);
			timer = 4f;
			playgrind = false;
			Jump();
			velocidade += 8f;
			m_Animator.SetBool("Grind", value: false);
			m_Animator.SetBool("GrindCr", value: false);
		}
	}

	private void GrindInclin()
	{
		if (Input.GetAxis("Horizontal") == 0f)
		{
			inputX = joystick.Horizontal;
		}
		else
		{
			inputX = Input.GetAxis("Horizontal");
		}
		slider.value += inputX / 2.5f;
		m_Animator.SetFloat("GrindEquil", slider.value);
		if (slider.value > 25f)
		{
			m_Animator.SetBool("Caiu", value: true);
			grindVer = false;
			isDead = true;
			velocidade = 0f;
			base.transform.Translate(0.8f, 0f, 0f);
			Gslider.SetActive(value: false);
			playgrind = false;
			isGrind = false;
		}
		if (slider.value < -25f)
		{
			m_Animator.SetBool("Caiu", value: true);
			grindVer = false;
			isDead = true;
			velocidade = 0f;
			base.transform.Translate(-0.8f, 0f, 0f);
			Gslider.SetActive(value: false);
			playgrind = false;
			isGrind = false;
		}
	}

	public void OnCollisionEnter(Collision collision)
	{
		if (collision.gameObject.tag == "Parede" && velocidade > 13f)
		{
			velocidade -= ReducaoBatida;
			hRot += 120f;
		}
		if (collision.gameObject.tag == "chão")
		{
			isGrounded = true;
			if (isJump || grindou || todos)
			{
				AS.clip = SAterrizando[Random.Range(0, SAterrizando.Length)];
				AS.PlayOneShot(SAterrizando[Random.Range(0, SAterrizando.Length)]);
				if (!Goofy)
				{
					m_Animator.Play("TocandoChao");
					m_Animator.SetBool("Grind", value: false);
					m_Animator.SetBool("GrindCr", value: false);
				}
				else
				{
					m_Animator.Play("TocandoChao Goofy");
					m_Animator.SetBool("Grind", value: false);
					m_Animator.SetBool("GrindCr", value: false);
				}
				isJump = false;
				grindou = false;
				todos = false;
			}
		}
		if (collision.gameObject.tag == "grama")
		{
			if (!Goofy)
			{
				m_Animator.Play("TocandoChao");
			}
			else
			{
				m_Animator.Play("TocandoChao Goofy");
			}
			m_Animator.SetBool("Caiu", value: true);
			m_Animator.SetBool("Flip", value: false);
			playmorte = true;
			isDead = true;
			velocidade = 0f;
		}
	}

	public void OnCollisionExit(Collision collision)
	{
		if (collision.gameObject.tag == "chão")
		{
			isGrounded = false;
		}
	}

	public void OnTriggerEnter(Collider other)
	{
		if (other.gameObject.tag == "grind")
		{
			isGrind = true;
			grind = other.gameObject.transform.parent.gameObject;
			pos = other.gameObject.transform.GetChild(0);
			inter = null;
			intermedio = false;
			if (grind.GetComponent<Grind>().dir)
			{
				local = grind.transform.GetChild(0);
			}
			else if (!grind.GetComponent<Grind>().dir)
			{
				local = grind.transform.GetChild(1);
			}
		}
		if (other.gameObject.tag == "grindInter")
		{
			isGrind = true;
			grind = other.gameObject.transform.parent.gameObject;
			pos = other.gameObject.transform.GetChild(0);
			inter = grind.transform.GetChild(2);
			intermedio = true;
			if (grind.GetComponent<Grind>().dir)
			{
				local = grind.transform.GetChild(0);
			}
			else if (!grind.GetComponent<Grind>().dir)
			{
				local = grind.transform.GetChild(1);
			}
		}
		if (other.gameObject.tag == "Rampa" && !isRamp)
		{
			isRamp = true;
		}
		if (other.gameObject.tag == "Colect")
		{
			marca = other.gameObject.GetComponent<Colect>().marca;
			max = other.gameObject.GetComponent<Colect>().max;
			if (marca == 1)
			{
				TextoColecionaveis.text = marcas[0] + " - " + m.marca01 + " de " + max;
				colecionavel.SetActive(value: true);
				colect = true;
			}
			else if (marca == 2)
			{
				TextoColecionaveis.text = marcas[1] + " - " + m.marca02 + " de " + max;
				colecionavel.SetActive(value: true);
				colect = true;
			}
			else if (marca == 3)
			{
				TextoColecionaveis.text = marcas[2] + " - " + m.marca03 + " de " + max;
				colecionavel.SetActive(value: true);
				colect = true;
			}
		}
		if (other.gameObject.tag == "Bonus")
		{
			Pontos += bonus;
			TextoManobra.text = "BONUS +" + bonus;
			ABonus.PlayOneShot(ABonus.clip);
			Object.Destroy(other.gameObject.transform.parent.gameObject);
		}
		if (other.gameObject.tag == "doisX")
		{
			XQuatroX = false;
			xQuatro.SetActive(value: false);
			multTimer = 20f;
			xDois.SetActive(value: true);
			XDoisX = true;
			ABonus.PlayOneShot(ABonus.clip);
			Object.Destroy(other.gameObject.transform.parent.gameObject);
		}
		if (other.gameObject.tag == "quatroX")
		{
			XDoisX = false;
			xDois.SetActive(value: false);
			multTimer = 20f;
			xQuatro.SetActive(value: true);
			XQuatroX = true;
			ABonus.PlayOneShot(ABonus.clip);
			Object.Destroy(other.gameObject.transform.parent.gameObject);
		}
		if (other.gameObject.tag == "grama")
		{
			m_Animator.SetBool("Caiu", value: true);
			m_Animator.SetBool("Flip", value: false);
			playmorte = true;
			isDead = true;
			velocidade = 0f;
			base.transform.position = respMorte.transform.position;
		}
		if (other.gameObject.tag == "mano")
		{
			areaMano = other.gameObject.GetComponent<AreaMano>();
			mano = true;
			if (!mano01.activeSelf)
			{
				mano01.SetActive(value: true);
			}
		}
	}

	private void OnTriggerExit(Collider other)
	{
		if (other.gameObject.tag == "Rampa")
		{
			isRamp = false;
		}
		if (other.gameObject.tag == "grindInter")
		{
			isGrind = false;
			intermedio = false;
		}
		if (other.gameObject.tag == "grind")
		{
			isGrind = false;
			intermedio = false;
		}
		if (other.gameObject.tag == "grama")
		{
			grama = false;
		}
		if (other.gameObject.tag == "mano")
		{
			areaMano = null;
			mano = false;
		}
	}

	private void OnTriggerStay(Collider other)
	{
		if (other.gameObject.tag == "grindInter")
		{
			isGrind = true;
		}
		if (other.gameObject.tag == "grind")
		{
			isGrind = true;
		}
	}

	private void AreaManobra()
	{
		if (mano)
		{
			if (mano01.activeSelf)
			{
				manoText.text = "Realize - 0" + areaMano.TotalMano + " manobras";
			}
			if (areaMano.AttMano >= areaMano.TotalMano)
			{
				mano02.SetActive(value: true);
			}
		}
	}
}