﻿using UnityEngine;
using System.Collections;

public class MenuCrowdMember : PixelMover {

	public float speed = 100;

	public Vector3 _targetPosition;
	public Vector3 targetPosition{
		set{
			_targetPosition = value.roundedVector();
		}
		get{
			return _targetPosition;
		}
	}

	void Start(){
		speed *= Random.Range(.75f, 1.25f);

		SetAnimation anim = GetComponent<SetAnimation>();
		anim.setRandomAnimation();
	}
	
	void Update () {
		float differenceY = targetPosition.y - this.transform.position.y;
		float differenceX = targetPosition.x - this.transform.position.x;
		Vector3 movement = new Vector3();
		
		float verticalSpeed = speed * Time.deltaTime;
		float horizontalSpeed = speed * Time.deltaTime;

		if(differenceY > 0)
			movement.y = Mathf.Min(verticalSpeed, differenceY);
		else if(differenceY < 0)
			movement.y = Mathf.Max(-verticalSpeed, differenceY);
	
		if(differenceX > 0)
			movement.x = Mathf.Min(horizontalSpeed, differenceX);
		else if(differenceX < 0)
			movement.x = Mathf.Max(-horizontalSpeed, differenceX);

		this.moveBy(movement);
	}
}
