using UnityEngine;
using System.Collections;

public class UThinkie : Thinkie {
	Vector3 target;
    public Transform bad;
    public Transform puf;
	public float radius = 8;
	public float speedU = 0.05f;
	private bool canMove = true;
	void Start(){
		type = ThinkieType.UGLY;
		target = transform.position;
	}

	public override void BulletHit (){
		Boom ();
		canMove = false;
	}

	public override void IdeaQueueReaction (){
		//Boom ();
	}

	void Update()
	{
		PositionChange ();
	}

	void PositionChange(){
        if (transform.position.x == target.x && transform.position.y == target.y)
        {
            target = UnityEngine.Random.insideUnitSphere * radius;
        }

		if (canMove) transform.position = Vector3.MoveTowards(transform.position, target, speedU);
	}

    void OnTriggerStay2D(Collider2D col) {
        if (col.tag == "Thinkie")
        {
			if(col.GetComponent<Thinkie>().type == ThinkieType.GOOD){
				Vector3 pos = col.transform.position;
				Quaternion rot = col.transform.rotation;
				Destroy(col.gameObject);
				Instantiate(bad, pos, rot);
				var pufObj = Instantiate(puf, pos, rot);
				((Transform)pufObj).GetComponent<ParticleRenderer>().sortingOrder = 50;
			}
        }
    }

    void OnCollisionStay2D(Collision2D col)
    {
        if (col.gameObject.tag == "IdeaQueue")
            target = UnityEngine.Random.insideUnitSphere * radius;
    }
}
