using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerBahaviour : MonoBehaviour
{
    /* GUIA DEV TEM TODAS EXPLICA�OES DENTRO DA PASTA EXTRAS */
    public bool dead;
    public bool concluido;
    public Rigidbody2D playerRD;
    public float velocity;
    public float forceJp;
    public bool onGd;
    public bool onladder;
    public float direction;
    public Transform foot;
    public LayerMask gdLay;
    public bool rightlook = true;
    public Animator aniPlayer;
    public AudioSource soundPlayer;
    public AudioClip pulosnd;
    public AudioClip getiten;
    void Start()
    {
        
    }


    void Update()
    {
        onGd = Physics2D.OverlapCircle(foot.position, 0.3f, gdLay);
        direction = Input.GetAxisRaw("Horizontal");
        playerRD.velocity = new Vector2(direction * velocity, playerRD.velocity.y);
        if ((direction < 0 && rightlook) || (direction > 0 && !rightlook))
        {
            rightlook = !rightlook;
            transform.Rotate(0, 180f, 0);
        }
        if (!onladder && onGd && Input.GetButtonDown("Jump"))
        {
            playerRD.velocity = Vector2.up * forceJp;
            soundPlayer.clip = pulosnd;
            soundPlayer.Play();
        }
        if (concluido)
        {
            FindObjectOfType<Npc001>().missionConplete = true;
        }
        aniPlayer.SetFloat("Correndo", Mathf.Abs(direction));
        aniPlayer.SetBool("Pulando", !onGd);
        aniPlayer.SetFloat("VeloY", playerRD.velocity.y);
    }
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "ladder")
        { 
            onladder = true;
        }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
            onladder = false;
    }
}
