//メイン＆サブショット
task TShot
{//メイン
	let pShot=false;
	ShotCheck;
	let Speed=22.5;
	let MainDamage=3.0;
	let DamageRate=1;
	loop
	{
		while(!pShot){yield;}
		if(IsPlayerSpellActive){DamageRate=1.0;}
		else{DamageRate=1.0;}
		if((GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD))
		{
			MainShot(GetPlayerX()+8, GetPlayerY(), Speed, 270, MainDamage, 1, 32);
			MainShot(GetPlayerX()-8, GetPlayerY(), Speed, 270, MainDamage, 1, 32);
		}
		else
		{
			MainShot(GetPlayerX()+8, GetPlayerY(), Speed, 270, MainDamage, 1, 30);
			MainShot(GetPlayerX()-8, GetPlayerY(), Speed, 270, MainDamage, 1, 30);
		}
//		PlaySE(SE_SHOT);

		loop(3){yield;}
	}

	task ShotCheck
	{
		loop
		{
			if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD) && GetPlayerState==STATE_NORMAL && IsPermitPlayerShot)
			{
			pShot=true;

			}
			else
			{
			pShot=false;

			}
			yield;
		}
	}

	task MainShot(x,y,speed,angle,damage,pene,id)
	{
		let obj=CreatePlayerShotA1(x,y,speed,angle,damage,pene,id);
		let scale=1;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		Obj_SetRenderPriorityI(obj,40);
		let OldX;
		let OldY;
		while(!Obj_IsDeleted(obj))
		{
			OldX=ObjMove_GetX(obj);
			OldY=ObjMove_GetY(obj);
			yield;
		}
		HitEffect(OldX,OldY,speed,angle,id);
		HitEffect2(OldX,OldY,speed,angle,id);
		if(id==32)
		{
		HitEffect3(OldX,OldY);
		}
		Obj_Delete(obj);
	}

	task HitEffect(x,y,speed,angle,id)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,angle+90);

		ObjPrim_SetDestCenter(obj,128,96,144,128);
		if(id==10){ObjPrim_SetDestCenter(obj,160,96,176,128);}
		ObjRender_SetPosition(obj,x+1,y-18,0);
		speed/=8;
		let Alpha=1.0;
		let R=255;
		let G=255;
		let B=255;
		loop(3)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		ObjPrim_SetDestCenter(obj,128,64,144,96);
		if(id==10){ObjPrim_SetDestCenter(obj,160,64,176,96);}
		loop(3)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		ObjPrim_SetDestCenter(obj,128,32,144,64);
		loop(3)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		Obj_Delete(obj);
	}

	task HitEffect2(x,y,speed,angle,id)
	{
		angle+=180+rand(-90,90);
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);

		ObjPrim_SetDestCenter(obj,128,96,144,128);
		if(id==10){ObjPrim_SetDestCenter(obj,160,96,176,128);}

		ObjRender_SetPosition(obj,x,y,0);
		speed=rand(2.5,5);
		let Scale=1;
		let Alpha=0.5;
		let R=255;
		let G=255;
		let B=255;
		let Zangle=angle+90;
		let ZanglePlus=rand(10,20)*rand_dir;
		loop(10)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=0.5/15;
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus;
			yield;
		}
		ObjPrim_SetDestCenter(obj,128,64,144,96);
		if(id==10){ObjPrim_SetDestCenter(obj,160,64,176,96);}
		loop(5)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=0.5/15;
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus;
			yield;
		}
		Obj_Delete(obj);
	}

	task HitEffect3(x,y)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SPLASH);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);

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

		ObjRender_SetPosition(obj,x,y+45,0);
		let Scale=2;
		let Alpha=0;
		let R=100;
		let G=255;
		let B=100;
		let Zangle=0;
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		ObjRender_SetAngleZ(obj,Zangle+90);
		let count=0;
		loop(8)
		{
			ObjPrim_SetDestCenter(obj,0,0+count*16,64,16+count*16);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha+=0.5/8;
			count+=1;
			yield;
		}
		Obj_Delete(obj);
	}
}

