
task PlayerDrawCount
{
loop
{
	if(THdot)
	{
		CharaDrawCount+=1;
		if(CharaDrawCount>=DrawFrame*7)
		{
			CharaDrawCount=0;
		}

		CharaLeftMoveDrawCount+=1;

		if(CharaLeftMoveDrawCount>=DrawFrame*7)
		{
			CharaLeftMoveDrawCount=DrawFrame*4;
		}
		if(KeyStateLeft=="FREE")
		{
			CharaLeftMoveDrawCount=0;
		}

		CharaRightMoveDrawCount+=1;

		if(CharaRightMoveDrawCount>=DrawFrame*7)
		{
			CharaRightMoveDrawCount=DrawFrame*4;
		}
		if(KeyStateRight=="FREE")
		{
			CharaRightMoveDrawCount=0;
		}
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
yield;
}
}

task PlayerRect
{
	loop
	{
		if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD)
		{
			PlayerRectLeft=0;
			PlayerRectUp=48;
			PlayerRectRight=48;
			PlayerRectDown=96;
		}
		else if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD)
		{
			PlayerRectLeft=0;
			PlayerRectUp=96;
			PlayerRectRight=48;
			PlayerRectDown=144;
		}
		else
		{
			PlayerRectLeft=0;
			PlayerRectUp=0;
			PlayerRectRight=48;
			PlayerRectDown=48;
		}

	if(THdot)
	{
			if(KeyStateLeft=="PUSH" || KeyStateLeft=="HOLD")
			{
				PlayerRectLeft=floor(CharaLeftMoveDrawCount/DrawFrame)*32;
				PlayerRectUp=49;
				PlayerRectRight=floor(CharaLeftMoveDrawCount/DrawFrame+1)*32;
				PlayerRectDown=97;
			}
			else if(KeyStateRight=="PUSH" || KeyStateRight=="HOLD")
			{
				PlayerRectLeft=floor(CharaRightMoveDrawCount/DrawFrame)*32;
				PlayerRectUp=97;
				PlayerRectRight=floor(CharaRightMoveDrawCount/DrawFrame+1)*32;
				PlayerRectDown=144;
			}
			else
			{
				PlayerRectLeft=floor(CharaDrawCount/DrawFrame)*32;
				PlayerRectUp=1;
				PlayerRectRight=floor(CharaDrawCount/DrawFrame+1)*32;
				PlayerRectDown=49;
			}
	}

	yield;
	}
}

task Shadow(time)
{

let count=0;
loop(time)
{
	if(BurstMode==0){break;}
	if(BurstMode==1 && count>=2)
	{
	PlayerShadow;
	ascent(let i in 0..4)
	{
		OptionShadow(i);
	}
	count=0;
	}
	count+=1;
	yield;
}

}

task PlayerShadow//プレイヤーの残像エフェクト
{
		function randrect
		{
			return(rand_int(-3,3));
		}
	let XYrect=[];
	loop(4)
	{
		XYrect=XYrect~[(PlayerRectRight-PlayerRectLeft)/2+randrect];
		XYrect=XYrect~[(PlayerRectDown-PlayerRectUp)/2+randrect];
	}
		if(GetCommonDataDefault("LightMode_PlayerBlur",0)==1){return;}

  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
		if(THdot)
		{
		ObjEffect_SetTexture(obj, THimg);
		}
		else
		{
		ObjEffect_SetTexture(obj, img);
		}
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, -XYrect[0], -XYrect[1]);
		ObjEffect_SetVertexXY(obj, 1, XYrect[2], -XYrect[3]);
		ObjEffect_SetVertexXY(obj, 2, XYrect[4], XYrect[5]);
		ObjEffect_SetVertexXY(obj, 3, -XYrect[6], XYrect[7]);

		ObjEffect_SetVertexUV(obj, 0,  PlayerRectLeft,  PlayerRectUp);
		ObjEffect_SetVertexUV(obj, 1,  PlayerRectRight, PlayerRectUp);
		ObjEffect_SetVertexUV(obj, 2, PlayerRectRight,  PlayerRectDown);
		ObjEffect_SetVertexUV(obj, 3, PlayerRectLeft, PlayerRectDown);

		ascent(let i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,100,127,127,255);
		}
		
		ObjEffect_SetLayer(obj, 2);
		Obj_SetAngle(obj,90);
		Obj_SetSpeed(obj,3.0);
		let Alpha=120;
		let ScaleX=0.8;
		let ScaleY=0.8;
		let DisScale=0.045;
		loop(3)
		{
		if(OnMissed){Obj_Delete(obj); break;}
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,ColorRed,ColorGreen,ColorBlue);
			}
			ObjEffect_SetScale(obj,ScaleX,ScaleY);
			ScaleX+=DisScale;
			ScaleY-=DisScale;
			Alpha-=15;
			yield;
		}
		
		Obj_Delete(obj);
}

