//メイン＆サブショット
task TShot
{//メイン
	let pShot=false;
	ShotCheck;
	let Speed=22.5;
	let MainDamage=2;
	let DamageRate=1*1.15;
	let SHOT = 114;
	LaserDraw(0);
	let count = 0;
	loop
	{
		while(!pShot)
		{
			count+=3.5/3;
			yield;
		}
		if(PlayerType==1)
		{
			if((GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD))
			{
				MainShot(GetPlayerX,GetPlayerY,35,-90+4*sin(count),MainDamage,1,179);
				MainShot(GetPlayerX,GetPlayerY,35,-90-4*sin(count),MainDamage,1,179);	
				MainShot(OptionX[0],OptionY[0],35,-90+10*sin(count),MainDamage,1,179);
				MainShot(OptionX[1],OptionY[1],35,-90-10*sin(count),MainDamage,1,179);	
				MainShot(OptionX[0],OptionY[0],35,-90+30*sin(count),MainDamage,1,179);
				MainShot(OptionX[1],OptionY[1],35,-90-30*sin(count),MainDamage,1,179);
				MainShot(OptionX[0],OptionY[0],35,-90+50*sin(count),MainDamage,1,179);
				MainShot(OptionX[1],OptionY[1],35,-90-50*sin(count),MainDamage,1,179);	
				MainShot(OptionX[0],OptionY[0],35,-90+75*sin(count),MainDamage,1,179);
				MainShot(OptionX[1],OptionY[1],35,-90-75*sin(count),MainDamage,1,179);
			}
			else
			{
					
				MainShot(GetPlayerX,GetPlayerY,35,-90+4*sin(count),MainDamage,1,179);
				MainShot(GetPlayerX,GetPlayerY,35,-90-4*sin(count),MainDamage,1,179);	
				MainShot(OptionX[0],OptionY[0],35,-90+10*sin(count+72),MainDamage,1,179);
				MainShot(OptionX[1],OptionY[1],35,-90-10*sin(count+72),MainDamage,1,179);	
				MainShot(OptionX[0],OptionY[0],35,-90+30*sin(count+72*2),MainDamage,1,179);
				MainShot(OptionX[1],OptionY[1],35,-90-30*sin(count+72*2),MainDamage,1,179);
				MainShot(OptionX[0],OptionY[0],35,-90+50*sin(count+72*3),MainDamage,1,179);
				MainShot(OptionX[1],OptionY[1],35,-90-50*sin(count+72*3),MainDamage,1,179);	
				MainShot(OptionX[0],OptionY[0],35,-90+75*sin(count+72*4),MainDamage,1,179);
				MainShot(OptionX[1],OptionY[1],35,-90-75*sin(count+72*4),MainDamage,1,179);
				
			
			}
			PlaySE(SE_SHOT);
			loop(3)
			{
				count+=3.5/3;
				yield;
			}
		}
		else
		{
			LaserShot(GetPlayerX,GetPlayerY,-90,8/3,1);
			LaserShotDummy;
			loop(1){yield;}
		}
	}
	task LaserShotDummy
	{
		let obj=CreatePlayerShotA1(GetPlayerX,GetPlayerY,25,-90,10/6,999,149);
		Obj_SetRenderPriorityI(obj,40);
		let scale=1;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		ObjRender_SetAlpha(obj,0);
		let OldX;
		let OldY;
		while(!Obj_IsDeleted(obj))
		{
			ObjMove_SetAngle(obj,-90);
			ObjMove_SetX(obj,GetPlayerX);
			yield;
		}
	}
	task ShotCheck
	{
		loop
		{
			if((GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD) && GetPlayerState==STATE_NORMAL && IsPermitPlayerShot && !IsPlayerSpellActive && !OnSpell)
			{
			pShot=true;

			}
			else
			{
			pShot=false;

			}
			yield;
		}
	}

	task MainShot(x,y,speed,angle,damage,pene,id)
	{
		let obj=CreatePlayerShotA1(x,y,speed,angle,damage,999,id);
		Obj_SetRenderPriorityI(obj,40);
		let scale=1;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		let OldX;
		let OldY;
		while(!Obj_IsDeleted(obj)&&ObjShot_GetPenetration(obj)==999)
		{
			OldX=ObjMove_GetX(obj);
			OldY=ObjMove_GetY(obj);

			yield;
		}
		ObjShot_SetIntersectionEnable(obj,false);
		ObjMove_SetSpeed(obj,speed/16);
		ObjShot_SetDamage(obj,0);
		let ALF = 255;
		let scale2 = 1;
		loop(20)
		{
			ObjRender_SetAlpha(obj,ALF);
			ObjRender_SetScaleXYZ(obj,scale,scale2,scale);
			scale+=4/20;
			scale2-=1/20;
			ALF-=255/20;
			yield;
		}
		//HitEffect(OldX,OldY,speed,angle);
		Obj_Delete(obj);
	}


}
let LaserPoint=[[0,0],[0,0],[0,0],[0,0]];
let LaserImpactFlag=[0,0,0,0];

