task MissJudg
{
let PX=GetPlayerX;
let PY=GetPlayerY;
let HS=GetPlayerInfo(PLAYER_SPEED_HIGH);
let SS=GetPlayerInfo(PLAYER_SPEED_LOW);
loop
{
	if(MissTime>0){MissTime-=1;SetX(PX);SetY(PY);ForbidBomb(true);}
	else if(!IsForbidBomb){ForbidBomb(false);}
	if(OnMissed && !OnBorderOfLife)
	{
		KakaeBombNum+=GetPlayerBomb;
		SetSpeed(0,0);
		PX=GetPlayerX;
		PY=GetPlayerY;
		BossMagicCircleBreak(GetPlayerX,GetPlayerY,1,0.5,0,255,0,0);
		ReturnEffect;
		SetAutoEffect(false);
		MissTime=60;
		SetX(PX);SetY(PY);
	}

	while(OnMissed && !OnBorderOfLife)
	{
		SetX(PX);SetY(PY);
		yield;
		SetX(PX);SetY(PY);
	}
	if(MissTime==0)
	{
		if(!OnBomb)
		{
			SetSpeed(HS,SS);
			if(PlayerType=="B" && BurstLevel==3)
			{
				SetSpeed(HS*1.2, SS*1.2);
			}
		}
		if(GetCommonDataDefault("LightMode_PlayerIntervalEffect",0)==1)
		{
			SetAutoEffect(true);
		}
	}

yield;
}

}


task BossMagicCircleBreak(x,y,type,scale,Zangle,R,G,B)
{
	ascent(i in 0..18)
	{
	BossMagicCircleBreakEffect(x,y,type,scale*1.2,Zangle+i*20,R,G,B);
	}
}

task BossMagicCircleBreakEffect(x,y,type,scale,angle,R,G,B)
{
	let r=128;
	let way=18;

	let X=[0,0,0,0,0,0,0,0,0,0];
	let Y=[0,0,0,0,0,0,0,0,0,0];
	X[0]=0;
	X[1]=r/3*cos(angle);
	X[2]=r/3*cos(angle+360/way);
	X[3]=r*2/3*cos(angle);
	X[4]=r*2/3*cos(angle+180/way);
	X[5]=r*2/3*cos(angle+360/way);
	X[6]=r*cos(angle);
	X[7]=r*cos(angle+120/way);
	X[8]=r*cos(angle+240/way);
	X[9]=r*cos(angle+360/way);

	Y[0]=0;
	Y[1]=r/3*sin(angle);
	Y[2]=r/3*sin(angle+360/way);
	Y[3]=r*2/3*sin(angle);
	Y[4]=r*2/3*sin(angle+180/way);
	Y[5]=r*2/3*sin(angle+360/way);
	Y[6]=r*sin(angle);
	Y[7]=r*sin(angle+120/way);
	Y[8]=r*sin(angle+240/way);
	Y[9]=r*sin(angle+360/way);

	BossMagicCircleBreakEffectTriangle(x,y,X[0],X[1],X[2],Y[0],Y[1],Y[2],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[1],X[3],X[4],Y[1],Y[3],Y[4],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[2],X[4],X[5],Y[2],Y[4],Y[5],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[1],X[2],X[4],Y[1],Y[2],Y[4],type,scale,R,G,B);

	BossMagicCircleBreakEffectTriangle(x,y,X[3],X[6],X[7],Y[3],Y[6],Y[7],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[3],X[4],X[7],Y[3],Y[4],Y[7],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[4],X[7],X[8],Y[4],Y[7],Y[8],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[4],X[5],X[8],Y[4],Y[5],Y[8],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[5],X[8],X[9],Y[5],Y[8],Y[9],type,scale,R,G,B);

}

