task BombCheck
{
loop
{
	if(OnBomb)
	{
		if(SectionMagicFragment>0)
		{
		
			if(SectionMagicFragment<=6000)
			{
			SectionMagicFragment-=1;
			}
			else
			{
				SectionMagicFragment-=floor(SectionMagicFragment/6000);
			}

			if(BurstMode==1)
			{
				if(SectionMagicFragment<=6000)
				{
					SectionMagicFragment-=1;
				}
				else
				{
					SectionMagicFragment-=floor(SectionMagicFragment/6000);
				}
			}
		}
		BurstRank-=5;
		if(RushGauge>0){RushGauge-=1;}
		else{RushGauge+=1;}
	}
yield;
}
}

task SlowKeyCheck
{
wait(30);
if(GetCommonDataDefault("SELECTEDDIFFICULT","None")!="Extream"){return;}
let count=0;
loop
{
	if(GetKeyState(VK_SLOWMOVE)!=KEY_FREE)
	{
		count=15;
	}
	if(count>0)
	{
	count-=1;
	}
	if(count>0)
	{
		SetCommonData("SlowMoveSwitch",true);
	}
	else
	{
		SetCommonData("SlowMoveSwitch",false);
	}
yield;
}

}

let MainShotCreateItemJudg=0;

function MainShotHit(x,y)
{
	if(MainShotCreateItemJudg<6)
	{
		MainShotCreateItemJudg+=1;
		return;
	}
	else
	{
		MainShotCreateItemJudg=0;
	}
	let PowerPlus;
	let CounterPlus;
	let CounterPlusOnBurst;
	let ScorePlus;
	let FragmentPlus=1;

	let DifficultChargeAmp=1;
	let DifficultCounterAmp=1;
	let DifficultScoreAmp=1;
	let DifficultFragmentAmp=1;

	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
		DifficultChargeAmp=1;
		DifficultCounterAmp=1;
		DifficultScoreAmp=1;
		DifficultFragmentAmp=1;
	}
	case("Extream")
	{
		DifficultChargeAmp=1.0;
		DifficultCounterAmp=1.0;
		DifficultScoreAmp=1.5;
		DifficultFragmentAmp=1.0;
	}
	case("Apocalypse")
	{
		DifficultChargeAmp=1.0;
		DifficultCounterAmp=1.0;
		DifficultScoreAmp=2.0;
		DifficultFragmentAmp=1.0;
	}
	others{}

	if(BurstMode==1)
	{
		PowerPlus=2.5*DifficultChargeAmp;
		CounterPlus=10*DifficultCounterAmp;
		CounterPlusOnBurst=10*DifficultCounterAmp;
		ScorePlus=MagicCounter*10*DifficultScoreAmp;
		FragmentPlus=1*DifficultFragmentAmp;
	}
	else
	{
		PowerPlus=0.5*DifficultChargeAmp;
		CounterPlus=5*DifficultCounterAmp;
		CounterPlusOnBurst=5*DifficultCounterAmp;
		ScorePlus=MagicCounter*DifficultScoreAmp;
		FragmentPlus=1*DifficultFragmentAmp;
	}

	if(Power<1000 && BurstMode==0)
	{
		Power+=PowerPlus;
	}
	if(MagicCounter<10000 && BurstMode==0)
	{
		MagicCounter+=CounterPlus;
	}
	if(MagicCounter<10000 && BurstMode==1)
	{
		MagicCounter+=CounterPlusOnBurst;
	}

	AddScore(ScorePlus);
	MagicFragment+=FragmentPlus;
	SectionMagicFragment+=FragmentPlus;
	//PlaySE("se\seScore.wav");
}

