using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ScoreManager : MonoBehaviour {

	int score = 0;

	public Text livesLabel;

	enum ScoreState
	{
		NORMAL,
		GROWING,
		SHRINKING
	}

	ScoreState scoreState;

	float animateTime;
	// Use this for initialization
	void Start () {
		scoreState = ScoreState.NORMAL;
	}
	
	// Update is called once per frame
	void Update () {
		switch (scoreState)
		{
			case ScoreState.GROWING:
				{
					if (animateTime < 1)
					{
						float scaleFactor = Mathf.Lerp(1.0f, 2f, animateTime);
						transform.localScale = new Vector3(scaleFactor, scaleFactor, 1);
						animateTime += Time.deltaTime * 4;
					}
					else
					{
						animateTime = 0.0f;
						scoreState = ScoreState.SHRINKING;
					}
					break;
				}
			case ScoreState.SHRINKING:
				{
					if (animateTime < 1)
					{
						float scaleFactor = Mathf.Lerp(2f, 1.0f, animateTime);
						transform.localScale = new Vector3(scaleFactor, scaleFactor, 1);
						animateTime += Time.deltaTime * 4;
					}
					else
					{
						animateTime = 0.0f;
						scoreState = ScoreState.NORMAL;
					}
					break;
				}
		}
	}

	public void IncrementScore()
	{
		score ++;
		GetComponent<Text>().text = score.ToString();
		scoreState = ScoreState.GROWING;
		animateTime = 0.0f;
	}

	public void UpdateLives(int lives)
	{
		livesLabel.text = lives.ToString ();
	}
}
