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

public class PlayerMovement : MonoBehaviour {

	public CharacterController2D controller;
	public float runSpeed = 40f;
	public bool playerStarted;
	public EndCollider endCollider;

	float horizontalMove = 0f;
	bool jump = false;
	bool crouch = false;

	private Animator anim;
	public Vector2 startPos;

	void Start()
	{
		anim = GetComponent<Animator>();
		playerStarted = false;
		startPos = transform.position;
	}
	

	void Update () {

		if (Input.GetButtonDown("Jump") && playerStarted == false)
		{
			BeginRunning();
		}

		if (playerStarted)
		{

			anim.SetBool("isWalking", true);
			

			if (Input.GetButtonDown("Jump"))
			{
				//jump = true;
			}

			if (Input.GetButtonDown("Crouch"))
			{
				//crouch = true;
			}
			else if (Input.GetButtonUp("Crouch"))
			{
				//crouch = false;
			}
		}

	}

	void FixedUpdate ()
	{
		if (playerStarted)
		{
			// Move our character
			controller.Move(runSpeed * Time.fixedDeltaTime, crouch, jump);
			jump = false;
		}
	}

	public void BeginRunning()
	{
		if (endCollider.reached == false)
		{
			playerStarted = true;
			//FindObjectOfType<TimerScript>().canCount = false;
		}
	}
}