task CreateMigicItem(x,y,type)
{
		if(WeaknessCount>0 && type!=-1){return;}
		let DifficultChargeAmp=1;
		let DifficultCounterAmp=1;
		let DifficultScoreAmp=1;
		let DifficultFragmentAmp=1;


		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			DifficultChargeAmp=1;
			DifficultCounterAmp=1;
			DifficultScoreAmp=1;
			DifficultFragmentAmp=1;
		}
		case("Extream")
		{
			DifficultChargeAmp=1.0;
			DifficultCounterAmp=1.0;
			DifficultScoreAmp=1.0;
			DifficultFragmentAmp=1.0;
		}
		case("Apocalypse")
		{
			DifficultChargeAmp=1.0;
			DifficultCounterAmp=1.0;
			DifficultScoreAmp=2.0;
			DifficultFragmentAmp=1.0;
		}
		others{}

		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgItem);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);
		
		ObjEffect_SetVertexUV(obj, 0,  12,  12);
		ObjEffect_SetVertexUV(obj, 1,  52, 12);
		ObjEffect_SetVertexUV(obj, 2, 52,  52);
		ObjEffect_SetVertexUV(obj, 3, 12, 52);

			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(3,10);
		let speed=StandardSpeed;
		//let angle=rand(0,360);
		let angle=atan2(GetPlayerY-y,GetPlayerX-x)+180+rand(-120,120);

		let lightangle=rand(0,360);
		let ZAngle=0;
		let ZRotateAngle=rand(-15,15);
		let Scale;
		let DiScale;
		let R;
		let G;
		let B;
		let Alpha=155;
		let VAlpha=50;
		let PowerPlus;
		let CounterPlus;
		let CounterPlusOnBurst;
		let ScorePlus;
		let FragmentPlus=1;
		let RushGaugePlus=0;
		let amp=1;
		let BurstRankPlus=0;

		let RushGaugeAdjustPower=1;
		let RushGaugeAdjustMagic=1;
		let RushGaugeAdjustScore=1;
		let RushGaugeAdjustFragment=1;
		let RushGaugeAdjustRankUp=1;
		let RushGaugeAdjustRankDown=1;

		if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Extream")
		{
			if(RushGauge>=0)
			{
				RushGaugeAdjustPower=1-0.25*RushGauge/1000;
				RushGaugeAdjustScore=1+0.5*RushGauge/1000;
				RushGaugeAdjustFragment=1+0.5*RushGauge/1000;
				RushGaugeAdjustRankUp=1+0.5*RushGauge/1000;
			}
			else
			{
				RushGaugeAdjustPower=1-0.25*RushGauge/1000;
				RushGaugeAdjustMagic=1-0.25*RushGauge/1000;
				RushGaugeAdjustRankDown=1-0.5*RushGauge/1000;
			}
		}
		
		if(type==-1)//黒アイテム
		{
			ObjEffect_SetRenderState(obj,SUBTRACT); 
			Scale=1.5;
			DiScale=0.015;
			R=255;
			G=255;
			B=255;
			PowerPlus=0;
			CounterPlus=0;
			CounterPlusOnBurst=0;
			ScorePlus=0;
			BurstRankPlus=0;
			FragmentPlus=0;
		}
		if(type==1)//緑アイテム
		{
			Scale=1.5;
			DiScale=0.015;
			R=127;
			G=255;
			B=127;
			PowerPlus=1;
			CounterPlus=6;
			CounterPlusOnBurst=4;
			ScorePlus=MagicCounter;
			BurstRankPlus=0;
		}
		if(type==2)//青アイテム
		{
			Scale=1;
			DiScale=0.005;
			R=127;
			G=127;
			B=255;
			PowerPlus=1.5;
			CounterPlus=5;
			CounterPlusOnBurst=5;
			ScorePlus=MagicCounter;
		//	BurstRankPlus=-1;
		}
		if(type==3)//得大赤アイテム
		{
			Scale=2;
			DiScale=0.020;
			R=255;
			G=127;
			B=127;
			PowerPlus=10;
			CounterPlus=20;
			CounterPlusOnBurst=20;
			ScorePlus=MagicCounter;
			BurstRankPlus=-10*RushGaugeAdjustRankDown;
		}
		if(type==4)//小赤アイテム
		{
			Alpha=100;
			VAlpha=25;
			Scale=1;
			DiScale=0.010;
			R=255;
			G=127;
			B=127;
			PowerPlus=0.5*DifficultChargeAmp;
			CounterPlus=1.0*DifficultCounterAmp;
			CounterPlusOnBurst=1*DifficultCounterAmp;
			ScorePlus=MagicCounter*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;
			BurstRankPlus=-1*RushGaugeAdjustRankDown;
		}
		if(type==41)//中赤アイテム
		{
			Alpha=100;
			VAlpha=25;
			Scale=1.2;
			DiScale=0.012;
			R=255;
			G=127;
			B=127;
			PowerPlus=0.5*DifficultChargeAmp*2;
			CounterPlus=1.0*DifficultCounterAmp*2;
			CounterPlusOnBurst=1*DifficultCounterAmp*2;
			ScorePlus=MagicCounter*DifficultScoreAmp*2;
			FragmentPlus=1*DifficultFragmentAmp*2;
			BurstRankPlus=-2*RushGaugeAdjustRankDown;
		}
		if(type==42)//大赤アイテム
		{
			Alpha=100;
			VAlpha=25;
			Scale=1.5;
			DiScale=0.015;
			R=255;
			G=127;
			B=127;
			PowerPlus=0.5*DifficultChargeAmp*4;
			CounterPlus=1.0*DifficultCounterAmp*4;
			CounterPlusOnBurst=1*DifficultCounterAmp*4;
			ScorePlus=MagicCounter*DifficultScoreAmp*4;
			FragmentPlus=1*DifficultFragmentAmp*4;
			BurstRankPlus=-4*RushGaugeAdjustRankDown;
		}
		if(type==5)//得大白アイテム
		{
			Scale=2;
			DiScale=0.020;
			R=255;
			G=255;
			B=255;
			PowerPlus=10*DifficultChargeAmp;
			CounterPlus=10*DifficultCounterAmp;
			CounterPlusOnBurst=10*DifficultCounterAmp;
			ScorePlus=MagicCounter*100*DifficultScoreAmp;
			BurstRankPlus=10*RushGaugeAdjustRankUp;
		}
		if(type==6)//小白アイテム1
		{
			Alpha=100;
			VAlpha=25;
			Scale=1;
			DiScale=0.010;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.5*DifficultChargeAmp;
			CounterPlus=7*DifficultCounterAmp;
			CounterPlusOnBurst=7*DifficultCounterAmp;
			ScorePlus=MagicCounter*10*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;
			BurstRankPlus=1*RushGaugeAdjustRankUp;
		}
		if(type==61)//中白アイテム2
		{
			Alpha=100;
			VAlpha=25;
			Scale=1.2;
			DiScale=0.012;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.5*DifficultChargeAmp*2;
			CounterPlus=7*DifficultCounterAmp*2;
			CounterPlusOnBurst=7*DifficultCounterAmp*2;
			ScorePlus=MagicCounter*10*DifficultScoreAmp*2;
			FragmentPlus=1*DifficultFragmentAmp*2;
			BurstRankPlus=2*RushGaugeAdjustRankUp;
		}
		if(type==62)//大白アイテム3
		{
			Alpha=100;
			VAlpha=25;
			Scale=1.5;
			DiScale=0.015;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.5*DifficultChargeAmp*4;
			CounterPlus=7*DifficultCounterAmp*4;
			CounterPlusOnBurst=7*DifficultCounterAmp*4;
			ScorePlus=MagicCounter*10*DifficultScoreAmp*4;
			FragmentPlus=1*DifficultFragmentAmp*4;
			BurstRankPlus=4*RushGaugeAdjustRankUp;
		}
		if(type==66)//変換大白アイテム3
		{
			Alpha=100;
			VAlpha=25;
			Scale=1.75;
			DiScale=0.0175;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.5*DifficultChargeAmp*6;
			CounterPlus=7*DifficultCounterAmp*6;
			CounterPlusOnBurst=7*DifficultCounterAmp*6;
			ScorePlus=MagicCounter*10*DifficultScoreAmp*6;
			FragmentPlus=1*DifficultFragmentAmp*6;
			BurstRankPlus=6*RushGaugeAdjustRankUp;
		}
		if(type==7)//小紫アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=160;
			G=32;
			B=240;
			PowerPlus=1.0*0;
			CounterPlus=10*0;
			CounterPlusOnBurst=0;
			ScorePlus=MagicCounter*0;
			FragmentPlus=1*0;
			RushGaugePlus=-10;
		}
		if(type==75)//小緑アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=50;
			G=255;
			B=100;
			PowerPlus=1.0*0;
			CounterPlus=10*0;
			CounterPlusOnBurst=0;
			ScorePlus=MagicCounter*0;
			FragmentPlus=1*0;
			RushGaugePlus=10;
		}
		if(type==8)//小白アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=255;
			G=255;
			B=255;
			PowerPlus=2.0*DifficultChargeAmp;
			CounterPlus=6*DifficultCounterAmp;
			CounterPlusOnBurst=4*DifficultCounterAmp;
			ScorePlus=MagicCounter*10*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;
			BurstRankPlus=1*RushGaugeAdjustRankUp;
		}
		if(type==9)//暗青アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=0;
			G=255;
			B=255;
			PowerPlus=1;
			CounterPlus=10;
			CounterPlusOnBurst=10;
			ScorePlus=MagicCounter;
			FragmentPlus=1;
		}
		if(type==10)//白アイテム
		{
			Scale=1.5;
			DiScale=0.015;
			R=255;
			G=255;
			B=255;
			PowerPlus=1;
			CounterPlus=5;
			CounterPlusOnBurst=5;
			ScorePlus=10*MagicCounter;
			BurstRankPlus=1*RushGaugeAdjustRankUp;
		}
		if(type==101)//ボス撃破特殊アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=0;
			G=250;
			B=154;
			PowerPlus=108/324*DifficultChargeAmp;
			CounterPlus=1080/324*DifficultCounterAmp;
			CounterPlusOnBurst=1080/324*DifficultCounterAmp;
			ScorePlus=MagicCounter*10*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;
		}

		if(type==102)//ボス撃破特殊アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=255;
			G=100;
			B=0;
			PowerPlus=108/324*DifficultChargeAmp;
			CounterPlus=1080/324*DifficultCounterAmp;
			CounterPlusOnBurst=1080/324*DifficultCounterAmp;
			ScorePlus=MagicCounter*20*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;
		}

		if(type==103)//ボス撃破特殊アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=148;
			G=0;
			B=211;
			PowerPlus=108/324*DifficultChargeAmp;
			CounterPlus=1080/324*DifficultCounterAmp;
			CounterPlusOnBurst=1080/324*DifficultCounterAmp;
			ScorePlus=MagicCounter*30*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;
		}

		if(type==104)//ボス撃破特殊アイテム
		{
			Scale=1;
			DiScale=0.010;
			R=0;
			G=100;
			B=255;
			PowerPlus=108/324*DifficultChargeAmp;
			CounterPlus=1080/324*DifficultCounterAmp;
			CounterPlusOnBurst=1080/324*DifficultCounterAmp;
			ScorePlus=MagicCounter*40*DifficultScoreAmp;
			FragmentPlus=1*DifficultFragmentAmp;
		}
			DiScale=0.00;
		//ScorePlus=ScorePlus*SectionMagicFragment;

		PowerPlus*=RushGaugeAdjustPower;
		FragmentPlus*=RushGaugeAdjustFragment;
		ScorePlus*=RushGaugeAdjustScore;
		if(type>100)
		{

		}
		else if(type<=3 || type==5 || type==7 || type==75 ||type==8 || type==9 || type==10 || type==15 || type==25 || type==45 || type==85)
		{
		loop(5)
		{
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha+VAlpha*cos(lightangle),R,G,B);
			}
		//	Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			Obj_SetAngle(obj,angle);
			Obj_SetSpeed(obj,speed);
			speed-=StandardSpeed/15;
			Scale-=DiScale*2;
			ObjEffect_SetScale(obj,Scale,Scale);
			yield;
		}
		}
		else
		{
		speed=speed*2;
		StandardSpeed=speed;
		loop(15)
		{
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,155+50*cos(lightangle),R,G,B);
			}
		//	Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			Obj_SetAngle(obj,angle);
			Obj_SetSpeed(obj,speed);
			speed-=StandardSpeed/15;
			Scale-=DiScale*2;
			ObjEffect_SetScale(obj,Scale,Scale);
			if(((Obj_GetX(obj)-GetPlayerX)^2+(Obj_GetY(obj)-GetPlayerY)^2)^0.5<10)
			{
				if(Power<1000 && BurstMode==0)
				{
					Power+=PowerPlus;
				}
				if(MagicCounter<10000 && BurstMode==0)
				{
					MagicCounter+=CounterPlus;
				}
				if(MagicCounter<10000 && BurstMode==1)
				{
					MagicCounter+=CounterPlusOnBurst;
				}

				AddScore(ScorePlus);
				MagicFragment+=FragmentPlus;
				SectionMagicFragment+=FragmentPlus;
				BurstRank+=BurstRankPlus;
				RushGauge+=RushGaugePlus;
				PlaySE("se\seScore.wav");
				Obj_Delete(obj);
			}
			yield;
		}
		}
		while(!Obj_BeDeleted(obj))
		{
			ZAngle+=ZRotateAngle;
			ObjEffect_SetAngle(obj,0,0,ZAngle);
			Scale-=DiScale;
			ObjEffect_SetScale(obj,Scale,Scale);
			if(speed<10)
			{
			speed+=0.4;
			}
			lightangle+=12;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,155+50*cos(lightangle),R,G,B);
			}
			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));
			Obj_SetAngle(obj,sangle);
			Obj_SetSpeed(obj,speed);
			if(((Obj_GetX(obj)-GetPlayerX)^2+(Obj_GetY(obj)-GetPlayerY)^2)^0.5<10)
			{
				if(Power<1000 && BurstMode==0)
				{
					Power+=PowerPlus;
				}
				if(MagicCounter<10000 && BurstMode==0)
				{
					MagicCounter+=CounterPlus;
				}
				if(MagicCounter<10000 && BurstMode==1)
				{
					MagicCounter+=CounterPlusOnBurst;
				}

				AddScore(ScorePlus);
				MagicFragment+=FragmentPlus;
				SectionMagicFragment+=FragmentPlus;
				BurstRank+=BurstRankPlus;
				RushGauge+=RushGaugePlus;
			//	RushGauge+=0.1;
			//	PlaySE("se\seScore.wav");
			//	MagicScoredraw(ScorePlus);
				if(type==-1)
				{
					Weakness;
				}
				else
				{
				PlaySE(SE[7]);
				}
				Obj_Delete(obj);
			}
		yield;
		}
}

