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

public class PlayerL1 : MonoBehaviour
{
    Rigidbody2D rb;
    public float movespeed;
    public float rotatamount;
    float rot;
    int Score;
    public GameObject winText;
    

    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Vector3 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            if (mousepos.x < 0)
            {
                rot = rotatamount;
            }

            else
            {
                rot = -rotatamount;
            }

            transform.Rotate(0, 0, rot); 
        }
    }


    private void FixedUpdate()
    {
        rb.velocity = transform.up * movespeed;
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if(collision.gameObject.tag == "Food")
        {
            Destroy(collision.gameObject);
            Score++;
            if(Score >= 5)
            {
                print("LevelComplet");
                winText.SetActive(true);
            }
            if (Score == 5)
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
            }
        }

        else if (collision.gameObject.tag == "Danger")
        {
            SceneManager.LoadScene("Game");
        }

    }    
            

            
}