
//type, x, y, after_speed, after_angle
let m_Arg = [0];
let m_flag_Stop = false;
let m_flag_Wait = true;
let m_MoveStep = 0;

function system_IsWaitingForStart(){
	return m_flag_Wait;
}
function system_StopMove(){
	m_flag_Stop = true;
}
function system_StartMove(){
	m_flag_Stop = false;
}
function system_NextStep(){
	m_MoveStep ++;
}
function system_GetStep(){
	return m_MoveStep;
}


function system_MoveTypeSelect(){

	m_Arg = GetArgument();

	alternative(m_Arg[0])

	case(0){
		return;
	}
	case(1){
		once_system_Move01(m_Arg[1], m_Arg[2], m_Arg[3], m_Arg[4]);
		loop(10){yield;}
		while(system_IsWaitingForStart()){yield;}
	}
	case(2){
		once_system_Move02(m_Arg[1], m_Arg[2], m_Arg[3]);
		system_StopMove();
		loop(10){yield;}
		while(system_IsWaitingForStart()){yield;}

	}
	case(3){
		once_system_Move03(m_Arg[1], m_Arg[2], m_Arg[3], m_Arg[4]);
		loop(10){yield;}
		while(system_IsWaitingForStart()){yield;}
	}
	case(11){
		once_system_Move11(m_Arg[1], m_Arg[2], m_Arg[3], m_Arg[4]);
		loop(10){yield;}
		while(system_IsWaitingForStart()){yield;}
	}



}//end function


//等速運動
task once_system_Move01(let x, let y, let spd, let ang){

	SetMovePosition03(x, y, 8, 8);
	loop(10){yield;}
	while(GetSpeed()>0){yield;}
	m_flag_Wait = false;

	loop{
		while(m_flag_Stop){yield;}		
		SetAngle(ang);
		ascent(i in 0..11){
			SetSpeed(spd  * (i/10));
		}

		while(!m_flag_Stop){yield;}
		SetSpeed(0);
	}

}//end task


//自機方向へ突っ込む
task once_system_Move02(let x, let y, let spd){

	SetMovePosition03(x, y, 8, 4);
	loop(10){yield;}
	while(GetSpeed()>0){yield;}
	m_flag_Wait = false;

	loop{
		while(m_flag_Stop){yield;}		
		SetAngle(GetAngleToPlayer());
		ascent(i in 0..21){
			SetSpeed(spd * (i/20));
		}

		while(!m_flag_Stop){yield;}
		SetSpeed(0);
	}

}//end task


//とまらずに方向転換
task once_system_Move03(let x, let y, let spd, let ang){

	let ang_old = GetAngle();
	let spd_old = GetSpeed();

	SetMovePosition03(x, y, 8, 4);
	loop(10){yield;}
	while(GetSpeed()>0){yield;}
	m_flag_Wait = false;

	loop{
		while(m_flag_Stop){yield;}		
		SetAngle(ang_old);
		ascent(i in 0..11){
			SetSpeed(spd_old  * (i/10));
		}

		while(!m_flag_Stop){yield;}
		while(m_flag_Stop){yield;}		

		SetAngle(ang);
		ascent(i in 0..61){
			SetSpeed(spd * (i/60));
		}

		while(!m_flag_Stop){yield;}
		SetSpeed(0);
		break;
	}

}//end task


//親の周りを回る
task once_system_Move11(let x, let y, let rad, let ang){

	SetCoordinateType(COODINATE_TYPE_PARENT);
	SetMovePosition03(x, y, 8, 4);
	loop(10){yield;}
	while(GetSpeed()>0){yield;}
	m_flag_Wait = false;

	let radius = ((x*x)+(y*y))^0.5;
	let angle = atan2(y,x);

	loop{
		while(m_flag_Stop){yield;}

		while(!m_flag_Stop){
			SetX(radius * cos(angle));
			SetY(radius * sin(angle));
			angle += ang;
			radius += rad;
			yield;
		}

	}

}//end task

