using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ZoidSmash : MonoBehaviour {

    public bool PunchClock=true;
    public List<Transform> ThreatSpawns;
    public List<Transform> Debris;
    public float ThreatDropDist;
    public float ThreatDropSpread;
    public AudioClip StruckClip;

	void Start () {
	
	}	

	public void Smash(Vector2 dir)
    {
        GetComponent<Collider2D>().enabled = false;
        GetComponent<Rigidbody2D>().isKinematic = true;

        if (PunchClock)
        {
            if (StruckClip != null)
                iTween.Stab(Camera.main.gameObject, StruckClip, 0f);

            transform.localScale *= 1.3f;
            ClockControl.Punch(0.01f);
            Invoke("SpawnThreats", 0.05f);
            GameObject.Destroy(gameObject, 0.1f);
        }
        else
        {
            GameObject.Destroy(gameObject);
        }
    }

    private void SpawnThreats()
    {
        //Vector2 dir = -smashDir;
        //Vector2 orth = new Vector2(-dir.y, dir.x);

        foreach(Transform prefab in ThreatSpawns)
        {
            Transform t = GameObject.Instantiate(prefab);
            t.position = (Vector2)transform.position + Random.insideUnitCircle * ThreatDropSpread; //dir * ThreatDropDist + Random.Range(-1f, 1f) * ThreatDropSpread * orth + Random.Range(0f, 0.8f) * ThreatDropSpread * dir;
            t.localEulerAngles = new Vector3(0, 0, Random.Range(0f, 360f));
        }
    }
}
