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

namespace Assets.Scripts
{
    public class DeathCounter : MonoBehaviour
    {
        private int lineIndex = 0;
        private System.Random rand = new System.Random();

        Vector3 origin = new Vector3(-0.45f, 0.32f, 0.5f);
        public Vector3 actual = new Vector3(-0.45f, 0.32f, 0.5f);

        void Start()
        {
//            for (int i = 0; i < 150; i++ )
//                createLine();
        }

        // Update is called once per frame
        void Update()
        {
        }

        public void createLine()
        {
            lineIndex++;

            GameObject line = new GameObject(string.Format("line{0}", lineIndex));
            line.transform.parent = this.transform.parent;
            line.transform.localScale = new Vector3(4, 35, 1);
            if (lineIndex % 5 != 0)
            {
                line.transform.position = actual + new Vector3(lineIndex % 5 * 0.03f, 0, 0);
                line.transform.Rotate(new Vector3(0, 0, -5 + rand.Next() % 10));
            }
            else
            {
                line.transform.localScale = new Vector3(5, 60, 1);

                line.transform.position = actual + new Vector3(2.5f * 0.03f, 0, 0);
                line.transform.Rotate(new Vector3(0,0,120 + rand.Next()%10));
            }
            line.layer = this.gameObject.layer;

            line.AddComponent<UISprite>();
            UISprite sprite = line.GetComponent<UISprite>();
            sprite.atlas = this.GetComponent<UISprite>().atlas;
            sprite.spriteName = "bar";
            sprite.depth = 3;

            if (lineIndex % 5 == 0)
            {
                actual += new Vector3(0.15f, 0, 0);
            }
            if (lineIndex % 30 == 0)
            {
                actual = new Vector3(origin.x, actual.y - 0.11f, origin.z);
            }
        }
    }
}