task OptionShadow(num)//オプションの残像エフェクト
{
		function randrect
		{
			return(rand_int(-1,1));
		}
	let XYrect=[];
	loop(8)
	{
	XYrect=XYrect~[14/2+randrect];
	}
		if(GetCommonDataDefault("LightMode_PlayerBlur",0)==1){return;}

  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,opX[num],opY[num]);
		if(THdot)
		{
		ObjEffect_SetTexture(obj, THimg);
		}
		else
		{
		ObjEffect_SetTexture(obj, img);
		}
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

	ObjEffect_SetVertexXY(obj, 0, -XYrect[0], -XYrect[1]);
	ObjEffect_SetVertexXY(obj, 1, XYrect[2], -XYrect[3]);
	ObjEffect_SetVertexXY(obj, 2, XYrect[4], XYrect[5]);
	ObjEffect_SetVertexXY(obj, 3, -XYrect[6], XYrect[7]);
		
		if(THdot)
		{
			if(PlayerType=="A")
			{
			ObjEffect_SetVertexUV(obj, 0,  80, 160);
			ObjEffect_SetVertexUV(obj, 1,  96, 160);
			ObjEffect_SetVertexUV(obj, 2, 96,  176);
			ObjEffect_SetVertexUV(obj, 3, 80, 176);
			}
			if(PlayerType=="B")
			{
			ObjEffect_SetVertexUV(obj, 0,  64, 160);
			ObjEffect_SetVertexUV(obj, 1,  80, 160);
			ObjEffect_SetVertexUV(obj, 2, 80,  176);
			ObjEffect_SetVertexUV(obj, 3, 64, 176);
			}
			if(PlayerType=="C")
			{
			ObjEffect_SetVertexUV(obj, 0,  176, 144);
			ObjEffect_SetVertexUV(obj, 1,  192, 144);
			ObjEffect_SetVertexUV(obj, 2, 192,  160);
			ObjEffect_SetVertexUV(obj, 3, 176, 160);
			}
			if(PlayerType=="D")
			{
			ObjEffect_SetVertexUV(obj, 0,  96, 160);
			ObjEffect_SetVertexUV(obj, 1,  112, 160);
			ObjEffect_SetVertexUV(obj, 2, 112,  176);
			ObjEffect_SetVertexUV(obj, 3, 96, 176);
			}
		}
		else
		{
		ObjEffect_SetVertexUV(obj, 0,  3,  162);
		ObjEffect_SetVertexUV(obj, 1,  17, 162);
		ObjEffect_SetVertexUV(obj, 2, 17,  176);
		ObjEffect_SetVertexUV(obj, 3, 3, 176);
		}

		ascent(let i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,100,127,127,255);
		}
		
		ObjEffect_SetLayer(obj, 2);
		Obj_SetAngle(obj,90);
		Obj_SetSpeed(obj,3.0);
		let Alpha=60;
		let ScaleX=1.5;
		let ScaleY=1.5;
		let DisScale=0.045;

		loop(3)
		{
		if(OnMissed){Obj_Delete(obj); break;}
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,ColorRed,ColorGreen,ColorBlue);
			}
			ObjEffect_SetScale(obj,ScaleX,ScaleY);
			ScaleX+=0.03;
			ScaleY-=0.03;
			Alpha-=7.5;
			yield;
		}
		Obj_Delete(obj);
}