task Weakness
{
	if(WeaknessCount<30)
	{
		WeaknessCount=30;
	}
}

task MagicScoredraw(MagicScore)//
{
	//let bx=GetClipMaxX+190;
	let bx=GetPlayerX;
	let by=GetPlayerY;
	let by2=GetPlayerY;
wait(5);
while(GetCommonDataDefault("TitleMenu",false)){yield;}
if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="None")
{return;}
let Bnum=[];
loop(8){Bnum=Bnum~[0];}

Bnum[0]=trunc(MagicScore%10);
Bnum[1]=trunc(MagicScore%100/10);
Bnum[2]=trunc(MagicScore%1000/100);
Bnum[3]=trunc(MagicScore%10000/1000);
Bnum[4]=trunc(MagicScore%100000/10000);
Bnum[5]=trunc(MagicScore%1000000/100000);
Bnum[6]=trunc(MagicScore%10000000/1000000);

//Powernum(bx,by,Bnum[0]);

MagicScorenum2(bx,0,by2,Bnum[0]);

ascent(let i in 1..7)
{
	if(MagicScore>=10^i)
	{
		MagicScorenum2(bx,-i*15,by2,Bnum[i]);
	}
}

}

task MagicScorenum2(x,ax,y,num)
{
		let scx=0.8;
		let scy=0.8;
		let obj0 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj0,imgNumber);
		ObjEffect_SetPrimitiveType(obj0, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj0, ADD); 
		ObjEffect_CreateVertex(obj0, 4);
		ObjEffect_SetVertexXY(obj0, 0, -13, -16);
		ObjEffect_SetVertexXY(obj0, 1, 13,  -16);
		ObjEffect_SetVertexXY(obj0, 2, 13, 16);
		ObjEffect_SetVertexXY(obj0, 3,  -13,  16);
		
		ObjEffect_SetVertexUV(obj0, 0,  0+40*num,  6);
		ObjEffect_SetVertexUV(obj0, 1,  26+40*num, 6);
		ObjEffect_SetVertexUV(obj0, 2, 26+40*num,  38);
		ObjEffect_SetVertexUV(obj0, 3, 0+40*num, 38);

		let Alpha=50;


		ObjEffect_SetScale(obj0, scx,scy);
		Obj_SetPosition(obj0,x+ax,y+5);
		ObjEffect_SetLayer(obj0,8);

		let Angle=atan2(GetClipMinY+117-y,GetClipMaxX+190-x);
		let Speed=((GetClipMinY+117-y)^2+(GetClipMaxX+190-x)^2)^0.5;
		Obj_SetSpeed(obj0,Speed/30);
		Obj_SetAngle(obj0,Angle);
		loop(30)
		{
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj0, i, Alpha, 255, 255, 255);
			}
			Alpha-=50/30;
			yield;
		}
		wait(30);
		Obj_Delete(obj0);
}