task LaserShot(x,y,angle,damage,Opnum)
{
	let speed=16.875;
	let obj=CreatePlayerShotA1(x,y,speed,angle,0,1,21);
	let obj2=CreatePlayerShotA1(x,y,speed,angle,10,999,21);
	
	Obj_SetRenderPriorityI(obj,20);
	Obj_SetRenderPriorityI(obj2,20);
	let scale=1.0;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	ObjRender_SetAlpha(obj,0);
	ObjRender_SetAlpha(obj2,0);
	let count=0;
	let OldX=x;
	let OldY=y;
	let dx=0;
	let dy=0;
	while(!Obj_IsDeleted(obj))
	{
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		ObjMove_SetX(obj,GetPlayerX+dx);
		ObjMove_SetY(obj,GetPlayerY+dy);
		
		ObjMove_SetX(obj2,GetPlayerX+dx);
		ObjMove_SetY(obj2,GetPlayerY+dy);
		
		ObjMove_SetAngle(obj,-90);
		ObjMove_SetAngle(obj2,-90);
		
		dx+=speed*cos(angle);
		dy+=speed*sin(angle);
		if(GetVirtualKeyState(VK_SHOT)==KEY_PULL){break;}
		if(GetPlayerState!=STATE_NORMAL){break;}
		if(!IsPermitPlayerShot){break;}

		let TempLaserPoint=LaserPoint[Opnum];
		let LaserLeng=((GetPlayerY-LaserPoint[Opnum][1])^2+(GetPlayerX-LaserPoint[Opnum][0])^2)^0.5;
		let Leng=((GetPlayerY-ObjMove_GetY(obj))^2+(GetPlayerX-ObjMove_GetX(obj))^2)^0.5;
		if(LaserLeng<Leng)
		{
			let TempLaserPoint=LaserPoint[Opnum];
			TempLaserPoint[0]=OldX;
			TempLaserPoint[1]=OldY;
			LaserPoint[Opnum]=TempLaserPoint;
		}

		yield;
	}

	if(GetVirtualKeyState(VK_SHOT)!=KEY_PULL )
	{
		let TempLaserPoint=LaserPoint[Opnum];
		TempLaserPoint[0]=OldX;
		TempLaserPoint[1]=OldY;
		LaserPoint[Opnum]=TempLaserPoint;
		if(OldY>-16)
		{
			//HitEffect(OldX,OldY,speed,angle);
			LaserImpactFlag[Opnum]=2;
		}
	}
	else
	{

	}
	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,64,34,80,61);

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

