using UnityEngine;
using System.Collections;

public class SwingArmJuice : MonoBehaviour {

	public Transform BounceFlashPrefab;
	public AudioClip BounceClip;

	private bool juicing=false;
	private int count=0;
	private GameController gc;

	// Use this for initialization
	void Start () {
		GameObject go = GameObject.Find ("GameController");
		gc = go.GetComponent<GameController>();

	}
	
	// Update is called once per frame
	void Update () {
	
	}
	/*
	void OnCollisionEnter2D(Collision2D coll) {
		if (coll.gameObject.tag == "Laser")
		{
			RunJuice((Vector3)coll.contacts[0].point);
		}
	}
	*/
	public void RunJuice(Vector3 pos)
	{
		count++;

		//Debug.Log ("Bounce # " + count + " juicing = " + juicing);
		if(!juicing)
		{
			juicing = true;
			//iTween.PunchScale (gameObject, iTween.Hash("amount", new Vector3(0.8f, 0.3f, 0f), "time", 0.2f, "oncomplete", "DoneJuicing"));
			iTween.ScaleFrom (gameObject, iTween.Hash("scale", new Vector3(1.5f, 0.7f, 0f), "time", 0.2f, "easetype", iTween.EaseType.easeOutQuad, "oncomplete", "DoneJuicing"));
			System.Threading.Thread.Sleep(50);
		}
		// todo play sound
		if(BounceFlashPrefab != null)
		{
			Transform flashObj = (Transform) GameObject.Instantiate(BounceFlashPrefab);
			flashObj.position = pos;
			flashObj.eulerAngles = transform.eulerAngles;
			flashObj.parent = gc.Player;
		}

		if(BounceClip != null)
			iTween.Stab(gameObject, iTween.Hash ("audioclip", BounceClip, "volume", gc.Volume));

	}

	void DoneJuicing()
	{
		juicing = false;
	}
}
