task Obj_SetMovePosition01(obj,EndX,EndY,Speed)
{
	let Angle=atan2(EndY-Obj_GetY(obj),EndX-Obj_GetX(obj));
	let MoveDistance=((EndY-Obj_GetY(obj))^2+(EndX-Obj_GetX(obj))^2)^0.5;
	let time=floor(MoveDistance/Speed);
 	loop(time)
	{
		Obj_SetX(obj,Obj_GetX(obj)+Speed*cos(Angle));
		Obj_SetY(obj,Obj_GetY(obj)+Speed*sin(Angle));
               	yield;
	}
}

task Obj_SetMovePosition02(obj,EndX,EndY,Frame)
{
	let Angle=atan2(EndY-Obj_GetY(obj),EndX-Obj_GetX(obj));
	let MoveDistance=((EndY-Obj_GetY(obj))^2+(EndX-Obj_GetX(obj))^2)^0.5;
	let Speed=MoveDistance/Frame;
 	loop(Frame)
	{
		Obj_SetX(obj,Obj_GetX(obj)+Speed*cos(Angle));
		Obj_SetY(obj,Obj_GetY(obj)+Speed*sin(Angle));
               	yield;
	}
}

task Obj_SetMovePosition03(obj,EndX,EndY,Weight,MaxSpeed)
{
	let Angle=atan2(EndY-Obj_GetY(obj),EndX-Obj_GetX(obj));
	let MoveDistance=((EndY-Obj_GetY(obj))^2+(EndX-Obj_GetX(obj))^2)^0.5;
	let Distance=0;
	let Cspeed=MaxSpeed;
	let e=2.71828;
	let count=0;
 	while(Cspeed>MaxSpeed/20)
	{
		Distance=((EndY-Obj_GetY(obj))^2+(EndX-Obj_GetX(obj))^2)^0.5;
		if(MoveDistance>MaxSpeed*Weight)
		{
			if(Distance>MaxSpeed*Weight)
			{
				Cspeed=MaxSpeed;
			}
			else
			{
				Cspeed=MaxSpeed*e^(-count/Weight);
				count+=1;
			}
		}
		else
		{
			Cspeed=Distance/Weight*e^(-count/Weight);
			count+=1;
		}
		Obj_SetX(obj,Obj_GetX(obj)+Cspeed*cos(Angle));
		Obj_SetY(obj,Obj_GetY(obj)+Cspeed*sin(Angle));
               	yield;
	}
}

task Obj_SetMovePositionHermite(obj,EndX,EndY,Size1,Angle1,Size2,Angle2,frame)
{
	let StartX=Obj_GetX(obj);
	let StartY=Obj_GetY(obj);
	let x=[0,0,0,0];
	let y=[0,0,0,0];
	let k;
	let count=0;
	loop(frame)
	{
		k=count/frame;
		x[0]=2*StartX+Size1*cos(Angle1)-2*EndX+Size2*cos(Angle2);
		x[1]=-3*StartX-2*Size1*cos(Angle1)+3*EndX-Size2*cos(Angle2);
		x[2]=Size1*cos(Angle1);
		x[3]=StartX;
		Obj_SetX(obj,x[0]*k^3+x[1]*k^2+x[2]*k+x[3]);

		y[0]=2*StartY+Size1*sin(Angle1)-2*EndY+Size2*sin(Angle2);
		y[1]=-3*StartY-2*Size1*sin(Angle1)+3*EndY-Size2*sin(Angle2);
		y[2]=Size1*sin(Angle1);
		y[3]=StartY;
		Obj_SetY(obj,y[0]*(k^3)+y[1]*(k^2)+y[2]*k+y[3]);
		count+=1;
		yield;
    	}
}

task Obj_SetMovePositionBezier(obj,ControlX,ControlY,EndX,EndY,frame)
{
	let X=[Obj_GetX(obj)]~ControlX~[EndX];
	let Y=[Obj_GetY(obj)]~ControlY~[EndY];

	let num=length(X);

	let C=[];
	ascent(i in 0..num)
	{
		C=C~[factorial(num-1)/(factorial(num-1-i)*factorial(i))];
	}

	let x=0;
	let y=0;
	let k;
	let count=0;

	loop(frame)
	{
		k=count/frame;
		ascent(i in 0..num)
		{
			x+=C[i]*(1-k)^(num-1-i)*k^i*X[i];
			y+=C[i]*(1-k)^(num-1-i)*k^i*Y[i];
		}
		Obj_SetX(obj,x);
		Obj_SetY(obj,y);
		x=0;
		y=0;
		count+=1;
		yield;
    	}
}

function factorial(num)
{
	num=absolute(num);
	if(num==0){num=1;}
	let answer=num;
	while(num>1)
	{
		num-=1;
		answer*=num;
	}
	return(answer);
}
