using DG.Tweening;
using UnityEngine;
using UnityEngine.SceneManagement;
using ScrambleKit.FX;

public class Block : MonoBehaviour
{
	public static float HighestBlockHeight;

	public FXTrigger BreakFX;
	public FXTrigger GameOverFX;

	public Sprite DrillingSprite;

	public int ScoreValue = 5;
	public float DigTime = 0.4f;

	public bool SceneChangeOnBreak = false;
	public string NewSceneName = "";

	private SpriteRenderer rend;
	private BoxCollider2D col;

	void Start()
	{
		col = GetComponent<BoxCollider2D>();
		rend = GetComponent<SpriteRenderer>();
	}

	void Update()
	{
		if(transform.position.y > 0.99f && !DigGame.GameOver)
		{
			GameOverFX.Trigger(transform);
			DigGame.TriggerGameOver();
		}

		if(transform.position.y > HighestBlockHeight)
		{
			HighestBlockHeight = transform.position.y;
		}
	}

	public bool CanBreak()
	{
		return true;
	}

	public void Break()
	{
		transform.DOKill();
		BreakFX.Trigger(transform);

		if (SceneChangeOnBreak)
		{
			SceneManager.LoadScene(NewSceneName);
		}
		else
		{
			Destroy(gameObject);
		}
	}

	public void StartDrilling()
	{
		if(DrillingSprite == null || rend == null)
		{
			return;
		}
		rend.sprite = DrillingSprite;
	}

}
