task ItemCreate(Cobj,No,Success,ChargeLimit,x,y)//玉消ししたときに発生する。装填率を上げたりする
{
		if(No>=11)
		{
			No=10;
		}
	//	let judg=rand_int(0,1);
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBorder);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -4, -4);
		ObjEffect_SetVertexXY(obj, 1, 4,  -4);
		ObjEffect_SetVertexXY(obj, 2, 4, 4);
		ObjEffect_SetVertexXY(obj, 3,  -4,  4);
		
		ObjEffect_SetVertexUV(obj, 0,  173,  119);
		ObjEffect_SetVertexUV(obj, 1,  180, 119);
		ObjEffect_SetVertexUV(obj, 2, 180,  126);
		ObjEffect_SetVertexUV(obj, 3, 173, 126);
		ObjEffect_SetScale(obj,1.2,1.2);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,155,255,255,255);
			}	

		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		let StandardSpeed=rand(2,6);
		let speed=StandardSpeed;
		let angle=rand(0,360);

		let lightangle=rand(0,360);
		let Scale=2;
		loop(15)
		{
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,55+50*cos(lightangle),255,255,255);
			}
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			speed-=StandardSpeed/15;
			Scale-=0.02;
			ObjEffect_SetScale(obj,Scale,Scale);
			wait(1);
		}
		let aspeed=0;

		let amp;
		if(Success)
		{
			if(GetCommonDataDefault("BunSpell",false)==true)
			{
				amp=1+(No-1)*1/9;
			}
			else
			{
				amp=1.5;
				if(GetCommonDataDefault("BunSpell",false)==false && IsBossExisting==false)
				{
					amp=4.5;
				}
			}
		}
		else
		{
			amp=10/3;
			if(GetCommonDataDefault("BunSpell",false)==false && IsBossExisting==false)
			{
				amp=10;
			}
		}
		while(!Obj_BeDeleted(obj))
		{
			Scale-=0.01;
			ObjEffect_SetScale(obj,Scale,Scale);
			if(speed<10)
			{
			speed+=0.25;
			}
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,55+25*cos(lightangle),255,255,255);
			}
			let sangle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(sangle),Obj_GetY(obj)+speed*sin(sangle));
			if(((Obj_GetX(obj)-GetPlayerX)^2+(Obj_GetY(obj)-GetPlayerY)^2)^0.5<10)
			{
					if(Charge<ChargeLimit)
					{
						Charge+=0.50/(10/3)*amp;
					}
					else 
					{
						Charge+=0;
					}
					if(rand_int(0,1)==0)
					{
						if(GetCommonDataDefault("LIGHTMODE",false)==true || PlayerLightMode==true)
						{
						}
						else
						{
							EffectItemCreate;
						}
					}
					PlaySE("seScore.wav");
					Obj_Delete(obj);
			}
		wait(1);
		}
		
}

task CheckItem
{
let ItemCheck=0;//共通データの配列の長さをチェックする変数
let XY=[];//共通データの書き換えにワンクッション置くための変数
let ItemPerFrame=20;//１フレームあたりの最大アイテム生成数（処理落ち対策）
let judg=0;
loop
{
	if(GetCommonDataDefault("DefeatBossAction",false)==true || GetCommonDataDefault("DeleteBulletSignal",false)==true)
	{
		ItemPerFrame=200;
	}
	else
	{
		ItemPerFrame=20;
	}
	ItemCheck=length(GetCommonDataDefault("ItemXY",[]));//毎フレーム共通データの長さチェック
	if(ItemCheck>0)
	{//配列に中身がある（アイテム発生フラグ立っている）場合の処理
		loop(ItemPerFrame)
		{
			XY=GetCommonDataDefault("ItemXY",[]);//共通データ内容を変数に渡す
			if(judg%2==0)
			{
			ChargeItem(XY[0],XY[1],XY[2]);
			}
			if(GetCommonDataDefault("LIGHTMODE",false)==false)
			{
			DeleteShotEffect(XY[0],XY[1],XY[2],0);//アイテム生成。順番にX座標、Y座標、アイテムの種類
			}
			judg+=1;
			loop(3)
			{
				XY=erase(XY, 0);
			}//生成したのでその要素を配列から削除
			if(length(XY)==0)
			{//削除後の配列が空になった場合
				SetCommonData("ItemXY",[]);//共通データを空にして
				break;//アイテム生成ループ脱出
			}
			else
			{
				SetCommonData("ItemXY",XY);
			}//配列が空でない場合共通データに変更後の配列を渡す
		}
	}
yield;
}
}


