using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class TrapCollide : MonoBehaviour {
	public GameObject fire;

	bool picShown=false;
	public GameObject[] fireImg;
	public GameObject[] kuyuImg;
	//public GameObject spike;
	public GameObject hole;
	public GameObject oth;




	public bool died=false;

	//Type 0 fire, type 1 hole, type 2 spikes
	public int trapType=0;


	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.anyKey && died) {
			SceneManager.LoadScene (SceneManager.GetActiveScene().name);
		}
	
	}
	void OnTriggerEnter2D(Collider2D other) {
		if (other.tag.Equals ("Player")) {
			oth = other.gameObject;
			Invoke ("trapTouch", 0.3f);
			if (trapType == 0)
				fire.SetActive(true);
			else if (trapType == 1)
				hole.SetActive(true);
			//SceneManager.LoadScene (SceneManager.GetActiveScene().name);
		}
	}

	void trapTouch()
	{
		Invoke ("makeDied", 2.5f);

		if (trapType==0 && fireImg != null && !picShown) {
			picShown = true;
			Invoke ("showFirePic", 0.7f);
		}
		else if (trapType==1 && kuyuImg != null && !picShown) {
			picShown = true;
			Invoke ("showKuyuPic", 1.2f);

		}
		oth.GetComponent<Collider2D> ().attachedRigidbody.isKinematic = true;
		oth.GetComponent<AllCharMovement> ().enabled = false;


	}

	void makeDied()
	{
		died = true;
		//GameData.died = true;
	}

	void showFirePic()
	{
		fireImg [Random.Range (0, 2)].SetActive (true);
		GameData.randomFireText ();
	}

	void showKuyuPic()
	{
		kuyuImg [Random.Range (0, 2)].SetActive (true);
		GameData.randomKuyuText ();
	}



}
