//メイン＆サブショット
task TShot
{//メイン
	let pShot=false;
	ShotCheck;
	let Speed=22.5;
	let MainDamage=3.0;
	let DamageRate=1;
	loop
	{
		while(!pShot){yield;}
		if(IsPlayerSpellActive){DamageRate=0.5;}
		else{DamageRate=1.0;}

		MainShot(GetPlayerX()+8, GetPlayerY(), Speed, 270, MainDamage, 1, 10);
		MainShot(GetPlayerX()-8, GetPlayerY(), Speed, 270, MainDamage, 1, 10);
		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);
		Obj_SetRenderPriorityI(obj,40);
		let scale=1;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		let OldX;
		let OldY;
		while(!Obj_IsDeleted(obj))
		{
			OldX=ObjMove_GetX(obj);
			OldY=ObjMove_GetY(obj);
			yield;
		}
		HitEffect(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,0);

		ObjPrim_SetDestCenter(obj,3,209,14,224);

		ObjRender_SetPosition(obj,x+1,y-18,0);
		speed/=8;
		let Alpha=0.75;
		let R=255;
		let G=255;
		let B=255;
		loop(15)
		{
			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);
		//	ObjRender_SetAngleZ(obj,angle);
			Alpha-=0.375/15;
			yield;
		}

		ObjPrim_SetDestCenter(obj,3,193,14,208);

		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);
		//	ObjRender_SetAngleZ(obj,angle);
			Alpha-=0.375/5;
			yield;
		}
		Obj_Delete(obj);
	}
}

task TShot2
{//サブ
	let pShot=false;
	ShotCheck;
	let HomingDamage=2.4;
	let NeedleDamage=1.7;
	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];
	loop
	{
		while(!pShot){yield;}
		if(IsPlayerSpellActive){DamageRate=0.5;}
		else{DamageRate=1.0;}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			ascent(i in 0..PlayerPower_Int)
			{
			NeedleShot(OptionX[i]+6,OptionY[i],270,NeedleDamage);
			NeedleShot(OptionX[i]-6,OptionY[i],270,NeedleDamage);
			}
		}
		else
		{
			ascent(i in 0..PlayerPower_Int)
			{
			HomingShot_S(OptionX[i],OptionY[i],ShotAngle[PlayerPower_Int-1][i],HomingDamage);
			}
		}
		loop(6){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 NeedleShot(x,y,angle,damage)
{
	let speed=22.5;
	let obj=CreatePlayerShotA1(x,y,speed,angle,damage,1,12);
	Obj_SetRenderPriorityI(obj,41);
	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);
		yield;
	}
	HitEffect(OldX,OldY,speed,angle);
	HitEffect3(OldX,OldY);
	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,0);

		ObjPrim_SetDestCenter(obj,32+16,192,48+16,256);

		ObjRender_SetPosition(obj,x,y,0);
		speed/=6;
		let ScaleX=1;
		let Alpha=0.4;
		let R=255;
		let G=255;
		let B=255;
		ObjRender_SetAngleZ(obj,rand(-20,20));
		ObjRender_SetAlpha(obj,255*Alpha);
		loop(10)
		{
			ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
			yield;
		}

		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);
			ObjRender_SetScaleX(obj,ScaleX);
			ObjRender_SetAlpha(obj,255*Alpha);
			ScaleX-=1/5;
			Alpha-=0.4/5;
			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=235;
		let G=136;
		let B=16;
		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 HomingShot_S(x,y,angle,damage)
{
	let speed=4;
	let obj=CreatePlayerShotA1(x,y,speed,angle,damage,1,11);
	Obj_SetRenderPriorityI(obj,40);
	let scale=1.0;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	let count=0;
	let OldX=x;
	let OldY=y;
	loop(60)
	{
		if(Obj_IsDeleted(obj)){break;}
		let EnemyObjectArray=GetIntersectionRegistedEnemyID;
		let Dis=(count*5+120)^2;
		let nearObj=-1;
		if(length(EnemyObjectArray)!=0)
		{
		ascent(i in 0..length(EnemyObjectArray))
		{
		let dis=(ObjRender_GetY(EnemyObjectArray[i])-ObjRender_GetY(obj))^2+(ObjRender_GetX(EnemyObjectArray[i])-ObjRender_GetX(obj))^2;
		if(dis<Dis)
		{
			nearObj=EnemyObjectArray[i];
			Dis=dis;
		}
		}
		}

		if(nearObj!=-1)
		{
		let ToPlayerAngle=atan2(ObjRender_GetY(nearObj)-ObjRender_GetY(obj),ObjRender_GetX(nearObj)-ObjRender_GetX(obj));
		let judgangle=sin(ToPlayerAngle-angle);

		if(judgangle>0)
		{
			if(judgangle>0.05)
			{
			angle+=asin(judgangle)/4;
			}
			else
			{
			angle=ToPlayerAngle;
			}
		}
		else
		{
			if(judgangle<-0.05)
			{
			angle+=asin(judgangle)/4;
			}
			else
			{
			angle=ToPlayerAngle;
			}
		}
		ObjMove_SetAngle(obj,angle);
		}
		count++;
		if(count>30){count=30;}
		speed+=5/60;
		ObjMove_SetSpeed(obj,speed);
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		yield;
	}
	while(!Obj_IsDeleted(obj))
	{
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		speed+=5/60;
		ObjMove_SetSpeed(obj,speed);
		yield;
	}
	HitEffect(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,0);

		ObjPrim_SetDestCenter(obj,17,226,31,239);

		ObjRender_SetPosition(obj,x,y,0);
		speed/=4;
		let Alpha=0.5;
		let R=255;
		let G=255;
		let B=255;
		loop(8)
		{
			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);
			ObjRender_SetAngleZ(obj,angle);
		//	Alpha-=1/15;
			yield;
		}

		ObjPrim_SetDestCenter(obj,17,193,31,208);

		loop(12)
		{
			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);
			ObjRender_SetAngleZ(obj,angle);
			Alpha-=0.5/12;
			yield;
		}
		Obj_Delete(obj);
	}
}