using UnityEngine;
using System.Collections;

public class Explosion : MonoBehaviour {
    public float damage = 100f;
    public float radius = 2f;
    public float duration = 0.5f;

    float startTime = 0;
    SpriteRenderer _sr;
	// Use this for initialization
	void Start () {
        startTime = Time.time;
        this.transform.localScale = Vector3.zero;
        _sr = this.GetComponent<SpriteRenderer>();
	}
	
	// Update is called once per frame
	void Update () {
        float ratio = (Time.time - startTime) / duration;
        if (ratio > 1) Destroy(this.gameObject);

        this.transform.localScale = Mathf.Lerp(0, radius, ratio) * Vector3.one;
        _sr.color = new Color(_sr.color.r, _sr.color.g, _sr.color.b, Mathf.Exp(-(ratio * ratio *ratio * ratio * 4)));
	}

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Enemy") other.GetComponent<Character>().Hit(damage);
    }
}