task TShot2
{//サブ
	TShot3;//サブショットその２
	TShot4;//低速用
	let pShot=false;
	ShotCheck;
	let ShotDamage=2.4;
	let DamageRate=1;
	let ShotAngle_P1=[270,0,0,0];
	let ShotAngle_P2=[250,290,0,0];
	let ShotAngle_P3=[290,250,270,0];
	let ShotAngle_P4=[275,264,270,270];
	let ShotAngle=[ShotAngle_P1,ShotAngle_P2,ShotAngle_P3,ShotAngle_P4];
	let ShotLag=0;
	loop
	{
		while(!pShot){ShotLag=0;yield;}
		if(IsPlayerSpellActive){DamageRate=1.0;}
		else{DamageRate=1.0;}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{

		}
		else
		{
			ascent(i in 0..PlayerPower_Int)
			{
				if(i>=2)
				{
					KnifeShot(OptionX[i],OptionY[i],270,ShotDamage,i,31);
				}
			}
		}
		ShotLag+=1;
		loop(6-(ShotLag%3==2)*3){yield;}
	}

	task ShotCheck
	{
		loop
		{
			if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD) && GetPlayerState==STATE_NORMAL && IsPermitPlayerShot)
			{
			pShot=true;

			}
			else
			{
			pShot=false;

			}
			yield;
		}
	}
}

task TShot3
{//サブ
	let pShot=false;
	ShotCheck;
	let ShotDamage=2.4;
	let DamageRate=1;
	let ShotAngle_P1=[270,0,0,0];
	let ShotAngle_P2=[250,290,0,0];
	let ShotAngle_P3=[290,250,270,0];
	let ShotAngle_P4=[290,250,260,280];
	let ShotAngle=[ShotAngle_P1,ShotAngle_P2,ShotAngle_P3,ShotAngle_P4];
	let ShotLag=0;
	loop
	{
		while(!pShot){ShotLag=0;yield;}
		if(IsPlayerSpellActive){DamageRate=1.0;}
		else{DamageRate=1.0;}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{

		}
		else
		{
			ascent(i in 0..PlayerPower_Int)
			{
				KnifeShot(OptionX[i],OptionY[i],ShotAngle[PlayerPower_Int-1][i],ShotDamage,i,31);
				if(i<2)
				{
					KnifeShot(OptionX[i],OptionY[i],270,ShotDamage,i,31);
				}
			}
		}
		ShotLag+=1;
		loop(7+ShotLag%2){yield;}
	}

	task ShotCheck
	{
		loop
		{
			if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD) && GetPlayerState==STATE_NORMAL && IsPermitPlayerShot && !IsPlayerSpellActive)
			{
			pShot=true;

			}
			else
			{
			pShot=false;

			}
			yield;
		}
	}
}

task TShot4
{//サブ
	let pShot=false;
	ShotCheck;
	let ShotDamage=1.5;
	let DamageRate=1;
	let ShotAngle_P1=[270,0,0,0];
	let ShotAngle_P2=[250,290,0,0];
	let ShotAngle_P3=[290,250,270,0];
	let ShotAngle_P4=[250,290,290,250];
	let ShotAngle=[ShotAngle_P1,ShotAngle_P2,ShotAngle_P3,ShotAngle_P4];
	let ShotCount=0;

	loop
	{
		while(!pShot){ShotCount=0;yield;}
		if(IsPlayerSpellActive){DamageRate=1.0;}
		else{DamageRate=1.0;}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			ascent(i in 0..PlayerPower_Int)
			{
				KnifeShot(OptionX[i],OptionY[i],ShotAngle[PlayerPower_Int-1][i],ShotDamage,i,32);
			}
		}
		else
		{

		}
		loop(3){yield;}
	}

	task ShotCheck
	{
		loop
		{
			if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD) && GetPlayerState==STATE_NORMAL && IsPermitPlayerShot && !IsPlayerSpellActive)
			{
			pShot=true;

			}
			else
			{
			pShot=false;

			}
			yield;
		}
	}
}

