using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

    private SpriteRenderer sr;
    private float vel;
    public static int direction;

    public Sprite[] sprites;
    public GameObject bullet;
    

	// Use this for initialization
	void Start () {
        sr = this.GetComponent<SpriteRenderer>();
        vel = 4f;
        sr.sprite = sprites[2];
        direction = 2;
    }
	
	// Update is called once per frame
	void Update () {

        if ( Input.GetKey(KeyCode.W) )
        {
            direction = 0;
            sr.sprite = sprites[0];
            this.transform.Translate( new Vector3( 0, ( vel *Time.deltaTime ), 0 ) );
        }

        if ( Input.GetKey(KeyCode.D) )
        {
            direction = 1;
            sr.sprite = sprites[1];
            this.transform.Translate(new Vector3( ( vel * Time.deltaTime ), 0, 0 ) );
        }

        if ( Input.GetKey(KeyCode.S) )
        {
            direction = 2;
            sr.sprite = sprites[2];
            this.transform.Translate(new Vector3( 0, ( ( vel * Time.deltaTime ) * -1 ), 0 ) );
        }

        if ( Input.GetKey(KeyCode.A) )
        {
            direction = 3;
            sr.sprite = sprites[3];
            this.transform.Translate(new Vector3( ( ( vel * Time.deltaTime ) * -1 ), 0, 0 ) );
        }

        if ( Input.GetKeyDown(KeyCode.Space) )
        {
            Vector3 pos = new Vector3(transform.position.x +0.2f, transform.position.y -0.3f, 0 );
            Rigidbody2D go = (Instantiate( bullet, pos, transform.rotation) as GameObject).GetComponent<Rigidbody2D>();
            go.isKinematic = true;

        }

    }
}
