using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour {

    private int x, y;
    private float vel;
    private SpriteRenderer sr;

    void Awake()
    {
        // Four seconds
        Destroy(gameObject, 3);
    }

	void Start () {

        sr = this.GetComponent<SpriteRenderer>();

        vel = 0.2f;
        x = 0;
        y = 0;

        switch (Player.direction)
        {
            case 0:
                y = 1;
                break;

            case 1:
                x = 1;
                break;

            case 2:
                y = -1;
                break;

            case 3:
                x = -1;
                break;

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

        this.transform.Translate( new Vector3( ( vel *x ), ( vel *y ), 0 ) );

    }

    void OnCollisionEnter2D( Collision2D c )
    {
        if ( c.gameObject.tag == "Respawn" )
        {
            Destroy(gameObject);
        }
        
    }
}