task BossMagicCircleBreakEffectTriangle(x,y,x1,x2,x3,y1,y2,y3,type,scale,R,G,B)
{
		let CX=384;
		let CY=384;
		if(type==2){CY=128;}
		let TriCX=(x1+x2+x3)/3;
		let TriCY=(y1+y2+y3)/3;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBreakCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 3);
		ObjEffect_SetVertexXY(obj, 0, x1-TriCX, y1-TriCY);
		ObjEffect_SetVertexXY(obj, 1, x2-TriCX, y2-TriCY);
		ObjEffect_SetVertexXY(obj, 2, x3-TriCX, y3-TriCY);
		
		ObjEffect_SetVertexUV(obj, 0,  x1+CX,  y1+CY);
		ObjEffect_SetVertexUV(obj, 1,  x2+CX, y2+CY);
		ObjEffect_SetVertexUV(obj, 2, x3+CX,  y3+CY);

		ObjEffect_SetLayer(obj,7);

		let R;let G;let B;
		alternative(PlayerType)
		case("A"){R=127;G=255;B=196;}
		case("B"){R=255;G=64;B=196;}
		case("C"){R=255;G=128;B=64;}
		case("D"){R=50;G=205;B=50;}
/*
		alternative(GetPlayerInfo(PLAYER_SPEED_HIGH))
		case(4){R=100;G=100;B=255;}
		case(5){R=255;G=100;B=100;}
		case(5.5){R=255;G=100;B=255;}
		case(4.5){R=50;G=205;B=50;}
		case(4/2){R=100;G=100;B=255;}
		case(5/2){R=255;G=100;B=100;}
		case(5.5/2){R=255;G=100;B=255;}
		case(4.5/2){R=50;G=205;B=50;}
*/
		ascent(let i in 0..3)
		{
		ObjEffect_SetVertexColor(obj,i,255,R,G,B);
		}

		//Obj_SetPosition(obj,x+TriCX*scale,y+TriCY*scale);
		Obj_SetPosition(obj,x,y);
		ObjEffect_SetScale(obj, scale,scale);

		let Sscale=scale;
		let speed=((TriCX)^2+(TriCY)^2)^0.5*0.05/3*rand(0.85,1.15)*4;
		let Angle=atan2(TriCY,TriCX);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,Angle);

		let Xangle=rand(0,360);
		let Yangle=rand(0,360);
		let Zangle=rand(0,360);
		let XangleRotate=rand(-10,10);
		let YangleRotate=rand(-10,10);
		let ZangleRotate=rand(-10,10);

		if(GetCommonDataDefault("LightMode_PlayerIntervalEffect",0)==1){Obj_Delete(obj);return;}

		loop(75)
		{
			ObjEffect_SetScale(obj, scale,scale);
			scale-=Sscale/240;
			Xangle+=XangleRotate;
			Yangle+=YangleRotate;
			Zangle+=ZangleRotate;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			yield;
		}

		Obj_Delete(obj);

}

task ReturnEffect
{
	loop(60)
	{
	ReturnEffectItem;
	yield;
	}
}

task ReturnEffectItem
{
		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,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		ObjEffect_SetScale(obj,1.2,1.2);

		let R;let G;let B;
		alternative(PlayerType)
		case("A"){R=127;G=255;B=196;}
		case("B"){R=255;G=64;B=196;}
		case("C"){R=255;G=128;B=64;}
		case("D"){R=50;G=205;B=50;}
/*
		alternative(GetPlayerInfo(PLAYER_SPEED_HIGH))
		case(4){R=100;G=100;B=255;}
		case(5){R=255;G=100;B=100;}
		case(5.5){R=255;G=100;B=255;}
		case(4.5){R=50;G=205;B=50;}
		case(4/2){R=100;G=100;B=255;}
		case(5/2){R=255;G=100;B=100;}
		case(5.5/2){R=255;G=100;B=255;}
		case(4.5/2){R=50;G=205;B=50;}
*/
		let Alpha=155;
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
		let Radius=rand(60,120);
		let Angle=rand(0,360);
		let x=GetPlayerX+Radius*cos(Angle);
		let y=GetPlayerY+Radius*sin(Angle);
		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		let StandardSpeed=rand(3,10);
		let speed=StandardSpeed;

		let Time=rand(60,60);

		let Scale=rand(0.25,0.75);
		let StandardScale=Scale;

		let ContX=[GetPlayerX+rand(-250,250),GetPlayerX+rand(-250,250)];
		let ContY=[GetPlayerY+rand(-250,250),GetPlayerY+rand(-250,250)];
		let EndX=GetPlayerX;
		let EndY=GetPlayerY;
	//	EndX+=rand(-150,150);
	//	EndY+=rand(-150,150);
		Obj_SetMovePositionBezier(obj,ContX,ContY,EndX,EndY,Time);

	//	Obj_SetMovePositionHermite(obj,BX,BY,VSize1,VAngle1,VSize2,VAngle2,Time);
		loop(Time)
		{

		ObjEffect_SetScale(obj, Scale,Scale);
		yield;
		}
		loop(15)
		{
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			Alpha-=155/15;
			ObjEffect_SetScale(obj, Scale,Scale);
			Scale+=StandardScale/15;
			yield;
		}
		Obj_Delete(obj);
}


