using UnityEngine;
using System.Collections;

public class CitizenScript : MonoBehaviour {

	public int isScared = 0;
	public float timer;
	public float scare_speed = 1;
	public int frame = 0;
	public Sprite norm1;
	public Sprite norm2;
	public Sprite scare1;
	public Sprite scare2;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {

		timer += Time.deltaTime;

		GameObject scareObj = GameObject.Find("scare_screen");
		ScareScript scareScript = scareObj.GetComponent<ScareScript>();

		if (scareScript.scare == 1 && ((transform.position.x >= (GameObject.Find ("Player").transform.position.x - 6.0f)) && (transform.position.x <= (GameObject.Find ("Player").transform.position.x + 18.0f)))) {
			isScared = 1;
		}

		if (isScared == 1) {
			scare_speed = 0.3f;
		}

		if (timer >= 1.3f * scare_speed) {
			if (isScared == 0)
			{
				if (frame == 0)
				{
					GetComponent<SpriteRenderer>().sprite = norm1;
					timer = 0f;
					frame = 1;
				}
				else
				{
					GetComponent<SpriteRenderer>().sprite = norm2;
					timer = 0f;
					frame = 0;
				}
			}
			if (isScared == 1)
			{
				if (frame == 0)
				{
					GetComponent<SpriteRenderer>().sprite = scare1;
					timer = 0f;
					frame = 1;
				}
				else
				{
					GetComponent<SpriteRenderer>().sprite = scare2;
					timer = 0f;
					frame = 0;
				}
			}
		}
	
	}
}