task DeleteShotEffect(X,Y,color,num)//紅葉の設定
{
		while(GetCommonDataDefault("Shooting",false)){yield;}
	if(GetCommonDataDefault("DefeatBoss",false)==true && num==0)
	{
		DeleteShotEffect(X,Y,color,1);
	}
		let R;let G;let B;
		if(color==0){R=255;G=0;B=0;}
		if(color==1){R=255;G=165;B=0;}
		if(color==2){R=255;G=255;B=0;}
		if(color==3){R=0;G=255;B=0;}
		if(color==4){R=0;G=255;B=255;}
		if(color==5){R=0;G=0;B=255;}
		if(color==6){R=160;G=32;B=240;}
		if(color==7){R=255;G=255;B=255;}
		let Angle=rand(0,360);
		let Speed=rand(0.2,0.4);
		let RotateAngle=rand(2,10);
		let Zangle=rand(0,360);
		let dir=rand_int(0,1)*2-1;
		let Scale=0.45;
		let Alpha=150;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMissEffect2);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -15, -15);
		ObjEffect_SetVertexXY(obj, 1, 15,  -15);
		ObjEffect_SetVertexXY(obj, 2, 15, 15);
		ObjEffect_SetVertexXY(obj, 3,  -15,  15);
		
		ObjEffect_SetVertexUV(obj, 0,  2,  24);
		ObjEffect_SetVertexUV(obj, 1,  32, 24);
		ObjEffect_SetVertexUV(obj, 2, 32,  55);
		ObjEffect_SetVertexUV(obj, 3, 2, 55);
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		Obj_SetPosition(obj,X,Y);
		Obj_SetAngle(obj,Angle);
		Obj_SetSpeed(obj,Speed);

		loop(30)
		{
			ObjEffect_SetAngle(obj,0,0,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Zangle+=RotateAngle*dir;
			Scale-=0.015;
			yield;
		}
		Obj_Delete(obj);
}

task ChargeItem(X,Y,color)
{
		if(GetCommonDataDefault("DeleteBulletSignal",false)==true || GetCommonDataDefault("DefeatBoss",false)==true)
		{
			wait(30);
			SetCommonData("DeleteBulletSignal",false);
			return;
		}
		while(GetCommonDataDefault("Shooting",false)){yield;}
		let R;let G;let B;
		if(color==0){R=255;G=0;B=0;}
		if(color==1){R=255;G=165;B=0;}
		if(color==2){R=255;G=255;B=0;}
		if(color==3){R=0;G=255;B=0;}
		if(color==4){R=0;G=255;B=255;}
		if(color==5){R=0;G=0;B=255;}
		if(color==6){R=160;G=32;B=240;}
		if(color==7){R=255;G=255;B=255;}
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBorder);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -4, -4);
		ObjEffect_SetVertexXY(obj, 1, 4,  -4);
		ObjEffect_SetVertexXY(obj, 2, 4, 4);
		ObjEffect_SetVertexXY(obj, 3,  -4,  4);
		
		ObjEffect_SetVertexUV(obj, 0,  173,  119);
		ObjEffect_SetVertexUV(obj, 1,  180, 119);
		ObjEffect_SetVertexUV(obj, 2, 180,  126);
		ObjEffect_SetVertexUV(obj, 3, 173, 126);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,205,R,G,B);
			}	

		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,X,Y);
		let StandardSpeed=rand(2,6);
		let speed=StandardSpeed;
		let angle=rand(0,360);

		let lightangle=rand(0,360);
		let Scale=2;
		ObjEffect_SetScale(obj,Scale,Scale);

		loop(20)
		{
		if(GetCommonDataDefault("DefeatBoss",false)==true)
		{
			Obj_Delete(obj);
			return;
		}
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,55+25*cos(lightangle),R,G,B);
			}
			Obj_SetAngle(obj,angle);
			Obj_SetSpeed(obj,speed);
			speed-=StandardSpeed/20;
			Scale-=0.015;
			ObjEffect_SetScale(obj,Scale,Scale);
			wait(1);
		}
		let aspeed=0;
