using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class WizardMovement : MonoBehaviour
{
    public float moveSpeed = 0.05f, levelDifficulty = 1f;

    public TypeRepair mashType;
    public TypeWordRepair combType;

    public LevelLoader lvlLoad;
    public GameObject tutorial1, tutorial2;
    
    
    // Start is called before the first frame update
    void Start()
    {
        if (SceneManager.GetActiveScene().buildIndex == 1) levelDifficulty = 1f;
        else if (SceneManager.GetActiveScene().buildIndex == 2) levelDifficulty = 0.9f;
        else if (SceneManager.GetActiveScene().buildIndex ==  3) levelDifficulty = 0.8f;
        else if (SceneManager.GetActiveScene().buildIndex ==  4) levelDifficulty = 0.7f;
        else if (SceneManager.GetActiveScene().buildIndex == 5) levelDifficulty = 0.6f;
        else if (SceneManager.GetActiveScene().buildIndex == 6) levelDifficulty = 0.5f;
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.right * moveSpeed *levelDifficulty* Time.deltaTime);
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("censor"))
        {
            
            TypeRepair.canMash = true;
            TypeRepair.typeBarAmount = 0;
            mashType.NextBridge();
        }
        if (collision.gameObject.CompareTag("censorCombination"))
        {

            TypeWordRepair.finishedTyping = false;
            combType.Addword();
            //next combination bridge
        }
        if (collision.gameObject.CompareTag("dead"))
        {
            print("playerdead");
            lvlLoad.RestartLevel();
        }
        if (collision.gameObject.CompareTag("tutorial"))
        {
            Time.timeScale = 0.5f;
            if (SceneManager.GetActiveScene().buildIndex == 1)
            {
                tutorial1.SetActive(true);

            }
            if (SceneManager.GetActiveScene().buildIndex == 2)
            {
                tutorial2.SetActive(true);
                
            }

            StartCoroutine(FinishTutorial());

        }

        // if (collision.gameObject.CompareTag("censorWin"))
        // {
        //     moveSpeed = 5f;
        // }

    }
    IEnumerator FinishTutorial()
    {
        yield return new WaitForSeconds(1.5f);
        Time.timeScale = 1f;
        tutorial1.SetActive(false);
        tutorial2.SetActive(false);
    }
}
