using UnityEngine;
using System.Collections;

public class ExplosionScript : MonoBehaviour {

    public float fLifeTime;
    public float fFrameTime;

    public Sprite[] FoomSprites;

	// Use this for initialization
	void Start () 
    {
	
	}
	
	// Update is called once per frame
	void Update () 
    {
        SpriteRenderer sr = GetComponent<SpriteRenderer>();

        fLifeTime -= Time.deltaTime;
        if (fLifeTime < 0.0f)
        {
            sr.enabled = false;
            return;
        }

        if (fFrameTime >= 0.0f)
            fFrameTime -= Time.deltaTime;
        if (fFrameTime <= 0.0f)
        {
            fFrameTime = 0.1f;
            sr.sprite = FoomSprites[Random.Range(0, FoomSprites.Length)];

            Vector3 vEuler = transform.rotation.eulerAngles;
            vEuler.z = Random.value * 360.0f;
            transform.rotation = Quaternion.Euler(vEuler);

            Vector3 vPos = transform.position;
            vPos.x += -0.1f + (0.2f * Random.value);
            vPos.y += -0.1f + (0.2f * Random.value);

            transform.position = vPos;
        }

        fLifeTime -= Time.deltaTime;
        if (fLifeTime < 0.0f)
        {
            sr.enabled = false;
        }
	}
}