let amp;
let ChargeLimit;
		while(!Obj_BeDeleted(obj))
		{
			Scale-=0.01;
			ObjEffect_SetScale(obj,Scale,Scale);
			if(speed<10)
			{
			speed+=0.25;
			}
			if(GetCommonDataDefault("Playermissed",false)==true){speed=0;wait(30);Obj_Delete(obj);}
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,55+25*cos(lightangle),R,G,B);
			}
			let sangle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			Obj_SetAngle(obj,sangle);
			Obj_SetSpeed(obj,speed);
			if(((Obj_GetX(obj)-GetPlayerX)^2+(Obj_GetY(obj)-GetPlayerY)^2)^0.5<10)
			{

			if(ShootingSuccess)
			{
				amp=1+(photoNo-1)*1/9;
			}
			else
			{
				amp=10/3;
			}
			if(ShootingSuccess==true)
			{
				if(CameraWide==192)
				{
					ChargeLimit=35;
				}
				if(CameraWide==144)
				{
					ChargeLimit=60;
				}
			}
			else
			{
				if(CameraWide==192)
				{
					ChargeLimit=55;
				}
				if(CameraWide==144)
				{
					ChargeLimit=75;
				}
			}
					if(Charge<ChargeLimit)
					{
						Charge+=0.50/(10/3)*amp;
					}
					else 
					{
						Charge+=0;
					}
					if(rand_int(0,1)==0)
					{
						if(GetCommonDataDefault("LIGHTMODE",false)==true || PlayerLightMode==true)
						{
						}
						else
						{
							EffectItemCreate;
						}
					}
				PlaySE("seScore.wav");
				Obj_Delete(obj);
			}
		yield;
		}
}

task EffectItemCreate//アイテム取得時のエフェクト
{
		let scax=1;
		let scay=1;
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBorder);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -4, -4);
		ObjEffect_SetVertexXY(obj, 1, 4,  -4);
		ObjEffect_SetVertexXY(obj, 2, 4, 4);
		ObjEffect_SetVertexXY(obj, 3,  -4,  4);
		
		ObjEffect_SetVertexUV(obj, 0,  173,  119);
		ObjEffect_SetVertexUV(obj, 1,  180, 119);
		ObjEffect_SetVertexUV(obj, 2, 180,  126);
		ObjEffect_SetVertexUV(obj, 3, 173, 126);
		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,255,100,100,255);
			}
		let StandardSpeed=rand(3,5);	
		let speed=StandardSpeed;
		let angle=rand(0,360);
		let lightangle=rand(0,360);
		loop(50)
		{
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,205+50*cos(lightangle),100,100,255);
			}
			Obj_SetAngle(obj,angle);
			Obj_SetSpeed(obj,speed);
			speed-=StandardSpeed/50;
			ObjEffect_SetScale(obj, scax,scay);
			scax-=0.005;
			scay-=0.005;
			wait(1);
		}

		loop(50)
		{
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,205+50*cos(lightangle),100,100,255);
			}
			let sangle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			Obj_SetAngle(obj,sangle);
			Obj_SetSpeed(obj,speed);
			speed+=0.3;
			ObjEffect_SetScale(obj, scax,scay);
			scax-=0.015;
			scay-=0.015;
			wait(1);
		}
		Obj_Delete(obj);
}