//Copyright (C) Ben Parbury - All Rights Reserved. Unauthorized copying of this file, via any medium is strictly prohibited. Written by Ben Parbury <ben@gridlockinteractive.com> 2014
var gTweenSteps = 9;

function Tween(object, sx, sy, tx, ty, steps)
{
	this.x = sx;
	this.y = sy;
	
	this.tx = tx;
	this.ty = ty;
	
	this.dx = (tx - sx);
	this.dy = (ty - sy);

	this.step = 0;
	this.steps = steps;
	
	this.object = object;
	
	this.CanReverse = function()
	{
		return this.step != 0 && this.step != gTweenSteps - 1;
	}
	
	this.Reverse = function()
	{
		this.step = this.steps - this.step;
		this.dx = -this.dx;
		this.dy = -this.dy;
	}
	
	this.Update = function()
	{
		this.x += (this.dx / this.steps);
		this.y += (this.dy / this.steps);
		
		this.object.SetPosition(this.x, this.y);
		
		this.step++;
		
		if(this.IsComplete())
		{
			this.object.TweenComplete();
		}
	}
	
	this.IsComplete = function()
	{
		return (this.step == this.steps);
	}
}