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

public class Player : MonoBehaviour
{
	// The force which is added when the player jumps
	// This can be changed in the Inspector window
	public float upForce = 200f;
	public Vector2 jumpForce = new Vector2(0, 300);

	private bool isDead = false;
	private Rigidbody2D rb2d;
	void Start (){
		rb2d = GetComponent<Rigidbody2D> ();
	}

	// Update is called once per frame
	void Update ()
	{
		if (isDead == false) {
			// Jump
			if (Input.GetKeyUp ("space")) {
				GetComponent<Rigidbody2D> ().velocity = Vector2.zero;
				GetComponent<Rigidbody2D> ().AddForce (jumpForce);
			}
			Vector2 PosicaoTela = Camera.main.WorldToScreenPoint (transform.position);
			if (PosicaoTela.y > Screen.height || PosicaoTela.y < 0) {
				GameController.instance.Died ();
			}
		}

        if (Input.GetKey(KeyCode.Escape))
        {
            SceneManager.LoadScene("MainMenu");
        }
    }
	void OnCollisionEnter2D()
	{
		isDead = true;
		GameController.instance.Died ();

	}
}