task INEffect
{
yield;
if(GetCommonDataDefault("LightMode_PlayerIntervalEffect",0)==1){return;}
loop
{
if(GetTimeOfPlayerInvincibility!=0)
{
	StarLaser;
	while(GetTimeOfPlayerInvincibility!=0){yield;}
}
yield;
}
}

task StarLaser
{
	let R=100;

	let Rmax=100;
	let anglePlus=0;
	let ExpandTime=60;
	let Count=0;
	while(GetTimeOfPlayerInvincibility>0)
	{
		if(!OnMissed || !MissTime)
		{
		DeltaStarLaserEffect(R,anglePlus);
		DeltaStarLaserEffect(R,-anglePlus);
		}
		if(GetTimeOfPlayerInvincibility>ExpandTime && R<Rmax)
		{
			R+=Rmax/ExpandTime;
		}
		if(GetTimeOfPlayerInvincibility<=ExpandTime)
		{
			R-=Rmax/ExpandTime;
		}
		if(OnMissed){Count=1;}
		else if(Count>0){Count-=1;}
		anglePlus+=2;
		yield;
	}
}

task DeltaStarLaserEffect(R,angle)
{
		let Scale=1.5*R/100;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgIneDeltaLine);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -55, -66);
		ObjEffect_SetVertexXY(obj, 1,55,  -66);
		ObjEffect_SetVertexXY(obj, 2,55, 33);
		ObjEffect_SetVertexXY(obj, 3,  -55,  33);
		
		ObjEffect_SetVertexUV(obj, 0,  8,  13);
		ObjEffect_SetVertexUV(obj, 1,  118, 13);
		ObjEffect_SetVertexUV(obj, 2, 118, 111);
		ObjEffect_SetVertexUV(obj, 3, 8, 111);

		let Alpha=200;
		if(OnMissed || MissTime){Alpha=0;}

		let R=255;let G=255;let B=255;
		alternative(PlayerType)
		case("A"){R=127;G=255;B=196;}
		case("B"){R=255;G=64;B=196;}
		case("C"){R=255;G=128;B=64;}
		case("D"){R=50;G=205;B=50;}
/*
		alternative(GetPlayerInfo(PLAYER_SPEED_HIGH))
		case(4){R=100;G=100;B=255;}
		case(4/2){R=100;G=100;B=255;}
		case(5/2){R=255;G=100;B=100;}
		case(5){R=255;G=100;B=100;}
		case(5.5){R=255;G=100;B=255;}
		case(5.5/5){R=255;G=100;B=255;}
		case(4.5){R=50;G=205;B=50;}
		case(4.5/2){R=50;G=205;B=50;}
*/
		Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
		Obj_SetAngle(obj,angle);
		ObjEffect_SetAngle(obj,0,0,angle);
		ObjEffect_SetScale(obj,Scale,Scale);

		loop(15)
		{
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		Alpha-=200/15;
		if(OnMissed || MissTime>0){Alpha=0;}
		yield;
		}
		Obj_Delete(obj);
}