//�X�y���ƃ_�~�[�X�y��
task TSpell
{//�d��u�_�[�N�X�p�[�N�v  
	OnSpell=true;
	SetPlayerSpeed(1.0,0.4);
	SetPlayerInvincibilityFrame_Special(345);//���G���Ԃ�ݒ�
	let objManage = GetSpellManageObject();
	Obj_Delete(objManage);

	PlayVol(SE_SPELL1,56);
	PlayVol(SE_SPELL2,56);
	let SparkAngle=270;
	SparkGrad;
	DarkSpark;
	OperationEffect;

	loop(300){yield;}
	OnSpell=false;
	SetPlayerSpeed(5.0,2.0);

	task DarkSpark
	{
		DarkSparkShadow;
		SparkAttack;
		loop(10){yield;}
		TShake;
		T_DarkSparkShadow;
		loop(10){yield;}
		DarkSparkMain;
		SparkWave;
	}

	task SparkAttack
	{
		let obj = ObjSpell_Create();
		ObjSpell_Regist(obj);
		ObjSpell_SetEraseShot(obj,false);
		ObjSpell_SetDamage(obj, 12);
		loop(300)
		{
			ObjSpell_SetIntersectionLine(obj,GetPlayerX-64*cos(SparkAngle),GetPlayerY-64*sin(SparkAngle),GetPlayerX+512*cos(SparkAngle),GetPlayerY+512*sin(SparkAngle),128);
			yield;
		}
		Obj_Delete(obj);
	}

	task SparkWave
	{
		loop(24)
		{
			WaveEffect;
			loop(12){yield;}
		}

		task WaveEffect
		{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SPARK);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
		Obj_SetRenderPriorityI(obj,43);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,256,512,512);


		ObjRender_SetAngleZ(obj,0);

		//let Zangle=-num*60;
		let Alpha=1;
		let AlphaMax=Alpha;
		let R=64;
		let G=255;
		let B=255;

		let WaveMoveDistance=0;
		let WaveSpeed=20;
		let Scale=0;

		let Range=64;

		let objEraze = ObjSpell_Create();
		ObjSpell_Regist(objEraze);
		ObjSpell_SetDamage(objEraze, 0);

		loop(18)
		{
			WaveMoveDistance+=WaveSpeed;
			Scale+=0.75/18;
			ObjRender_SetPosition(obj,GetPlayerX+(WaveMoveDistance-Range)*cos(SparkAngle),GetPlayerY+(WaveMoveDistance-Range)*sin(SparkAngle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAngleZ(obj,SparkAngle+90);
			ObjSpell_SetIntersectionLine(objEraze,ObjRender_GetX(obj)+128*cos(SparkAngle+90),ObjRender_GetY(obj)+128*sin(SparkAngle+90),ObjRender_GetX(obj)-128*cos(SparkAngle+90),ObjRender_GetY(obj)-128*sin(SparkAngle+90),16);
			yield;
		}
		loop(30)
		{
			WaveMoveDistance+=WaveSpeed;
			ObjRender_SetPosition(obj,GetPlayerX+(WaveMoveDistance-Range)*cos(SparkAngle),GetPlayerY+(WaveMoveDistance-Range)*sin(SparkAngle),0);
			ObjRender_SetAngleZ(obj,SparkAngle+90);
			ObjSpell_SetIntersectionLine(objEraze,ObjRender_GetX(obj)+128*cos(SparkAngle+90),ObjRender_GetY(obj)+128*sin(SparkAngle+90),ObjRender_GetX(obj)-128*cos(SparkAngle+90),ObjRender_GetY(obj)-128*sin(SparkAngle+90),16);
			yield;
		}
		Obj_Delete(obj);
		Obj_Delete(objEraze);
		}
	}

	task SparkGrad
	{
		loop(310)
		{
			if(GetVirtualKeyState(VK_LEFT) == KEY_HOLD || GetVirtualKeyState(VK_LEFT) == KEY_HOLD)
			{
				SparkAngle-=0.15;
			}
			else if(GetVirtualKeyState(VK_RIGHT) == KEY_HOLD || GetVirtualKeyState(VK_RIGHT) == KEY_HOLD)
			{
				SparkAngle+=0.15;
			}
			yield;
		}
	}

	task DarkSparkMain
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SPARK);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,43);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,0,512,256);

		ObjPrim_SetVertexPosition(obj, 0, -0, -128, -0);
		ObjPrim_SetVertexPosition(obj, 1, 512, -128, -0);
		ObjPrim_SetVertexPosition(obj, 2, 512, 128, 0);
		ObjPrim_SetVertexPosition(obj, 3, 0, 128, 0);

		ObjRender_SetAngleZ(obj,SparkAngle);

		//let Zangle=-num*60;
		let Alpha=192;
		ObjRender_SetAlpha(obj,Alpha);

		let R=128;
		let G=192;
		let B=255;
		ObjRender_SetColor(obj,R,G,B);

		let ScaleY=0;
		let ScaleYSpeed=0.08/20;
		let Range=32;

		loop(20)
		{
			ObjRender_SetPosition(obj,GetPlayerX-Range*cos(SparkAngle),GetPlayerY-Range*sin(SparkAngle),0);
			ObjRender_SetScaleXYZ(obj,1,ScaleY,1);
			ObjRender_SetAngleZ(obj,SparkAngle);
		//	Alpha+=1/20;
			ScaleY+=ScaleYSpeed;
			ScaleYSpeed+=0.08/20;
			yield;
		}
		loop(260)
		{
			ObjRender_SetPosition(obj,GetPlayerX-Range*cos(SparkAngle),GetPlayerY-Range*sin(SparkAngle),0);
			ObjRender_SetAngleZ(obj,SparkAngle);
			yield;
		}
		loop(10)
		{
			ObjRender_SetPosition(obj,GetPlayerX-Range*cos(SparkAngle),GetPlayerY-Range*sin(SparkAngle),0);
			ObjRender_SetAngleZ(obj,SparkAngle);
			ObjRender_SetScaleXYZ(obj,1,ScaleY,1);
		//	Alpha-=1/10;
			ScaleY-=0.8/10;
			yield;
		}
		Obj_Delete(obj);	
	}

	task DarkSparkShadow
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SPARK);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
		Obj_SetRenderPriorityI(obj,41);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,0,512,256);

		ObjPrim_SetVertexPosition(obj, 0, -0, -128, -0);
		ObjPrim_SetVertexPosition(obj, 1, 512, -128, -0);
		ObjPrim_SetVertexPosition(obj, 2, 512, 128, 0);
		ObjPrim_SetVertexPosition(obj, 3, 0, 128, 0);

		ObjRender_SetAngleZ(obj,270);

		//let Zangle=-num*60;
		let Alpha=0;
		let AlphaMax=Alpha;
		let R=255;
		let G=255;
		let B=255;

		let ScaleY=0;
		let ScaleYSpeed=0.095/20;
		let Range=32;
		loop(20)
		{
			ObjRender_SetPosition(obj,GetPlayerX-Range*cos(SparkAngle),GetPlayerY-Range*sin(SparkAngle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,1,ScaleY,1);
			ObjRender_SetAngleZ(obj,SparkAngle);
			Alpha+=1/20;
			ScaleY+=ScaleYSpeed;
			ScaleYSpeed+=0.095/20;
			yield;
		}
		loop(280)
		{
			ObjRender_SetPosition(obj,GetPlayerX-Range*cos(SparkAngle),GetPlayerY-Range*sin(SparkAngle),0);
			ObjRender_SetAngleZ(obj,SparkAngle);
			yield;
		}
		loop(10)
		{
			ObjRender_SetPosition(obj,GetPlayerX-Range*cos(SparkAngle),GetPlayerY-Range*sin(SparkAngle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,1,ScaleY,1);
			ObjRender_SetAngleZ(obj,SparkAngle);
			Alpha-=1/10;
			ScaleY-=0.95/10;
			yield;
		}
		Obj_Delete(obj);	
	}

	task T_DarkSparkShadow
	{
		let Color=RainbowArray;
		let t=0;
		loop(18)
		{
			DarkSparkShadow2(Color[t%7]);
			t++;
			loop(15){yield;}
		}

		task DarkSparkShadow2(color)
		{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SPARK);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
		Obj_SetRenderPriorityI(obj,42);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,0,512,256);

		ObjPrim_SetVertexPosition(obj, 0, -0, -128, -0);
		ObjPrim_SetVertexPosition(obj, 1, 512, -128, -0);
		ObjPrim_SetVertexPosition(obj, 2, 512, 128, 0);
		ObjPrim_SetVertexPosition(obj, 3, 0, 128, 0);

		ObjRender_SetAngleZ(obj,270);

		//let Zangle=-num*60;
		let Alpha=0;
		let AlphaMax=Alpha;
		let R=color[0];
		let G=color[1];
		let B=color[2];

		let ScaleY=0;
		let ScaleYSpeed=0.095/20;
		let Range=32;
		loop(20)
		{
			ObjRender_SetPosition(obj,GetPlayerX-Range*cos(SparkAngle),GetPlayerY-Range*sin(SparkAngle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,1,ScaleY,1);
			ObjRender_SetAngleZ(obj,SparkAngle);
			Alpha+=1/20;
			ScaleY+=ScaleYSpeed;
			ScaleYSpeed+=0.095/20;
			yield;
		}
		loop(20)
		{
			ObjRender_SetPosition(obj,GetPlayerX-Range*cos(SparkAngle),GetPlayerY-Range*sin(SparkAngle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,1,ScaleY,1);
			ObjRender_SetAngleZ(obj,SparkAngle);
			Alpha-=1/20;
		//	ScaleY-=0.95/20;
			yield;
		}
		Obj_Delete(obj);	
		}
	}

	task TShake()
	{
		loop(315)
		{
			Set2DCameraFocusX(GetStgFrameWidth / 2 + 10*rand_degree);
			Set2DCameraFocusY(GetStgFrameHeight / 2 + 10*rand_degree);
			yield;
		}
		Reset2DCamera();
	}
}

