//���ʃG�t�F�N�g�i�O���C�Y�A�ᑬ�����w�A��e�i�e�����_���[�W�Ռ��g�܂ށj�j

task GrazeEffect(BulletArray)
{//�O���C�Y�G�t�F�N�g
	ascent(i in 0..length(BulletArray))
	{
		if(!Obj_IsDeleted(BulletArray[i]))
		{
		Effect(BulletArray[i]);
		}
	}

	task Effect(Bobj)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_WHITECIRCLE_S);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,0,128,128);

		let x=(GetPlayerX+ObjRender_GetX(Bobj))/2;
		let y=(GetPlayerY+ObjRender_GetY(Bobj))/2;
		ObjRender_SetPosition(obj,x,y,0);

		let Alpha=0.75;
		let R=255;
		let G=255;
		let B=255;
		let speed=rand(2,6);
		let angle=rand(0,360);
		let Scale=0.1;
		let ScaleMax=Scale;
		loop(10)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
	//		ObjRender_SetAngleZ(obj,Zangle);
	//		Alpha-=1.0/8;
			Scale-=ScaleMax/10;
			yield;
		}
		Obj_Delete(obj);
	}
}

task SlowEffect
{//�ᑬ�G�t�F�N�g
	loop
	{
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			SlowEffectRender1;
			SlowEffectRender2;
			while(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD){yield;}
		}
		yield;
	}

	//���v�A�����v�Ŏ኱�������Ⴄ

	task SlowEffectRender1
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_MOVEMAGICCIRCLE);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,44);
		ObjRender_SetAngleZ(obj,0);

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

		let Alpha=0;
		let R=255;
		let G=255;
		let B=255;
		let Zangle=0;
		let Scale=0.25;
		let ScaleMax=Scale;
		loop(5)
		{
			if(GetVirtualKeyState(VK_SLOWMOVE)!=KEY_PUSH && GetVirtualKeyState(VK_SLOWMOVE)!=KEY_HOLD){break;}
			ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAlpha(obj,255*Alpha);
			ObjRender_SetAngleZ(obj,Zangle);
			Alpha+=1.0/15;
			Scale+=0.0125;
			yield;
		}
		loop(10)
		{
			if(GetVirtualKeyState(VK_SLOWMOVE)!=KEY_PUSH && GetVirtualKeyState(VK_SLOWMOVE)!=KEY_HOLD){break;}
			ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAlpha(obj,255*Alpha);
			ObjRender_SetAngleZ(obj,Zangle);
			Alpha+=1.0/15;
			Scale-=0.00625;
			yield;
		}
		loop
		{
			if(GetVirtualKeyState(VK_SLOWMOVE)!=KEY_PUSH && GetVirtualKeyState(VK_SLOWMOVE)!=KEY_HOLD){break;}
			ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAlpha(obj,255*Alpha);
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle-=3;
			yield;
		}
		Obj_Delete(obj);
	}

	task SlowEffectRender2
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_MOVEMAGICCIRCLE);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,44);
		ObjRender_SetAngleZ(obj,0);

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

		let Alpha=0;
		let R=255;
		let G=255;
		let B=255;
		let Zangle=0;
		let ZanglePlus=6;
		let Scale=0.25;
		loop(5)
		{
			Zangle+=ZanglePlus;
			ZanglePlus-=6/15;
			if(GetVirtualKeyState(VK_SLOWMOVE)!=KEY_PUSH && GetVirtualKeyState(VK_SLOWMOVE)!=KEY_HOLD){break;}
			ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAlpha(obj,255*Alpha);
			ObjRender_SetAngleZ(obj,Zangle);
			Alpha+=1.0/15;
			yield;
		}
		loop(10)
		{
			Zangle+=ZanglePlus;
			ZanglePlus-=6/15;
			if(GetVirtualKeyState(VK_SLOWMOVE)!=KEY_PUSH && GetVirtualKeyState(VK_SLOWMOVE)!=KEY_HOLD){break;}
			ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAlpha(obj,255*Alpha);
			ObjRender_SetAngleZ(obj,Zangle);
			Alpha+=1.0/15;
			yield;
		}
		loop
		{
			if(GetVirtualKeyState(VK_SLOWMOVE)!=KEY_PUSH && GetVirtualKeyState(VK_SLOWMOVE)!=KEY_HOLD){break;}
			ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetAlpha(obj,255*Alpha);
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=3;
			yield;
		}
		Obj_Delete(obj);
	}
}

