//���C�����T�u�V���b�g
task TShot
{//���C��
	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 && !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,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
{//�T�u
	let pShot=false;
	ShotCheck;
	let HomingDamage=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];
	loop
	{
		while(!pShot){yield;}
		if(IsPlayerSpellActive){DamageRate=0.5;}
		else{DamageRate=1.0;}
		if(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
		{
			Rod;
			while(GetVirtualKeyState(VK_SLOWMOVE)==KEY_PUSH || GetVirtualKeyState(VK_SLOWMOVE)==KEY_HOLD)
			{
			if(GetPlayerState==STATE_DOWN){break;}
			if(GetPlayerState==STATE_END){break;}
			if(OnSpell){break;}
			if(GetVirtualKeyState(VK_SHOT)==KEY_PULL){break;}
			yield;
			}
		}
		else
		{
			if(RodFlag){DamageRate=0.5;}
			else{DamageRate=1.0;}
			ascent(i in 0..PlayerPower_Int)
			{
			HomingShot_S(OptionX[i],OptionY[i],ShotAngle[PlayerPower_Int-1][i],HomingDamage*DamageRate);
			}
		}
		loop(6){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 Rod
	{
		if(RodFlag){return;}
		RodFlag=true;
		RodX=GetPlayerX;
		RodY=GetPlayerY;
		let D_RodX=GetPlayerX;
		let D_RodY=GetPlayerY-80;
		let RodSpeed=7.5;
		let RodAngle=270;
		let RodRange=[43.2,57.6,72,86.4];
//		let objRod=CreatePlayerShotA1(GetPlayerX,GetPlayerY,RodSpeed,RodAngle,15,65535,100+PlayerPower_Int-1);
		let objRod=CreatePlayerShotA1(GetPlayerX,GetPlayerY,RodSpeed,RodAngle,12.5,65535,100+PlayerPower_Int-1);
		ObjShot_SetAutoDelete(objRod,false);

		let Count=0;
		let SlowCount=0;
		let nearObj=-1;
		let HitCount=0;
		RodMove;
		HitCheck;
		RodEffect(2);
		RodEffect(1);
		RodEffect(0);

		task RodMove
		{
		while(!Obj_IsDeleted(objRod))
		{
			if(GetVirtualKeyState(VK_SLOWMOVE)!=KEY_HOLD || GetVirtualKeyState(VK_SHOT)==KEY_FREE)
			{
				SlowCount++;
			}
			else{SlowCount=0;}
			if(SlowCount>=12){break;}
			if(GetPlayerState==STATE_DOWN){break;}
			if(GetPlayerState==STATE_END){break;}
			if(OnSpell){break;}

			ObjMove_SetPosition(objRod,RodX,RodY);
			RodX+=RodSpeed*cos(RodAngle);
			RodY+=RodSpeed*sin(RodAngle);
			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])-ObjRender_GetY(objRod))^2+(ObjRender_GetX(EnemyObjectArray[i])-ObjRender_GetX(objRod))^2;
				if(dis<Dis)
				{
					nearObj=EnemyObjectArray[i];
					Dis=dis;
				}
				}
			}
			else
			{
				nearObj=-1;
			}
			let DistanceFlag=false;
			if(dis>=150^2 && Count<20){nearObj=-1;DistanceFlag=true;}
			if(nearObj!=-1)
			{
			RodAngle=atan2(ObjRender_GetY(nearObj)-ObjRender_GetY(objRod),ObjRender_GetX(nearObj)-ObjRender_GetX(objRod));
			let dis=(ObjRender_GetY(nearObj)-ObjRender_GetY(objRod))^2+(ObjRender_GetX(nearObj)-ObjRender_GetX(objRod))^2;
			if(Count>=20 && dis<(RodRange[PlayerPower_Int-1])^2)
			{
				RodSpeed=-7.5/60;
			}
			else
			{
			RodSpeed+=7.5/60;
			if(RodSpeed>7.5){RodSpeed=7.5;}
			}
			}
			else if(Count>=10 && !DistanceFlag)
			{
				RodSpeed*=0.8;
			}
			Count++;
			yield;
		}
		Obj_Delete(objRod);
		RodFlag=false;
		}

		task HitCheck
		{
		while(!Obj_IsDeleted(objRod))
		{
			if(nearObj!=-1 && length(GetIntersectionRegistedEnemyID)!=0)
			{
				let d=((ObjRender_GetX(objRod)-ObjRender_GetX(nearObj))^2+(ObjRender_GetY(objRod)-ObjRender_GetY(nearObj))^2)^0.5;
				if(d<=RodRange[PlayerPower_Int-1]+12 && HitCount<=0)
				{
					ObjShot_SetIntersectionEnable(objRod,true);
					HitCount=7;
				}
				else
				{
					ObjShot_SetIntersectionEnable(objRod,false);
					HitCount-=1;
				}
			}
			else
			{
				ObjShot_SetIntersectionEnable(objRod,false);
				HitCount=0;
			}
			yield;
		}
		}

		task RodEffect(num)
		{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj,IMG_ROD);
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,41);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 0);
		ObjPrim_SetVertexUVT(obj, 1, 64, 0);
		ObjPrim_SetVertexUVT(obj, 2, 64, 64);
		ObjPrim_SetVertexUVT(obj, 3, 0, 64);

		ObjPrim_SetVertexPosition(obj, 0, -16, -48, -0);
		ObjPrim_SetVertexPosition(obj, 1, 48, -48, -0);
		ObjPrim_SetVertexPosition(obj, 2, 48, 16, 0);
		ObjPrim_SetVertexPosition(obj, 3, -16, 16, 0);

		let Zangle=-num*60;
		let Alpha=1.0-0.33*num;
		let AlphaMax=Alpha;
		let R=255;
		let G=255;
		let B=255;
		let Scale=0.6+PlayerPower_Int*0.3;
		let ScaleMax=Scale;
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		while(!Obj_IsDeleted(objRod))
		{
			Scale=0.6+PlayerPower_Int*0.3;
			ScaleMax=Scale;
			ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);

			ObjRender_SetPosition(obj,ObjRender_GetX(objRod),ObjRender_GetY(objRod),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetAngleZ(obj,Zangle);
			if(HitCount>=5)
			{
				R=255;G=50;B=50;
			}
			else
			{
				R=255;G=150;B=255;
				Zangle+=30;
			}
		//	Alpha-=1/15;
			yield;
		}
		R=255;G=150;B=255;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		loop(12)
		{
			//ObjRender_SetPosition(obj,ObjRender_GetX(objRod),ObjRender_GetY(objRod),0);
			ObjRender_SetColor(obj,R*Alpha,G*Alpha,B*Alpha);
			ObjRender_SetAngleZ(obj,Zangle);
			ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
			Zangle+=30;
		//	Alpha-=1/12;
			Scale-=ScaleMax/12;
			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);
	}
}