//オプションの移動と描画、パワー整数値の更新もする

task OptionMove
{//Power1~4までのオプション位置

let HiOpX_P1=[0,0,0,0];
let HiOpY_P1=[-32,0,0,0];
let LowOpX_P1=[0,0,0,0];
let LowOpY_P1=[-24,0,0,0];

let HiOpX_P2=[-36,36,0,0];
let HiOpY_P2=[0,0,0,0];
let LowOpX_P2=[-6,6,0,0];
let LowOpY_P2=[-24,-24,0,0];

let HiOpX_P3=[36,-36,0,0];
let HiOpY_P3=[15,15,30,0];
let LowOpX_P3=[8,-8,0,0];
let LowOpY_P3=[-24,-24,-26,0];

let HiOpX_P4=[30,-30,-16,16];
let HiOpY_P4=[0,0,-30,-30];
let LowOpX_P4=[18,-18,-6,6];
let LowOpY_P4=[-20,-20,-30,-30];

let HiOpX=[HiOpX_P1,HiOpX_P2,HiOpX_P3,HiOpX_P4];
let HiOpY=[ HiOpY_P1, HiOpY_P2, HiOpY_P3, HiOpY_P4];
let LowOpX=[LowOpX_P1,LowOpX_P2,LowOpX_P3,LowOpX_P4];
let LowOpY=[LowOpY_P1,LowOpY_P2,LowOpY_P3,LowOpY_P4];

let LowCount=0;
let D_OptionX=[0,0,0,0];
let D_OptionY=[0,0,0,0];
loop
{
	ascent(i in 0..4)
	{
	if(GetVirtualKeyState(VK_SLOWMOVE) == KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE) == KEY_HOLD)
	{
	D_OptionX[i]=GetPlayerX+LowOpX[PlayerPower_Int-1][i];
	D_OptionY[i]=GetPlayerY+LowOpY[PlayerPower_Int-1][i];
	}
	else
	{
	D_OptionX[i]=GetPlayerX+HiOpX[PlayerPower_Int-1][i];
	D_OptionY[i]=GetPlayerY+HiOpY[PlayerPower_Int-1][i];
	}
	OptionX[i]=OptionX[i]*0.70+D_OptionX[i]*0.30;
	OptionY[i]=OptionY[i]*0.70+D_OptionY[i]*0.30;
	}
	yield;
}
}

task TRenderOption
{
	let CurrentPower;
	
	loop
	{
	CurrentPower=PlayerPower_Int;
	DrawOption(0);
	DrawOption(1);
	DrawOption(2);
	DrawOption(3);
	while(CurrentPower==floor(PlayerPower/100)){yield;}
	PlayerPower_Int=floor(PlayerPower/100);//パワー段階の更新
	}

	task DrawOption(num)
	{
		let path = IMG_OPTION;
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		objOption=objOption~[obj];
		ObjPrim_SetTexture(obj, path);	
		Obj_SetRenderPriorityI(obj,43);
		let Zangle=0;
		ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
		ObjSprite2D_SetDestCenter(obj);
		let scale=0;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		if(PlayerPower_Int>=num+1)
		{
			ObjRender_SetAlpha(obj,255);
		}
		else
		{
			Obj_Delete(obj);
			return;
		}
		loop(10)
		{
			ObjRender_SetPosition(obj, OptionX[num],OptionY[num], 0);
			scale+=0.03/2;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			yield;
		}
		if(PlayerPower==400)
		{
			DrawOptionBlur(obj,num,Zangle);
		}
		loop(5)
		{
			ObjRender_SetPosition(obj, OptionX[num],OptionY[num], 0);
			scale-=0.03/2;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			yield;
		}
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		let DownCount=0;
		let ScaleTheta=0;
		while(CurrentPower==PlayerPower_Int)
		{
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			scale=0.065+0.010*sin(ScaleTheta);
			ScaleTheta+=12;
			ObjRender_SetPosition(obj, OptionX[num],OptionY[num], 0);
			if(PlayerPower_Int>=num+1)
			{
				ObjRender_SetAlpha(obj,255);
			}
			else
			{
				ObjRender_SetAlpha(obj,0);
			}
 			if(GetPlayerState==STATE_DOWN)
			{
				ObjRender_SetAlpha(obj,0);
				DownCount=50;
			}
 			if(DownCount>0)
			{
				ObjRender_SetAlpha(obj,0);
			}
			DownCount-=1;
			yield;
		}
		Obj_Delete(obj);
	}

	task DrawOptionBlur(objOption,num,Zangle)
	{//パワー４の時のオーラエフェクト
		let path = IMG_OPTION;
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, path);	
		Obj_SetRenderPriorityI(obj,42);
		ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
		ObjSprite2D_SetDestCenter(obj);
		let scale=0.20/2;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		ObjRender_SetAlpha(obj,150);
		let DownCount=0;
		while(!Obj_IsDeleted(objOption))
		{
			ObjRender_SetPosition(obj, OptionX[num],OptionY[num], 0);
 			if(GetPlayerState==STATE_DOWN)
			{
				ObjRender_SetAlpha(obj,0);
				DownCount=50;
			}
			else
			{
				ObjRender_SetAlpha(obj,150);
			}

 			if(DownCount>0)
			{
				ObjRender_SetAlpha(obj,0);
			}
			DownCount-=1;
			yield;
		}
		Obj_Delete(obj);
	}
}