using UnityEngine;
using System.Collections;

public class Ghost : MonoBehaviour {

	private PlayerManager targetPlayer;
	private float movedSpeed = (float)GhostSpeed.Slow;
	//each second the moveSpeed grows by accelleration;
	private float accelaration = 0.3f;
	private float deltaAcc=0f;

	public SpriteRenderer spriteRenderer;

	public PlayerManager TargetPlayer{
		get {return targetPlayer;}
		set { targetPlayer =value;}

	}

	public float MovedSpeed{
		get {return movedSpeed;}
		set { movedSpeed =value;}
	}
	public float Accelaration{
		get {return accelaration;}
		set { accelaration =value;}
	}

	// Use this for initialization
	void Start () {
		Camera cam = Camera.main;
		float height = 2f * cam.orthographicSize;
		float width = height * cam.aspect;
		//Debug.Log ("Camera width "+width);

		if (targetPlayer.transform.position.x>= 0) {
			transform.position = new Vector3 (-(width/2f), 0, 0);
		} else {
			transform.position = new Vector3 ((width/2f), 0, 0);
		
		}
	
	}

	// Update is called once per frame
	void Update () {
		//move towards the player
		transform.position = Vector3.MoveTowards(transform.position,targetPlayer.transform.position + new Vector3(0,-1,0),movedSpeed*Time.deltaTime);

		if (targetPlayer.transform.position.x > transform.position.x)
			spriteRenderer.flipX = true;
		else
			spriteRenderer.flipX = false;

		deltaAcc += Time.deltaTime;
		if (deltaAcc >= 1) {
			movedSpeed +=accelaration;
			deltaAcc = 0;
		}
	}

	public enum  GhostSpeed:int {
		Slow= 2,
		Normal= 4,
		Evil= 8,
		Deathly= 15
	} 
}
