//メイン＆サブショット
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, 20);
		MainShot(GetPlayerX()-8, GetPlayerY(), Speed, 270, MainDamage, 1, 20);
//		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);
		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,64,48,96);

		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.25/15;
			yield;
		}

		ObjPrim_SetDestCenter(obj,32,32,48,64);

		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.25/5;
			yield;
		}

		ObjPrim_SetDestCenter(obj,32,0,48,32);

		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.25/5;
			yield;
		}
		Obj_Delete(obj);
	}

}

task TShot2
{//サブ
	let pShot=false;
	ShotCheck;
	let ShotDamage=10.0*0;
	let LaserDamage=0.6;
	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];
	LaserDraw(ShotAngle);
	let LaserLagCount=6;
	let ShotLagCount=0;
	loop
	{
		while(!pShot){ShotLagCount=0;yield;}
		if(IsPlayerSpellActive){DamageRate=0.5;}
		else{DamageRate=1.0;}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
//			PlaySE(SE_MISSILE);
			if(ShotLagCount%2==0)
			{
			MissileShot(OptionX[0],OptionY[0],270,ShotDamage,0);
			MissileShot(OptionX[1],OptionY[1],270,ShotDamage,1);
			}
			else
			{
			MissileShot(OptionX[2],OptionY[2],270,ShotDamage,2);
			MissileShot(OptionX[3],OptionY[3],270,ShotDamage,3);
			}
			ShotLagCount+=1;
			loop(5){yield;}
			if(ShotLagCount%2==0){loop(3){yield;}}
		}
		else
		{
			ascent(i in 0..PlayerPower_Int)
			{
			if(i<=1)
			{
			if(LaserLagCount<=0)
			{
			LaserShot(OptionX[i],OptionY[i],ShotAngle[PlayerPower_Int-1][i],LaserDamage,i);
			}
			}
			else
			{
			LaserShot(OptionX[i],OptionY[i],ShotAngle[PlayerPower_Int-1][i],LaserDamage,i);
			}
			}
		}
		ascent(i in 0..4)
		{
		if(LaserImpactFlag[i]>0)
		{
		LaserImpactFlag[i]=LaserImpactFlag[i]-1;
		}
		}

		LaserLagCount--;
		loop(1){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 MissileShot(x,y,angle,damage,Opnum)
{
	let speed=3;
	let speedPlus=2;
	let obj=CreatePlayerShotA1(x,y,speed,angle,damage,1,21);
	Obj_SetRenderPriorityI(obj,40);
	let scale=1.0;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	let count=2;
	let OldX=x;
	let OldY=y;
	let Alpha=255;
	GraChange;
	loop(6)
	{
		if(Obj_IsDeleted(obj)){break;}
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		count+=1;
		yield;
	}
	while(!Obj_IsDeleted(obj))
	{
		OldX=ObjMove_GetX(obj);
		OldY=ObjMove_GetY(obj);
		speed+=1.5;
		ObjMove_SetSpeed(obj,speed);
		count+=1;
		yield;
	}
	ExplodeAttack(OldX,OldY);
	T_HitEffect(OldX,OldY,speed,angle);
	Obj_Delete(obj);

	task GraChange
	{
		while(!Obj_IsDeleted(obj))
		{	
			if(count%8<4){ObjShot_SetGraphic(obj,23);}
			else{ObjShot_SetGraphic(obj,24);}
			yield;
		}
	}

	task ExplodeAttack(x,y)
	{
		let objAK=CreatePlayerShotA1(x,y,0,0,0.85,65525,21);
		ObjRender_SetAlpha(objAK,0);
		loop(10)
		{
			ObjShot_SetIntersectionCircleA1(objAK,24);
			loop(2){yield;}
		}
		Obj_Delete(objAK);
	}

	task T_HitEffect(x,y,speed,angle)
	{
		if(y>0)
		{
//		PlaySE(SE_MISSILE2);
		ascent(i in 0..10)
		{
			let ra=rand(0,360);
			HitEffect(x+4*i*cos(ra),y+4*i*sin(ra));
			y-=4;
			loop(2){yield;}
		}
		}
	}

	task HitEffect(x,y)
	{
		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);

		ObjRender_SetPosition(obj,x,y,0);
		let Alpha=0.5;
		let Scale=0;
		let R=255;
		let G=255;
		let B=255;

		ObjPrim_SetDestCenter(obj,96,96,128,128);
		loop(4)
		{
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			Scale+=1/4;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			yield;
		}
		ObjPrim_SetDestCenter(obj,96,64,128,96);
		loop(4)
		{
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			yield;
		}
		Alpha=0.25;
		ObjPrim_SetDestCenter(obj,96,32,128,64);
		loop(4)
		{
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			yield;
		}
		ObjPrim_SetDestCenter(obj,96,0,128,32);
		loop(4)
		{
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,1);
			yield;
		}
		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,damage,1,21);
	Obj_SetRenderPriorityI(obj,20);
	let scale=1.0;
	ObjRender_SetScaleXYZ(obj,scale,scale,scale);
	ObjRender_SetAlpha(obj,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,OptionX[Opnum]+dx);
		ObjMove_SetY(obj,OptionY[Opnum]+dy);
		dx+=speed*cos(angle);
		dy+=speed*sin(angle);
		if(GetVirtualKeyState(VK_SHOT)==KEY_PULL){break;}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH){break;}
		if(GetPlayerState!=STATE_NORMAL){break;}
		if(!IsPermitPlayerShot){break;}

		let TempLaserPoint=LaserPoint[Opnum];
		let LaserLeng=((OptionY[Opnum]-LaserPoint[Opnum][1])^2+(OptionX[Opnum]-LaserPoint[Opnum][0])^2)^0.5;
		let Leng=((OptionY[Opnum]-ObjMove_GetY(obj))^2+(OptionX[Opnum]-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 && GetVirtualKeyState(VK_SLOWMOVE)!=KEY_PUSH)
	{
		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+90);
			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;
	}
	if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_FREE)
	{
	LaserPoint=[[0,0],[0,0],[0,0],[0,0]];
	LaserEffect(2);
	LaserEffect(3);
	LaserEffect(0);
	LaserEffect(1);
	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;
	}
	}
	else{yield;}
}
	task LaserEffect(num)
	{
		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,80,0,96,256);
		let Alpha=1.0;
		let R=255;
		let G=255;
		let B=255;
	//	ObjRender_SetScaleXYZ(obj,5,5,5);
	//	ObjRender_SetAngleX(obj,180);
		ObjRender_SetAngleZ(obj,ShotAngle[PlayerPower_Int-1][num]-90);
		let LengMax=0;
		let ScaleX=0;
		let LagCount=6;
		LaserSourceEffect(num);
		let AnimeCount=0;
		while( (GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD ))
		{
			if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH){break;}
			if(GetPlayerState!=STATE_NORMAL){break;}
			if(!IsPermitPlayerShot){break;}
			if(LaserImpactFlag[num]>0)
			{
				R=100;G=100;B=255;
			}
			else
			{
				R=255;G=255;B=255;
			}

			ObjRender_SetPosition(obj,OptionX[num],OptionY[num],0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,ScaleX,1,1);

			let Leng=((OptionY[num]-LaserPoint[num][1])^2+(OptionX[num]-LaserPoint[num][0])^2)^0.5;
			LengMax+=16.875;
			if(LaserPoint[num][0]==0 && LaserPoint[num][1]==0)
			{
				if(num>=2)
				{
				Leng=LengMax;
				}
				else
				{
				if(LagCount>0){LengMax=0;Leng=LengMax;}
				}
			}
			if(Leng>LengMax){Leng=LengMax;}

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

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

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

			LagCount--;
			AnimeCount-=64/5;
			yield;
		}
		loop(3)
		{
			if(LaserImpactFlag[num]>0)
			{
				R=100;G=100;B=255;
			}
			else
			{
				R=255;G=255;B=255;
			}

			ObjRender_SetPosition(obj,OptionX[num],OptionY[num],0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetScaleXYZ(obj,ScaleX,1,1);

			let Leng=((OptionY[num]-LaserPoint[num][1])^2+(OptionX[num]-LaserPoint[num][0])^2)^0.5;
			LengMax+=16.875;
			if(LaserPoint[num][0]==0 && LaserPoint[num][1]==0)
			{
				if(num>=2)
				{
				Leng=LengMax;
				}
				else
				{
				if(LagCount>0){LengMax=0;Leng=LengMax;}
				}
			}
			if(Leng>LengMax){Leng=LengMax;}

			ScaleX-=0.5;

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

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

			LagCount--;
			AnimeCount-=64/5;
			yield;
		}

		Obj_Delete(obj);

		task LaserSourceEffect(num)
		{
			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,43);
			ObjRender_SetAngleZ(obj,0);

			ObjPrim_SetDestCenter(obj,96,192,128,224);
			let Scale=1.25;
			let ScaleTheta=0;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
			let Xangle=-90;
			let Yangle=90;
			let Zangle=0;
			loop(3)
			{
				ObjRender_SetPosition(obj,OptionX[num],OptionY[num],0);
				ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
				Xangle+=30;
				Yangle-=30;
				Zangle+=30;
				yield;
			}
			while(GetVirtualKeyState(VK_SHOT)==KEY_PUSH || GetVirtualKeyState(VK_SHOT)==KEY_HOLD)
			{
				if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH){break;}
				if(GetPlayerState!=STATE_NORMAL){break;}
				if(!IsPermitPlayerShot){break;}
				ObjRender_SetPosition(obj,OptionX[num],OptionY[num],0);
				ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
				ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
				Scale=1.00+0.25*cos(ScaleTheta);
				Zangle+=30;
				ScaleTheta+=45;
				yield;
			}
			loop(3)
			{
				ObjRender_SetPosition(obj,OptionX[num],OptionY[num],0);
				ObjRender_SetAngleXYZ(obj,Xangle,Yangle,Zangle);
				Xangle-=30;
				Yangle+=30;
				Zangle+=30;
				yield;
			}
			Obj_Delete(obj);
		}
	}
}