using Assets.Scripts.MapGeneration;
using Assets.Scripts.Utils;
using UnityEngine;
using System;

namespace Assets.Scripts
{
    public class GameController : MonoBehaviour
    {
        public static int PoolSize = 256;

        public GameObject Wall;
        public GameObject BG;

        private Map _map;

        private Vector3 size;
        private Transform tra;
        private int mult = 1;

        void Start()
        {
            size = BG.GetComponent<SpriteRenderer>().sprite.bounds.size;
            tra = BG.GetComponent<Transform>();
        }

        void Update()
        {
            Camera.main.transform.Translate(new Vector3(2f*Time.deltaTime, 0, 0));
            var rightBorder = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width,
                Screen.height, 0)).x;
            var leftBorder = Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0)).x;

            if (!(rightBorder > (size.x*mult) - 2)) return;
            BG = (GameObject) Instantiate(BG, new Vector3(size.x + tra.position.x - .5f, tra.position.y, 0), Quaternion.identity);
            tra = BG.GetComponent<Transform>();
            mult++;
            // _ca.Step(rightBorder);

            // DrawMap(leftBorder, rightBorder);
            // Debug.Log(_map);
        }
    }
}