using UnityEngine;
using System.Collections;

public class ThrowScript : MonoBehaviour {
	public GameObject throwableRuby;
	public GameObject throwableDiamond;
	public GameObject throwableSaphire;
	public GameObject throwableEmerald;
	public GameObject throwableTopaz;

	public InventoryManager inv;

	void Start () {
	
	}
	

	void Update () {
		if (Input.GetKeyDown (KeyCode.Space)) {
			
			Vector3 p = transform.position;
			p.x += Mathf.Cos (PlayerController.direction * Mathf.Deg2Rad) /10f;
			p.y += .3f;
			p.z += Mathf.Sin (PlayerController.direction * Mathf.Deg2Rad) / 10f;
			GameObject g = null;
			if (inv.useItem(InventoryManager.activeItem)) {
				switch (InventoryManager.activeItem) {
				case "Ruby":
					g = Instantiate (throwableRuby,p, new Quaternion ()) as GameObject;
					break;
				case "Emerald":
					g = Instantiate (throwableEmerald,p, new Quaternion ()) as GameObject;
					break;
				case "Topaz":
					g = Instantiate (throwableTopaz,p, new Quaternion ()) as GameObject;
					break;
				case "Saphire":
					g = Instantiate (throwableSaphire,p, new Quaternion ()) as GameObject;
					break;
				case "Diamond":
					g = Instantiate (throwableDiamond,p, new Quaternion ()) as GameObject;
					break;
				}
			}
			if (g == null)
				return;
			Rigidbody r = g.GetComponent<Rigidbody> ();
			g.name = InventoryManager.activeItem;
			float fx = Mathf.Cos (PlayerController.direction * Mathf.Deg2Rad) * 100 ;
			float fy = Mathf.Sin (PlayerController.direction * Mathf.Deg2Rad) * 100;
			r.AddForce(new Vector3(fx,100 ,fy));

		}
	}
}
