using DG.Tweening;
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections.Generic;

public class GameOverSceneControl : MonoBehaviour
{
	public string PlayScene;
	public Transform TitleSign;
	public Transform FooterSign;
	public List<Transform> DigitPrefabs;
	public float DigitSpacing = 0.85f;

	public float DistancePerScore = 0.01f;

    void Start()
    {
		Invoke("ShowTitle", 0.05f);
		Invoke("ShowScore", 1.2f);
		Invoke("ShowFooter", 2.5f);
	}

	private void ShowTitle()
	{
		TitleSign.DOMoveY(2.5f, 1.1f).SetEase(Ease.OutElastic);
	}

	private void ShowFooter()
	{
		FooterSign.DOMoveY(-4, 0.8f).SetEase(Ease.OutElastic);
	}

	private void ShowScore()
	{
		int score = Score.Total;
		string s = score.ToString();

		float spacing = DigitSpacing;
		float leftEdge = -0.5f * (spacing * (s.Length-1));

		for(int i=0; i<s.Length; i++)
		{
			Transform digit = Instantiate(DigitPrefabs[int.Parse(s.Substring(i,1))]);
			float xpos = leftEdge + i * spacing;
			digit.position = new Vector3(xpos, 1.25f, 0f);
		}

	}

	void Update()
    {
		if(Input.GetKeyDown(KeyCode.Space))
			SceneManager.LoadScene(PlayScene);
	}
}
