using UnityEngine;
using System.Collections;

public class PlayerControllerScript : MonoBehaviour 
{
	float step = 5f;

	public Transform player1;
	string p1KeyPressed;
	string p2KeyPressed;
	public Transform player2;

	void Start()
	{

	}

	void Update()
	{
		//Player1 input
		if (Input.GetKeyDown ("w"))
		{
			p1KeyPressed = "w";
		}
		if (Input.GetKeyUp ("w"))
		{
			p1KeyPressed = "";
		}
		if (Input.GetKeyDown ("s"))
		{
			p1KeyPressed = "s";
		}
		if (Input.GetKeyUp ("s"))
		{
			p1KeyPressed = "";
		}
		if (Input.GetKeyDown ("a"))
		{
			p1KeyPressed = "a";
		}
		if (Input.GetKeyUp ("a"))
		{
			p1KeyPressed = "";
		}
		if (Input.GetKeyDown ("d"))
		{
			p1KeyPressed = "d";
		}
		if (Input.GetKeyUp ("d"))
		{
			p1KeyPressed = "";
		}

		//Player1 movement
		if (p1KeyPressed == "w")
		{
			//player1.rigidbody2D.AddForce( new Vector2 (1, 0.6f)*Time.fixedDeltaTime);
			player1.rigidbody2D.velocity = new Vector2 (20, 12f);
		}
		if (p1KeyPressed == "s")
		{
			//player1.rigidbody2D.AddForce( new Vector2 (-1, -0.6f)*Time.fixedDeltaTime);
			player1.rigidbody2D.velocity = new Vector2 (-20, -12f);
		}
		if (p1KeyPressed == "a")
		{
			//player1.rigidbody2D.AddForce( new Vector2 (-1, 0.6f)*Time.fixedDeltaTime);
			player1.rigidbody2D.velocity = new Vector2 (-20, 12f);
		}
		if (p1KeyPressed == "d")
		{
			//player1.rigidbody2D.AddForce( new Vector2 (1, -0.6f)*Time.fixedDeltaTime);
			player1.rigidbody2D.velocity = new Vector2 (20, -12f);
		}
		if (p1KeyPressed == "")
		{
			player1.rigidbody2D.velocity = new Vector2 (0, 0);		
		}
			
			//Player2 input
		if (Input.GetKeyDown (KeyCode.UpArrow))
		{
			p2KeyPressed = "up";
		}
		if (Input.GetKeyUp (KeyCode.UpArrow))
		{
			p2KeyPressed = "";
		}
		if (Input.GetKeyDown (KeyCode.DownArrow))
		{
			p2KeyPressed = "down";
		}
		if (Input.GetKeyUp (KeyCode.DownArrow))
		{
			p2KeyPressed = "";
		}
		if (Input.GetKeyDown (KeyCode.LeftArrow))
		{
			p2KeyPressed = "left";
		}
		if (Input.GetKeyUp (KeyCode.LeftArrow))
		{
			p2KeyPressed = "";
		}
		if (Input.GetKeyDown (KeyCode.RightArrow))
		{
			p2KeyPressed = "right";
		}
		if (Input.GetKeyUp (KeyCode.RightArrow))
		{
			p2KeyPressed = "";
		}

		//Player2 movement
		if (p2KeyPressed == "up")
		{
			//player2.rigidbody2D.AddForce( new Vector2 (1, 0.6f)*Time.fixedDeltaTime);
			player2.rigidbody2D.velocity = new Vector2 (20, 12f);
		}
		if (p2KeyPressed == "down")
		{
			//player2.rigidbody2D.AddForce( new Vector2 (-1, -0.6f)*Time.fixedDeltaTime);
			player2.rigidbody2D.velocity = new Vector2 (-20, -12f);
		}
		if (p2KeyPressed == "left")
		{
			//player2.rigidbody2D.AddForce( new Vector2 (-1, 0.6f)*Time.fixedDeltaTime);
			player2.rigidbody2D.velocity = new Vector2 (-20, 12f);
		}
		if (p2KeyPressed == "right")
		{
			//player2.rigidbody2D.AddForce( new Vector2 (1, -0.6f)*Time.fixedDeltaTime);
			player2.rigidbody2D.velocity = new Vector2 (20, -12f);
		}
		if (p2KeyPressed == "")
		{
			player2.rigidbody2D.velocity = new Vector2 (0, 0);		
		}
	}

	void FixedUpdate () 
	{

	}
}