task OperationEffect
{
	loop(5){yield;}
	ReverseEffect(GetPlayerX,GetPlayerY);
	task ReverseEffect(x,y)
	{//���]�����G�t�F�N�g
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_WHITECIRCLE_L);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjRender_SetBlendType(obj, BLEND_INV_DESTRGB);
		ObjPrim_SetVertexCount(obj, 4);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,0,512,512);

		ObjRender_SetPosition(obj,x,y,0);

		let Alpha=1.0;
		let Scale=0;
		let ScalePlus=0;
		let ScalePlusSpeed=0.0125/8*1.33;
		let R=255;
		let G=255;
		let B=255;

		loop(60)
		{
			ScalePlus+=ScalePlusSpeed;
			Scale+=ScalePlus;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			yield;
		}
		loop(225)
		{
			yield;
		}
		ScalePlus=Scale/30;
		loop(30)
		{
			Scale-=ScalePlus;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			yield;
		}
		Obj_Delete(obj);
	}
}

task DummySpell
{//���ꖳ�G�V�X�e���p
	SetPlayerInvincibilityFrame(0);//���G���Ԃ�ݒ�
	let objManage = GetSpellManageObject();
	Obj_Delete(objManage);
	if(OnSpell)
	{
		SetPlayerSpeed(1.0*2,0.4*2);	
	}
	else
	{
		SetPlayerSpeed(5.0*2,2.0*2);
	}
	yield;
	if(OnSpell)
	{
		SetPlayerSpeed(1.0,0.4);	
	}
	else
	{
		SetPlayerSpeed(5.0,2.0);
	}
}