using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
    public float speed;
    public float rotationSpeed;

    public GameObject gameManager;
    public float gameOverDelay;

    Animator anim;
    Rigidbody2D myRigidBody;

    private bool isMoving;

	// Use this for initialization
	void Start () {
        anim = GetComponent<Animator>();
        myRigidBody = GetComponent<Rigidbody2D>();
	
	}
	void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");


        transform.Rotate(0.0f, 0.0f, -moveHorizontal * rotationSpeed);	// Rotate the player
        myRigidBody.AddForce(transform.up * moveVertical * speed);	// Move the player in the direction they are facing

        if (moveVertical != 0)
        {
            isMoving = true;
        }
        else
        {
            isMoving = false;
            
        }

        Animation(isMoving);

        
    }
	// Update is called once per frame
	void Update () 
    {
        	
	}

    void Animation(bool isMoving)
    {
        anim.SetBool("Moving", isMoving);
    }

    void GameOver()
    {
        gameManager.SendMessage("GameOver", gameOverDelay);
    }
  
}
