using UnityEngine;
using System.Collections;

public class BackgroundScrollerManagerThing : MonoBehaviour
{
    private SpriteRenderer mySpriteRenderer;
    private GameManager theGame;

	// Use this for initialization
	void Start ()
	{
	    mySpriteRenderer = GetComponent<SpriteRenderer>();
	    theGame = GameObject.Find("GameManager").GetComponent<GameManager>();
	}
	
	// Update is called once per frame
	void Update () 
    {
        Vector3 vToCamera = Camera.main.transform.position - transform.position;
        Vector3 vPos = transform.position;

        float fXDelta = vToCamera.x;
        float fYDelta = vToCamera.y;

        if (fXDelta < -64.0f)
            vPos.x -= 128.0f;
        else if (fXDelta > 64.0f)
            vPos.x += 128.0f;

        if (fYDelta < -64.0f)
            vPos.y -= 96.0f;
        else if (fYDelta > 64.0f)
            vPos.y += 96.0f;

        transform.position = vPos;

	    mySpriteRenderer.color = theGame.GetBackgroundColor();
    }
}
