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

public class Figure : MonoBehaviour {
    public static List<Figure> Figures;
    public int damage;

    void Awake()
    {
        if (Figures == null)
        {
            Figures = new List<Figure>();
        }

        Figures.Add(this);

        damage = 0;
    }

    void OnDestroy()
    {
        Figures.Remove(this);
    }

    public void AddBrush(Slicer.Cut cut, bool super, int cutDamage)
    {
        damage += cutDamage;

        if (transform.childCount == 32)
        {
            Transform t = transform.GetChild(0);
            t.SetParent(null);
            GameObject.Destroy(t.gameObject);
        }

        float angle = Mathf.Atan2(cut.pointL.y - cut.pointR.y, cut.pointL.x - cut.pointR.x) / Mathf.PI * 180;
        Transform brush = (Transform)Transform.Instantiate(
            super ? GameManager.Instance.spawner.superBrush : GameManager.Instance.spawner.brush,
            (Vector3)(cut.pointL + cut.pointR) * 0.5f,
            Quaternion.Euler(0, 0, angle));
        brush.localScale = new Vector3((cut.pointL - cut.pointR).magnitude * 0.5f, 0.2f, 1f);
        brush.parent = transform;
        brush.localPosition = new Vector3(brush.localPosition.x, brush.localPosition.y, -0.01f);
    }
}