task KnifeShot(x,y,angle,damage,Opnum,id)
{
	let speed=22.5;
	let obj=CreatePlayerShotA1(x,y,speed,angle,damage,1,id);
	Obj_SetRenderPriorityI(obj,40);
	let scale=1.0;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	let count=0;
	let OldX=x;
	let OldY=y;
	while(!Obj_IsDeleted(obj))
	{
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		count+=1;
		if(count==5 && id==32){
			let EnemyObjectArray=GetIntersectionRegistedEnemyID;
			angle = 270;
			let tmpAngle;
			if(length(EnemyObjectArray)!=0)
			{
				ascent(i in 0..length(EnemyObjectArray))
				{
					tmpAngle = atan2(ObjMove_GetY(EnemyObjectArray[i])-GetPlayerY(),ObjMove_GetX(EnemyObjectArray[i])-GetPlayerX());
					tmpAngle %= 360;
					if(tmpAngle > 240 && tmpAngle < 300){
						angle = tmpAngle;
						break;
					}
				}
			}
			ObjMove_SetAngle(obj,angle);
		}
		yield;
	}

	HitEffect(OldX,OldY,speed,angle);
	HitEffect2(OldX,OldY,speed,angle);
	Obj_Delete(obj);

	task HitEffect(x,y,speed,angle)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,angle+90);

		ObjPrim_SetDestCenter(obj,144,96,160,128);
		if(id==32){ObjPrim_SetDestCenter(obj,160,96,176,128);}

		ObjRender_SetPosition(obj,x,y,0);
		speed/=8;
		let Scale=1;
		let Alpha=1.0;
		let R=255;
		let G=255;
		let B=255;
		loop(3)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		ObjPrim_SetDestCenter(obj,144,64,160,96);
		if(id==32){ObjPrim_SetDestCenter(obj,160,64,176,96);}
		loop(3)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		ObjPrim_SetDestCenter(obj,144,32,160,64);
		if(id==10){ObjPrim_SetDestCenter(obj,160,32,176,64);}

		loop(3)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		Obj_Delete(obj);
	}

	task HitEffect2(x,y,speed,angle)
	{
		angle+=180+rand(-90,90);
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);

		ObjPrim_SetDestCenter(obj,144,96,160,128);
		if(id==32){ObjPrim_SetDestCenter(obj,160,96,176,128);}

		ObjRender_SetPosition(obj,x,y,0);
		speed=rand(2.5,5);
		let Scale=1;
		let Alpha=0.5;
		let R=255;
		let G=255;
		let B=255;
		let Zangle=angle+90;
		let ZanglePlus=rand(10,20)*rand_dir;
		loop(10)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=0.5/15;
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus;
			yield;
		}
		ObjPrim_SetDestCenter(obj,144,64,160,96);
		if(id==32){ObjPrim_SetDestCenter(obj,160,64,176,96);}

		loop(5)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=0.5/15;
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus;
			yield;
		}
		Obj_Delete(obj);
	}
}

task ReflectShot(x,y,angle,damage,Opnum,id)
{
	let speed=22.5;
	let obj=CreatePlayerShotA1(x,y,speed*0,angle,damage,1,id);
	Obj_SetRenderPriorityI(obj,40);
	let scale=1.0;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	let count=0;
	let OldX=x;
	let OldY=y;
	let AngleZ=0;
	ObjRender_SetAngleZ(obj,AngleZ);
	ObjShot_SetIntersectionEnable(obj,false);
	loop(30)
	{
		AngleZ+=24;
		ObjRender_SetAngleZ(obj,AngleZ);
		yield;
	}
	loop(15)
	{
		yield;
	}
	ObjShot_SetIntersectionEnable(obj,true);
	ObjShot_SetSpellFactor(obj,true);
	ObjMove_SetSpeed(obj,speed);
	while(!Obj_IsDeleted(obj))
	{
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		count+=1;
		if(count==5 && id==32){ObjMove_SetAngle(obj,270);angle=270;}
		yield;
	}

	HitEffect(OldX,OldY,speed,angle);
	HitEffect2(OldX,OldY,speed,angle);
	Obj_Delete(obj);

	task HitEffect(x,y,speed,angle)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,angle+90);

		ObjPrim_SetDestCenter(obj,144,96,160,128);
		if(id==32){ObjPrim_SetDestCenter(obj,160,96,176,128);}

		ObjRender_SetPosition(obj,x,y,0);
		speed/=8;
		let Scale=1;
		let Alpha=1.0;
		let R=255;
		let G=255;
		let B=255;
		loop(3)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		ObjPrim_SetDestCenter(obj,144,64,160,96);
		if(id==32){ObjPrim_SetDestCenter(obj,160,64,176,96);}
		loop(3)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		ObjPrim_SetDestCenter(obj,144,32,160,64);
		if(id==10){ObjPrim_SetDestCenter(obj,160,32,176,64);}

		loop(3)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=1.0/9;
			yield;
		}
		Obj_Delete(obj);
	}

	task HitEffect2(x,y,speed,angle)
	{
		angle+=180+rand(-90,90);
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_SHOT);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);

		ObjPrim_SetDestCenter(obj,144,96,160,128);
		if(id==32){ObjPrim_SetDestCenter(obj,160,96,176,128);}

		ObjRender_SetPosition(obj,x,y,0);
		speed=rand(2.5,5);
		let Scale=1;
		let Alpha=0.5;
		let R=255;
		let G=255;
		let B=255;
		let Zangle=angle+90;
		let ZanglePlus=rand(10,20)*rand_dir;
		loop(10)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=0.5/15;
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus;
			yield;
		}
		ObjPrim_SetDestCenter(obj,144,64,160,96);
		if(id==32){ObjPrim_SetDestCenter(obj,160,64,176,96);}

		loop(5)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Alpha-=0.5/15;
			ObjRender_SetAngleZ(obj,Zangle);
			Zangle+=ZanglePlus;
			yield;
		}
		Obj_Delete(obj);
	}
}