task TExplosion
{//��e�G�t�F�N�g
	while(GetPlayerState==STATE_HIT)
	{//��炢�{���\���̃G�t�F�N�g
		loop(3)
		{
		Particle(1);
		}
		yield;
	}

	//���]�G�t�F�N�g�̏I�����}�p�t���O
	let ReverseEffectFlag=true;

	if(GetPlayerState!=STATE_NORMAL)
	{
		loop(30){Particle(2);}
		RebirthEffect;
		ExplodeEffect;
		ShockWave;
		let rx=GetPlayerX;
		let ry=GetPlayerY;
		ReverseEffect(rx,ry);
		loop(4){yield;}
		ReverseEffect(rx+32,ry);
		ReverseEffect(rx-32,ry);
		ReverseEffect(rx,ry+32);
		ReverseEffect(rx,ry-32);
		loop(23){yield;}
		ReverseEffect(rx,ry);
		loop(13){yield;}
		loop(47){yield;}
	}
	ReverseEffectFlag=false;

	task ShockWave
	{//�Ռ��g
		let x=GetPlayerX;
		let y=GetPlayerY;
		loop(30){yield;}
		let obj=CreatePlayerShotA1(x,y,0,0,8,65535,100);
		let range=0;
		loop(30)
		{
			ObjShot_SetIntersectionCircleA1(obj,range);
			range+=20;
			yield;
		}
		DeleteShotInCircle(TYPE_SHOT, TYPE_ITEM, x, y, 256);
		Obj_Delete(obj);
	}

	task Particle(type)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_LIGHT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		Obj_SetRenderPriorityI(obj,69);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,0,64,64);

		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);

		let Alpha=1.0;
		let Scale=rand(0.5,0.75);
		let ScaleMax=Scale;
		let R=255;
		let G=255;
		let B=255;
		if(rand_dir>0 || type==2)
		{
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			R=255;
			G=150;
			B=255;
		}
		else
		{
			ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
			R=0;
			G=105;
			B=0;
		}
		ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
		let speed=rand(5,15);
		let Angle=rand(0,360);
		let time=rand_int(15,20);
		loop(time)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(Angle),ObjRender_GetY(obj)+speed*sin(Angle),0);
			Scale-=ScaleMax/time;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			yield;
		}
		Obj_Delete(obj);
	}

	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,69);
		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;

		while(ReverseEffectFlag)
		{
			ScalePlus+=ScalePlusSpeed;
			Scale+=ScalePlus;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			yield;
		}
		Obj_Delete(obj);
	}

	task ExplodeEffect
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_DEADCIRCLE);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetDestCenter(obj,0,128,64,192);

		ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);

		let Alpha=1.0;
		let Scale=1;
		let R=255;
		let G=255;
		let B=255;


		loop(24)
		{
			Alpha-=1.0/24;
			Scale+=4.5/24;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			yield;
		}
		Obj_Delete(obj);
	}

	task RebirthEffect
	{//�������̎��@����
		let X=GetStgFrameWidth/2;
		let Y=466;//416
		RebirthFlag=true;
		loop(10){yield;}
		loop(25)
		{
			ObjRender_SetPosition(objPlayer, X,Y, 0);
			yield;
		}
		SetForbidPlayerShot(true);
		loop(5)
		{
			ObjRender_SetPosition(objPlayer, X,Y, 0);
			yield;
		}
		loop(50)
		{
			ObjRender_SetPosition(objPlayer, X,Y, 0);
			Y-=1;
			yield;
		}
		RebirthFlag=false;
		SetForbidPlayerShot(false);
	}
}