task NormalShadow
{
let count=0;
loop
{
	if(count>=2)
	{
	NormalPlayerShadow;
	ascent(let i in 0..4)
	{
		NormalOptionShadow(i);
	}
	count=0;
	}
	count+=1;
	yield;
}
}


task NormalPlayerShadow//プレイヤーの残像エフェクト
{
		function randrect
		{
			return(rand_int(-3,3));
		}
	let XYrect=[];
	loop(4)
	{
	//	XYrect=XYrect~[56/2+randrect];
	//	XYrect=XYrect~[92/2+randrect];
		XYrect=XYrect~[(PlayerRectRight-PlayerRectLeft)/2+randrect];
		XYrect=XYrect~[(PlayerRectDown-PlayerRectUp)/2+randrect];
	}
		if(GetCommonDataDefault("LightMode_PlayerBlur",0)==1){return;}

  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
		if(THdot)
		{
		ObjEffect_SetTexture(obj, THimg);
		}
		else
		{
		ObjEffect_SetTexture(obj, img);
		}
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

	ObjEffect_SetVertexXY(obj, 0, -XYrect[0], -XYrect[1]);
	ObjEffect_SetVertexXY(obj, 1, XYrect[2], -XYrect[3]);
	ObjEffect_SetVertexXY(obj, 2, XYrect[4], XYrect[5]);
	ObjEffect_SetVertexXY(obj, 3, -XYrect[6], XYrect[7]);

		ObjEffect_SetVertexUV(obj, 0,  PlayerRectLeft,  PlayerRectUp);
		ObjEffect_SetVertexUV(obj, 1,  PlayerRectRight, PlayerRectUp);
		ObjEffect_SetVertexUV(obj, 2, PlayerRectRight,  PlayerRectDown);
		ObjEffect_SetVertexUV(obj, 3, PlayerRectLeft, PlayerRectDown);

		ascent(let i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,100,127,127,255);
		}
		
		ObjEffect_SetLayer(obj, 2);
		Obj_SetAngle(obj,90);
		Obj_SetSpeed(obj,1.5);
		let Alpha=120;
		let ScaleX=0.8;
		let ScaleY=0.8;
		let DisScale=0.050;
		let ady=0;

		let R;
		let G;
		let B;
		if(PlayerType=="A"){R=0;G=0;B=150;}
		if(PlayerType=="B"){R=150;G=0;B=0;}
		if(PlayerType=="C"){R=150;G=0;B=150;}
		if(PlayerType=="D"){R=50;G=205;B=50;}

		loop(3)
		{
		if(OnMissed){Obj_Delete(obj); break;}
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			ObjEffect_SetScale(obj,ScaleX,ScaleY);
			ScaleX+=DisScale;
			ScaleY-=DisScale;
			Alpha-=7.5*2*5/3;
			yield;
		}
		
		Obj_Delete(obj);
}