task LaserDraw(ShotAngle)
{
loop
{
	while(GetPlayerState!=STATE_NORMAL || !IsPermitPlayerShot){yield;}
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH)
	{
		if(GetVirtualKeyState(VK_SHOT)==KEY_HOLD){break;}
		yield;
	}

	LaserPoint=[[0,0],[0,0],[0,0],[0,0]];
	if(PlayerPower_Int==3||PlayerPower_Int==4||PlayerPower_Int==5)
	{
		LaserEffect(0);
	}
	while( GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD)
	{
		//if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PULL){break;}
		if(GetPlayerState!=STATE_NORMAL){break;}
		if(!IsPermitPlayerShot){break;}
		yield;
	}
	
	yield;
}
	task LaserEffect(num)
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_TSUBAKURA_LASER);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
		Obj_SetRenderPriorityI(obj,40);
		ObjRender_SetAngleZ(obj,0);
		
		ObjPrim_SetDestCenter(obj,0,0,12,50);
		let Alpha1=0.0;
		let Alpha2=0.0;
		let R=255;
		let G=255;
		let B=255;
	//	ObjRender_SetScaleXYZ(obj,5,5,5);
	//	ObjRender_SetAngleX(obj,180);
		ObjRender_SetAngleZ(obj,180);
		let LengMax=0;
		let ScaleX=0;
		let LagCount=6;

		let AnimeCount=0;
		while( (GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD ))
		{
			//if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_FREE){break;}
			if(GetPlayerState!=STATE_NORMAL){break;}
			if(!IsPermitPlayerShot){break;}
			if(PlayerType==-1)
			{
				Alpha1 = 1
			}
			else
			{
				Alpha1 = 0;
			}
			ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
			ObjRender_SetColor(obj,255*Alpha1,255*Alpha1,255*Alpha1);
			ObjRender_SetScaleXYZ(obj,ScaleX,1,2);

			let Leng=((GetPlayerY)^2+(GetPlayerX)^2)^0.5;
			LengMax+=50*9;
			Alpha1+=1/30;
			if(LaserPoint[num][0]==0 && LaserPoint[num][1]==0)
			{
				if(num>=2)
				{
				Leng=GetStgFrameHeight+90;
				}
				else
				{
				if(LagCount>0){LengMax=0;Leng=LengMax;}
				}
			}
			if(Leng>LengMax){Leng=LengMax;}

			if(ScaleX<1){ScaleX+=0.5;}

			ObjPrim_SetVertexUVT(obj, 0, 0, AnimeCount);
			ObjPrim_SetVertexUVT(obj, 1, 12, AnimeCount);
			ObjPrim_SetVertexUVT(obj, 2, 12, Leng+AnimeCount);
			ObjPrim_SetVertexUVT(obj, 3, 0, Leng+AnimeCount);

			ObjPrim_SetVertexPosition(obj, 0, -6, 0, -0);
			ObjPrim_SetVertexPosition(obj, 1, 6, 0, -0);
			ObjPrim_SetVertexPosition(obj, 2, 6, Leng, 0);
			ObjPrim_SetVertexPosition(obj, 3, -6, Leng, 0);

			LagCount--;
			AnimeCount-=50/5;
			yield;
		}
		Obj_Delete(obj);
	}
}
//if(ShotLagCount%1==0){loop(7){yield;}}
task TShot2
{//サブ
	let pShot=false;
	ShotCheck;
	let ShotLagCount=0;
	let HomingDamage=3.4*1;
	let DamageRate=1*1.5;
	let LaserDamage=0.6*2;

	let Plusangle = 0;
	let Plusangle2 = 0;
	let bit = 5;
	let bit2 = 5;
	let bit4 = 1;
	let darm = 1;
	let LaserLagCount=6;
	loop
	{
		while(!pShot){yield;}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			if(PlayerType==1)
			{
				
				WHITE(OptionX[0],OptionY[0],-90+90*sin(Plusangle),10,1);
				WHITE(OptionX[1],OptionY[1],-90-90*sin(Plusangle),10,-1);
				
			}
			else
			{
				PlaySE(SE_SHOT);
				ascent(i in 0..6)
				{
					BLACK(OptionX[i],OptionY[i],270-5*cos(OpangleT+360/6*i),7,149);
					
					BLACK(OptionX[i],OptionY[i],270+5*cos(OpangleT+360/6*i),1,148);
				}
			}
			loop(3){yield;}
		}
		else
		{
			if(PlayerType==1)
			{
				WHITE(OptionX[0],OptionY[0],-90+90*sin(Plusangle),10,1);
				WHITE(OptionX[1],OptionY[1],-90-90*sin(Plusangle),10,-1);
			}
			else
			{
				PlaySE(SE_SHOT);
				ascent(i in 0..6)
				{
					BLACK(OptionX[i],OptionY[i],270-15*cos(OpangleT+360/6*i),4,149);
					
					BLACK(OptionX[i],OptionY[i],270-5*cos(OpangleT+360/6*i),4,148);
				}
			}
			Plusangle+=4.23;
			Plusangle2-=4.23;
			loop(3){yield;}
		}

		
	}

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

			}
			else
			{
			pShot=false;

			}
			yield;
		}
	}

	
	
}
task BLACK(x,y,angle,damage,ID)
{

	let obj=CreatePlayerShotA1(x,y,22.5,angle,damage-1,999,ID);

	Obj_SetRenderPriorityI(obj,40);
	ObjRender_SetAlpha(obj,128);
	let scale=1.0;
	if(ID==149)
	{
		ObjRender_SetScaleXYZ(obj,1/2,scale,scale);
	}
	let count=255;
	let OldX=x;
	let OldY=y;
	while(!Obj_IsDeleted(obj)&&ObjShot_GetPenetration(obj)==999)
	{
		ObjRender_SetColor(obj,count,count,count);
		count-=255/10;
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);

		yield;
	}
	ObjShot_SetIntersectionEnable(obj,false);
	ObjMove_SetSpeed(obj,22.5/8);
	ObjShot_SetDamage(obj,0);
	let ALF = 128;
	loop(10)
	{
		ObjRender_SetAlpha(obj,ALF);
		ObjRender_SetScaleXYZ(obj,1,scale,scale);
		if(ID==149)
		{
			ObjRender_SetScaleXYZ(obj,1/2,scale,scale);
		}
		scale+=3/10;
		ALF-=128/10;
		yield;
	}
	Obj_Delete(obj);


}
task WHITE(x,y,angle,damage,bit)
{

	let obj=CreatePlayerShotA1(x,y,1,angle,damage-1,999,157);
	
	Obj_SetRenderPriorityI(obj,40);
	let scale=1.0;
	
	let count=0;
	let OldX=x;
	let OldY=y;
	ObjRender_SetAlpha(obj,32);
	Mover(obj);
	while(!Obj_IsDeleted(obj)&&ObjShot_GetPenetration(obj)==999)
	{
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);

		yield;
	}
	ObjShot_SetIntersectionEnable(obj,false);
	ObjShot_SetDamage(obj,0);
	let ALF = 32;
	let scale2 = 15;
	let sped = 30;
	loop(20)
	{
		ObjMove_SetSpeed(obj,sped/5);
		ObjRender_SetAlpha(obj,ALF);
		ObjRender_SetScaleXYZ(obj,scale/2,scale2,scale);
		scale2-=15/20;
		sped-=30/20;
		//ALF-=255/20;
		yield;
	}
	task Mover(obj)
	{
		ObjShot_SetIntersectionEnable(obj,false);
		ObjRender_SetScaleXYZ(obj,0.5,1,1);
		loop(30)
		{
			ObjRender_SetAngleZ(obj,ObjRender_GetAngleZ(obj)+24.32*bit);
			yield;
		}
		ObjShot_SetIntersectionEnable(obj,true);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetAngleZ(obj,0);
		ObjMove_SetSpeed(obj,30);
		x = ObjMove_GetX(obj);
		y = ObjMove_GetY(obj);
		ObjRender_SetScaleXYZ(obj,0.5,15,1);
		loop(1)
		{
			let nearObj=-1;
			let EnemyObjectArray=GetIntersectionRegistedEnemyID;
			let dis=0;
			let Dis=1000^2;
			if(length(EnemyObjectArray)!=0)
			{
				ascent(i in 0..length(EnemyObjectArray))
				{
				dis=(ObjRender_GetY(EnemyObjectArray[i]-y^2)+(ObjRender_GetX(EnemyObjectArray[i])-x))^2;
				if(dis<Dis)
				{
					nearObj=EnemyObjectArray[i];
					Dis=dis;
				}
				}
			}
			if(nearObj!=-1)
			{
				ObjMove_SetAngle(obj,atan2(ObjRender_GetY(nearObj)-y,ObjRender_GetX(nearObj)-x));
			}
			else{}
		}
	}
	Obj_Delete(obj);


}