task NormalOptionShadow(num)//オプションの残像エフェクト
{
		function randrect
		{
			return(rand_int(-1,1));
		}
	let XYrect=[];
	loop(8)
	{
	XYrect=XYrect~[14/2+randrect];
	}
		if(GetCommonDataDefault("LightMode_PlayerBlur",0)==1){return;}

  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,opX[num],opY[num]);
		if(THdot)
		{
		ObjEffect_SetTexture(obj, THimg);
		}
		else
		{
		ObjEffect_SetTexture(obj, img);
		}
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

	ObjEffect_SetVertexXY(obj, 0, -XYrect[0], -XYrect[1]);
	ObjEffect_SetVertexXY(obj, 1, XYrect[2], -XYrect[3]);
	ObjEffect_SetVertexXY(obj, 2, XYrect[4], XYrect[5]);
	ObjEffect_SetVertexXY(obj, 3, -XYrect[6], XYrect[7]);
		
		if(THdot)
		{
			if(PlayerType=="A")
			{
			ObjEffect_SetVertexUV(obj, 0,  80, 160);
			ObjEffect_SetVertexUV(obj, 1,  96, 160);
			ObjEffect_SetVertexUV(obj, 2, 96,  176);
			ObjEffect_SetVertexUV(obj, 3, 80, 176);
			}
			if(PlayerType=="B")
			{
			ObjEffect_SetVertexUV(obj, 0,  64, 160);
			ObjEffect_SetVertexUV(obj, 1,  80, 160);
			ObjEffect_SetVertexUV(obj, 2, 80,  176);
			ObjEffect_SetVertexUV(obj, 3, 64, 176);
			}
			if(PlayerType=="C")
			{
			ObjEffect_SetVertexUV(obj, 0,  176, 144);
			ObjEffect_SetVertexUV(obj, 1,  192, 144);
			ObjEffect_SetVertexUV(obj, 2, 192,  160);
			ObjEffect_SetVertexUV(obj, 3, 176, 160);
			}
			if(PlayerType=="D")
			{
			ObjEffect_SetVertexUV(obj, 0,  96, 160);
			ObjEffect_SetVertexUV(obj, 1,  112, 160);
			ObjEffect_SetVertexUV(obj, 2, 112,  176);
			ObjEffect_SetVertexUV(obj, 3, 96, 176);
			}
		}
		else
		{
		ObjEffect_SetVertexUV(obj, 0,  3,  162);
		ObjEffect_SetVertexUV(obj, 1,  17, 162);
		ObjEffect_SetVertexUV(obj, 2, 17,  176);
		ObjEffect_SetVertexUV(obj, 3, 3, 176);
		}
		
		ObjEffect_SetLayer(obj, 2);
		Obj_SetAngle(obj,90);
		Obj_SetSpeed(obj,1.5);
		let Alpha=60;
		let ScaleX=1.2;
		let ScaleY=1.2;
		let DisScale=0.05;

		let R;
		let G;
		let B;
		if(PlayerType=="A"){R=0;G=0;B=150;}
		if(PlayerType=="B"){R=150;G=0;B=0;}
		if(PlayerType=="C"){R=150;G=0;B=150;}
		if(PlayerType=="D"){R=50;G=205;B=50;}

		loop(3)
		{
		if(PlayerType=="C" && GetKeyState(VK_SLOWMOVE)==KEY_HOLD){break;}
		if(OnMissed){Obj_Delete(obj); break;}
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			ObjEffect_SetScale(obj,ScaleX,ScaleY);
			ScaleX+=DisScale;
			ScaleY-=DisScale;
			Alpha-=7.5*5/3;
			yield;
		}
		Obj_Delete(obj);
}

task ObjPlayerDraw//エフェクトオブジェクトによるプレイヤー表示
{
	let XYrect=[];
	loop(4)
	{
		XYrect=XYrect~[(PlayerRectRight-PlayerRectLeft)/2];
		XYrect=XYrect~[(PlayerRectDown-PlayerRectUp)/2];
	}

  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
		if(THdot)
		{
		ObjEffect_SetTexture(obj, THimg);
		}
		else
		{
		ObjEffect_SetTexture(obj, img);
		}
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

	ObjEffect_SetVertexXY(obj, 0, -XYrect[0], -XYrect[1]);
	ObjEffect_SetVertexXY(obj, 1, XYrect[2], -XYrect[3]);
	ObjEffect_SetVertexXY(obj, 2, XYrect[4], XYrect[5]);
	ObjEffect_SetVertexXY(obj, 3, -XYrect[6], XYrect[7]);

		ObjEffect_SetVertexUV(obj, 0,  PlayerRectLeft,  PlayerRectUp);
		ObjEffect_SetVertexUV(obj, 1,  PlayerRectRight, PlayerRectUp);
		ObjEffect_SetVertexUV(obj, 2, PlayerRectRight,  PlayerRectDown);
		ObjEffect_SetVertexUV(obj, 3, PlayerRectLeft, PlayerRectDown);

		ascent(let i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,255,255,127,127);
		}
		
		ObjEffect_SetLayer(obj, 3);

		loop(3)
		{
			yield;
		}
		
		Obj_Delete(obj);
}