
task StageStartEffect
{
		let obj = Obj_Create(OBJ_EFFECT);

		ObjEffect_SetTexture(obj, imgTitleSquareLine);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1,192,  -224);
		ObjEffect_SetVertexXY(obj, 2,192, 224);
		ObjEffect_SetVertexXY(obj, 3,  -192,  224);
		
		ObjEffect_SetVertexUV(obj, 0,  0, 0);
		ObjEffect_SetVertexUV(obj, 1,  416, 0);
		ObjEffect_SetVertexUV(obj, 2, 416, 480);
		ObjEffect_SetVertexUV(obj, 3, 0, 480);

		let Alpha=50;
		let R=255;let G=255;let B=255;
		if(GetCommonDataDefault("MSDPlayer",false))
		{
		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;}
		}
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,8);

		let X=GetCenterX;
		let Y=GetCenterY;
		Obj_SetPosition(obj,X,Y);

		let Scale=0;

		let dir=rand_int(0,1)*2-1;

		let Xangle=rand(60,360)*dir;
		let Yangle=rand(60,360)*dir;
		let Zangle=rand(60,360)*dir;

		let BXangle=Xangle;
		let BYangle=Yangle;
		let BZangle=Zangle;

		Yangle+=90;

		loop(60)
		{
			Scale+=1/60;
			StageStartEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Xangle-=BXangle/60;
			Yangle-=BYangle/60;
			Zangle-=BZangle/60;
			yield;
		}
		StageStartWhite;
		loop(30)
		{
			StageStartEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Yangle+=3;
			yield;
		}
		//Obj_Delete(obj);
}

task StageStartEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B)
{
		let obj = Obj_Create(OBJ_EFFECT);

		ObjEffect_SetTexture(obj, imgTitleSquareLine);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1,192,  -224);
		ObjEffect_SetVertexXY(obj, 2,192, 224);
		ObjEffect_SetVertexXY(obj, 3,  -192,  224);
		
		ObjEffect_SetVertexUV(obj, 0,  0, 0);
		ObjEffect_SetVertexUV(obj, 1,  416, 0);
		ObjEffect_SetVertexUV(obj, 2, 416, 480);
		ObjEffect_SetVertexUV(obj, 3, 0, 480);

		ObjEffect_SetLayer(obj,7);

		Obj_SetPosition(obj,X,Y);

		ObjEffect_SetScale(obj, Scale,Scale);
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

		let BAlpha=Alpha;

		loop(45)
		{
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Alpha-=BAlpha/45;
			yield;
		}
		Obj_Delete(obj);
}

task StageStartWhite
{
		let scx=1;
		let scy=1;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgWhite);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1,192,  -224);
		ObjEffect_SetVertexXY(obj, 2,192, 224);
		ObjEffect_SetVertexXY(obj, 3,  -192,  224);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  10, 0);
		ObjEffect_SetVertexUV(obj, 2, 10, 10);
		ObjEffect_SetVertexUV(obj, 3, 0, 10);

		let Xangle=0;
		let Yangle=90;
		let Zangle=0;

		let Alpha=0;

		ObjEffect_SetLayer(obj,7);
		Obj_SetPosition(obj,GetCenterX,GetCenterY);

		ObjEffect_SetScale(obj, scx,scy);

		loop(60)
		{
			Alpha+=255/60;
			if(Yangle<180)
			{
			Yangle+=3;
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, scx,scy);
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			yield;
		}
		wait(5);
		Obj_Delete(obj);
}

task PlayStartWhite
{
	let type=rand_int(1,2);
	if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD)
	{
		type=1;
	} 
	if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD)
	{
		type=2;
	} 
	let time=0;
	ascent(j in 0..19)
	{
	ascent(i in 0..16)
	{
		alternative(type)
		case(1)
		{
			time=i+j*1.5+2;
		}
		case(2)
		{
			time=16-i+j*1.5+2;
		}
		
		PlayStartWhiteBlock(45+24*i,28+24*j,time);
	}
	}
}

task PlayStartWhiteBlock(X,Y,time)
{
		let scale=1;

		let Num=[rand_int(0,2)];
		if(Num[0]==0)
		{
			if(rand_int(0,1)){Num=Num~[1,2];}
			else{Num=Num~[2,1];}
		}
		if(Num[0]==1)
		{
			if(rand_int(0,1)){Num=Num~[0,2];}
			else{Num=Num~[2,0];}
		}
		if(Num[0]==2)
		{
			if(rand_int(0,1)){Num=Num~[1,0];}
			else{Num=Num~[0,1];}
		}

			
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgWhite);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 3);
		ObjEffect_SetVertexXY(obj, Num[0], -12, -12);
		ObjEffect_SetVertexXY(obj, Num[1],12,  -12);
		ObjEffect_SetVertexXY(obj, Num[2],12, 12);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  10, 0);
		ObjEffect_SetVertexUV(obj, 2, 10, 10);

		let obj2 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj2, imgWhite);
		ObjEffect_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj2, ADD); 
		ObjEffect_CreateVertex(obj2, 3);
		ObjEffect_SetVertexXY(obj2, Num[2],12,  12);
		ObjEffect_SetVertexXY(obj2, Num[1],-12, 12);
		ObjEffect_SetVertexXY(obj2, Num[0],  -12,  -12);
		
		ObjEffect_SetVertexUV(obj2, 2,  10, 0);
		ObjEffect_SetVertexUV(obj2, 1, 10, 10);
		ObjEffect_SetVertexUV(obj2, 0, 0, 10);

		let Alpha=255;
		//	ObjEffect_SetScale(obj2, 0,0);
		ObjEffect_SetLayer(obj,7);
		Obj_SetPosition(obj,X,Y);
		ObjEffect_SetLayer(obj2,7);
		Obj_SetPosition(obj2,X,Y);

		wait(time);
		Obj_SetAngle(obj,rand(85,95));
		Obj_SetSpeed(obj,rand(6,7));
		Obj_SetAngle(obj2,rand(85,95));
		Obj_SetSpeed(obj2,rand(6,7));

		Obj_SetAngle(obj,rand(0,360));
		Obj_SetAngle(obj2,rand(0,360));
		Obj_SetSpeed(obj,rand(2,5));
		Obj_SetSpeed(obj2,rand(2,5));

		let Xangle=0;
		let Yangle=0;
		let Zangle=0;

		let XanglePlus=rand(-3,3);
		let YanglePlus=rand(-3,3);
		let ZanglePlus=rand(-3,3);

		loop(60)
		{
			ObjEffect_SetScale(obj, scale,scale);
			ObjEffect_SetScale(obj2, scale,scale);
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
				ObjEffect_SetVertexColor(obj2,i,Alpha,255,255,255);
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetAngle(obj2,Xangle,Yangle,Zangle);
			Xangle+=XanglePlus;
			Yangle+=YanglePlus;
			Zangle+=ZanglePlus;
			Alpha-=255/60;
			scale-=1/60;
			yield;
		}

		Obj_Delete(obj);
		Obj_Delete(obj2);
}

task TitleEffect
{
if(GetCommonDataDefaultEx(NsScore,"SelectedDifficult","None")=="None")
{
	let HueCount=rand(0,360);
	ascent(i in 0..6)
	{
		TitleEffectDisplay(i,HueCount+i*45);
	}
	loop
	{
		ascent(i in 1..9)
		{
		HueCount=HueCount-45*i;
		TitleEffectDisplay(0,HueCount);
		wait(90);
		}
	}
}
}

task TitleEffectDisplay(Scale,HueCount)
{
		let Xangle=rand(0,360);
		let Yangle=rand(0,360);
		let Zangle=rand(0,360);
		let obj = Obj_Create(OBJ_EFFECT);
		let Seletedimg=imgCircleLine;
		let imgkind=0;
		if(GetKeyState(VK_SKIP)==KEY_PUSH || GetKeyState(VK_SKIP)==KEY_HOLD){imgkind+=1;}
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD){imgkind+=2;}
		if(GetKeyState(VK_USER)==KEY_PUSH || GetKeyState(VK_USER)==KEY_HOLD){imgkind+=4;}
		alternative(imgkind)
		case(0){Seletedimg=imgCircleLine}
		case(1){Seletedimg=imgCrossLine}
		case(2){Seletedimg=imgDeltaLine}
		case(3){Seletedimg=imgSquareLine}
		case(4){Seletedimg=imgDoubleCircleLine}
		case(5){Seletedimg=imgStarLine}
		case(6){Seletedimg=imgMinusLine}
		case(7){Seletedimg=imgCircleCrossLine}
		ObjEffect_SetTexture(obj, Seletedimg);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		let rx=rand(15,30)*(rand_int(1,0)*2-1);
		let ry=rand(15,30)*(rand_int(1,0)*2-1);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -64+rx, -64+ry);
		ObjEffect_SetVertexXY(obj, 1,64+rx,  -64+ry);
		ObjEffect_SetVertexXY(obj, 2,64+rx, 64+ry);
		ObjEffect_SetVertexXY(obj, 3,  -64+rx,  64+ry);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  128, 0);
		ObjEffect_SetVertexUV(obj, 2, 128, 128);
		ObjEffect_SetVertexUV(obj, 3, 0, 128);

		let Alpha=25;
		let Color;let R;let G;let B;
		ObjEffect_SetLayer(obj,6);

		let X=GetCenterX+rand(-20,20);
		let Y=GetCenterY+rand(-20,20);
		Obj_SetPosition(obj,X,Y);

		let ScaleRate=1.2;

		ObjEffect_SetScale(obj, Scale*ScaleRate,Scale*ScaleRate);
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

		let dir=rand_int(0,1)*2-1;
		let XanglePlus=rand(0.5,1.5)*dir;let YanglePlus=rand(0.5,1.5)*dir;let ZanglePlus=rand(0.5,1.5)*dir;
		if(Scale<=4)
		{
		loop(360-Scale*90)
		{
			Color=HueDifine(HueCount);
			TitleEffectDisplayBlur(Seletedimg,X,Y,rx,ry,Alpha,Scale*ScaleRate,HueCount,Xangle,Yangle,Zangle);
			ascent(i in 0..1)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
			}
			ascent(i in 1..4)
			{
				ObjEffect_SetVertexColor(obj,i,0,Color[0],Color[1],Color[2]);
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale*ScaleRate,Scale*ScaleRate);
			Xangle+=XanglePlus;
			Yangle+=YanglePlus;
			Zangle+=ZanglePlus;
			Scale+=1/90;
			HueCount+=0.5;
			if(StageStartSignal){break;}
			yield;
		}
		}
		let ScaleAdjust=Scale-4;
		if(ScaleAdjust<0){ScaleAdjust=0;}
		loop(270-ScaleAdjust*90)
		{
			Color=HueDifine(HueCount);
			TitleEffectDisplayBlur(Seletedimg,X,Y,rx,ry,Alpha,Scale*ScaleRate,HueCount,Xangle,Yangle,Zangle);
			ascent(i in 0..1)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
			}
			ascent(i in 1..4)
			{
				ObjEffect_SetVertexColor(obj,i,0,Color[0],Color[1],Color[2]);
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale*ScaleRate,Scale*ScaleRate);
			Xangle+=XanglePlus;
			Yangle+=YanglePlus;
			Zangle+=ZanglePlus;
			Alpha-=80/270;
			Scale+=1/90;
			HueCount+=0.5;
			if(StageStartSignal){break;}
			yield;
		}
		if(StageStartSignal)
		{
			loop(60)
			{
			Color=HueDifine(HueCount);
			TitleEffectDisplayBlur(Seletedimg,X,Y,rx,ry,Alpha,Scale*ScaleRate,HueCount,Xangle,Yangle,Zangle);
			ascent(i in 0..1)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
			}
			ascent(i in 1..4)
			{
				ObjEffect_SetVertexColor(obj,i,0,Color[0],Color[1],Color[2]);
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale*ScaleRate,Scale*ScaleRate);
			Xangle+=XanglePlus;
			Yangle+=YanglePlus;
			Zangle+=ZanglePlus;
			Alpha-=80/60;
			Scale+=1/90;
			HueCount+=0.5;
			yield;
			}
		}
		Obj_Delete(obj);
}

task TitleEffectDisplayBlur(Seletedimg,X,Y,rx,ry,Alpha,Scale,HueCount,Xangle,Yangle,Zangle)
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, Seletedimg);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -64+rx, -64+ry);
		ObjEffect_SetVertexXY(obj, 1,64+rx,  -64+ry);
		ObjEffect_SetVertexXY(obj, 2,64+rx, 64+ry);
		ObjEffect_SetVertexXY(obj, 3,  -64+rx,  64+ry);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  128, 0);
		ObjEffect_SetVertexUV(obj, 2, 128, 128);
		ObjEffect_SetVertexUV(obj, 3, 0, 128);

		ObjEffect_SetLayer(obj,6);
		Obj_SetPosition(obj,X,Y);

		ObjEffect_SetScale(obj, Scale,Scale);
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

		let SAlpha=Alpha;
		let Color=HueDifine(HueCount);
		loop(45)
		{
			ascent(i in 0..1)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
			}
			ascent(i in 1..4)
			{
				ObjEffect_SetVertexColor(obj,i,0,Color[0],Color[1],Color[2]);
			}
			Alpha-=SAlpha/45;
			yield;
		}

		Obj_Delete(obj);
}



task StageIntervalEffect
{
		let obj = Obj_Create(OBJ_EFFECT);

		ObjEffect_SetTexture(obj, imgTitleSquareLine);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1,192,  -224);
		ObjEffect_SetVertexXY(obj, 2,192, 224);
		ObjEffect_SetVertexXY(obj, 3,  -192,  224);
		
		ObjEffect_SetVertexUV(obj, 0,  0, 0);
		ObjEffect_SetVertexUV(obj, 1,  416, 0);
		ObjEffect_SetVertexUV(obj, 2, 416, 480);
		ObjEffect_SetVertexUV(obj, 3, 0, 480);

		let Alpha=50;

		let R;let G;let B;
		alternative(StageProgress)
		case(1){R=0;G=250;B=154;}
		case(2){R=255;G=100;B=0;}
		case(3){R=148;G=0;B=211;}
		case(4){R=0;G=100;B=255;}
		case(5){R=255;G=255;B=0;}

		if(GetCommonDataDefault("StrongEffect",false)==true)
		{
			R=255;G=255;B=255;
		}
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,8);

		let X=GetCenterX;
		let Y=GetCenterY;
		Obj_SetPosition(obj,X,Y);

		let Scale=0;

		let dir=rand_int(0,1)*2-1;

		let Xangle=rand(60,360)*dir;
		let Yangle=rand(60,360)*dir;
		let Zangle=rand(60,360)*dir;

		let BXangle=Xangle;
		let BYangle=Yangle;
		let BZangle=Zangle;

		Yangle+=90;

		loop(60)
		{
			Scale+=1/60;
			StageStartEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Xangle-=BXangle/60;
			Yangle-=BYangle/60;
			Zangle-=BZangle/60;
			yield;
		}
		StageIntervalWhite;
		loop(30)
		{
			StageStartEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Yangle+=3;
			yield;
		}
		SetCommonData("StrongEffect",false);
		Obj_Delete(obj);
}

task StageIntervalEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B)
{
		let obj = Obj_Create(OBJ_EFFECT);

		ObjEffect_SetTexture(obj, imgTitleSquareLine);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1,192,  -224);
		ObjEffect_SetVertexXY(obj, 2,192, 224);
		ObjEffect_SetVertexXY(obj, 3,  -192,  224);
		
		ObjEffect_SetVertexUV(obj, 0,  0, 0);
		ObjEffect_SetVertexUV(obj, 1,  416, 0);
		ObjEffect_SetVertexUV(obj, 2, 416, 480);
		ObjEffect_SetVertexUV(obj, 3, 0, 480);

		ObjEffect_SetLayer(obj,7);

		Obj_SetPosition(obj,X,Y);

		ObjEffect_SetScale(obj, Scale,Scale);
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

		let BAlpha=Alpha;

		loop(45)
		{
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Alpha-=BAlpha/45;
			yield;
		}
		Obj_Delete(obj);
}


task StageIntervalWhite
{
		let scx=1;
		let scy=1;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgWhite);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1,192,  -224);
		ObjEffect_SetVertexXY(obj, 2,192, 224);
		ObjEffect_SetVertexXY(obj, 3,  -192,  224);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  10, 0);
		ObjEffect_SetVertexUV(obj, 2, 10, 10);
		ObjEffect_SetVertexUV(obj, 3, 0, 10);

		let Xangle=0;
		let Yangle=90;
		let Zangle=0;

		let Alpha=50;

		let R;let G;let B;
		alternative(StageProgress)
		case(1){R=0;G=250;B=154;}
		case(2){R=255;G=100;B=0;}
		case(3){R=148;G=0;B=211;}
		case(4){R=0;G=100;B=255;}
		case(5){R=255;G=255;B=0;}

		ObjEffect_SetLayer(obj,7);
		Obj_SetPosition(obj,GetCenterX,GetCenterY);

		ObjEffect_SetScale(obj, scx,scy);

		loop(30)
		{
			Alpha+=30/60;
			if(Yangle<180)
			{
			Yangle+=3;
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		StageInterval=false;
		wait(15);
		loop(30)
		{
			Alpha-=30/60;
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		Obj_Delete(obj);
}
/*
task PlayRestartWhite
{
	let time=0;
	ascent(j in 0..19)
	{
	ascent(i in 0..16)
	{
	time=i+j*1.5+2;
	PlayRestartWhiteBlock(45+24*i,28+24*j,time);
	}
	}
}

task PlayRestartWhiteBlock(X,Y,time)
{
		let scale=1;

		let Num=[rand_int(0,2)];
		if(Num[0]==0)
		{
			if(rand_int(0,1)){Num=Num~[1,2];}
			else{Num=Num~[2,1];}
		}
		if(Num[0]==1)
		{
			if(rand_int(0,1)){Num=Num~[0,2];}
			else{Num=Num~[2,0];}
		}
		if(Num[0]==2)
		{
			if(rand_int(0,1)){Num=Num~[1,0];}
			else{Num=Num~[0,1];}
		}

			
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgWhite);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 3);
		ObjEffect_SetVertexXY(obj, Num[0], -12, -12);
		ObjEffect_SetVertexXY(obj, Num[1],12,  -12);
		ObjEffect_SetVertexXY(obj, Num[2],12, 12);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  10, 0);
		ObjEffect_SetVertexUV(obj, 2, 10, 10);

		let obj2 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj2, imgWhite);
		ObjEffect_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj2, ADD); 
		ObjEffect_CreateVertex(obj2, 3);
		ObjEffect_SetVertexXY(obj2, Num[2],12,  12);
		ObjEffect_SetVertexXY(obj2, Num[1],-12, 12);
		ObjEffect_SetVertexXY(obj2, Num[0],  -12,  -12);
		
		ObjEffect_SetVertexUV(obj2, 2,  10, 0);
		ObjEffect_SetVertexUV(obj2, 1, 10, 10);
		ObjEffect_SetVertexUV(obj2, 0, 0, 10);

		let Alpha=255;

		ObjEffect_SetLayer(obj,7);
		Obj_SetPosition(obj,X,Y);
		ObjEffect_SetLayer(obj2,7);
		Obj_SetPosition(obj2,X,Y);

		wait(time);

		Obj_SetAngle(obj,rand(0,360));
		Obj_SetAngle(obj2,rand(0,360));
		Obj_SetSpeed(obj,rand(2,3));
		Obj_SetSpeed(obj2,rand(2,3));

		let Xangle=0;
		let Yangle=0;
		let Zangle=0;

		let XanglePlus=rand(-3,3);
		let YanglePlus=rand(-3,3);
		let ZanglePlus=rand(-3,3);

		let R=255;let G=255;let B=255;

		loop(60)
		{
			ObjEffect_SetScale(obj, scale,scale);
			ObjEffect_SetScale(obj2, scale,scale);
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
				ObjEffect_SetVertexColor(obj2,i,Alpha,R,G,B);
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetAngle(obj2,Xangle,Yangle,Zangle);
			Xangle+=XanglePlus;
			Yangle+=YanglePlus;
			Zangle+=ZanglePlus;
			Alpha-=255/60;
			scale-=1/60;
			yield;
		}

		Obj_Delete(obj);
		Obj_Delete(obj2);
}
*/

task MistEffect
{
		let scx=2;
		let scy=2;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd~"img\cloud.png");
		ObjEffect_SetTexture(obj, imgWhite);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		//ObjEffect_SetRenderState(obj, MULTIPLY); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -1200, -1500);
		ObjEffect_SetVertexXY(obj, 1,1200,  -1500);
		ObjEffect_SetVertexXY(obj, 2,1200, 1500);
		ObjEffect_SetVertexXY(obj, 3,  -1200,  1500);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  2400, 0);
		ObjEffect_SetVertexUV(obj, 2, 2400, 3000);
		ObjEffect_SetVertexUV(obj, 3, 0, 3000);


		let Alpha=100;

		ObjEffect_SetLayer(obj,6);
		Obj_SetPosition(obj,GetCenterX,GetCenterY);

		ObjEffect_SetScale(obj, scx,scy);
		let Y=0;
		loop(240)
		{
			Alpha-=100/240;
			Y+=8;
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,0,0,255);
			}
			Obj_SetPosition(obj,GetCenterX,GetCenterY+Y);
			yield;
		}
		Obj_Delete(obj);
}


task StageWaterEffect
{
let Alpha=60;
while(Alpha>0)
{
	WaterEffect(Alpha);
	if(GetCommonDataDefault("STAGE1BOSS",false))
	{
		Alpha-=1.5;
	}
	if(Alpha==0){break;}
	wait(15);
}
}

task WaterEffect(Alpha)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		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);
		
		let StandardAlpha=Alpha;
		let R;let G;let B;
		R=0;G=rand(0,100);B=255;
		ObjEffect_SetLayer(obj,1);
		Obj_SetPosition(obj,rand(GetClipMinX,GetClipMaxX),rand(GetCenterY-40,GetClipMaxY));
		let speed=rand(0.1,0.5);
		let Bspeed=speed;
		let angle=rand(240,300);
		let Scale=rand(0.5,1.0);
		let StandardScale=Scale;
		if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){Obj_Delete(obj);return;}
		loop(180)
		{
			let dis=((GetPlayerY-Obj_GetY(obj))^2+(GetPlayerX-Obj_GetX(obj))^2)^0.5;
			if(dis<=60)
			{
				angle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj))+180;
				speed+=0.1;
			}
			if(speed>Bspeed){speed-=0.05;}
			Alpha-=StandardAlpha/180;
			Scale-=StandardScale/180;
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			ObjEffect_SetScale(obj,Scale,Scale);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		Obj_Delete(obj);
}

task StageFireEffect
{
let Alpha=0;
if(StagePhaseProgress!=3 || !StagePractice)
{
	wait(600);
}
else
{
	Alpha=80;
}
while(!StageChange)
{
	FireEffect(Alpha);
	if(IsBossExisting || GetCommonDataDefault("IsMSDBossExisting",false))
	{
		Alpha-=0.1;
	}
	else if(Alpha<80)
	{
		Alpha+=0.1;
	}
	if(Alpha==0){break;}
	yield;
}
}


task FireEffect(Alpha)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		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);
		
		let StandardAlpha=Alpha;
		let R;let G;let B;
		R=255;G=0;B=0;
		ObjEffect_SetLayer(obj,1);
		Obj_SetPosition(obj,rand(GetClipMinX,GetClipMaxX),rand(GetClipMinY+80,GetClipMaxY));
		let speed=rand(0.1,0.5);
		let angle=rand(240,300);
		let Scale=rand(0.5,1.0);
		let StandardScale=Scale;
		if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){Obj_Delete(obj);return;}
		loop(30)
		{
			Alpha-=StandardAlpha/30;
			Scale-=StandardScale/30;
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			ObjEffect_SetScale(obj,Scale,Scale);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		Obj_Delete(obj);
}

task StageFrameEffect
{
	SceneFrameEffect;
	WindowFrameEffect;
}

task SceneFrameEffect
{
		let obj = Obj_Create(OBJ_EFFECT);

		ObjEffect_SetTexture(obj, imgTitleSquareLine);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -192-1, -224-1);
		ObjEffect_SetVertexXY(obj, 1,192+1,  -224-1);
		ObjEffect_SetVertexXY(obj, 2,192+1, 224+1);
		ObjEffect_SetVertexXY(obj, 3,  -192-1,  224+1);
		
		ObjEffect_SetVertexUV(obj, 0,  0, 0);
		ObjEffect_SetVertexUV(obj, 1,  416, 0);
		ObjEffect_SetVertexUV(obj, 2, 416, 480);
		ObjEffect_SetVertexUV(obj, 3, 0, 480);

		let Alpha=255;
		let R=255;let G=255;let B=255;

		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;}
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,8);

		let X=GetCenterX;
		let Y=GetCenterY;
		Obj_SetPosition(obj,X,Y);

		let Scale=1;

		let dir=rand_int(0,1)*2-1;

		let Xangle=rand(60,360)*dir;
		let Yangle=rand(60,360)*dir;
		let Zangle=rand(60,360)*dir;

		let BXangle=Xangle;
		let BYangle=Yangle;
		let BZangle=Zangle;

	//	StageStartEffectBlur(X,Y,Alpha,Scale,0,0,0,R,G,B);
		Yangle+=90;
/*
		loop(60)
		{
			Scale+=1/60;
			StageStartEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Xangle-=BXangle/60;
			Yangle-=BYangle/60;
			Zangle-=BZangle/60;
			yield;
		}
		loop(30)
		{
			StageStartEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Yangle+=3;
			yield;
		}
*/
		//Obj_Delete(obj);
}


task WindowFrameEffect
{
		let obj = Obj_Create(OBJ_EFFECT);

		ObjEffect_SetTexture(obj, imgTitleSquareLine);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -320, -240);
		ObjEffect_SetVertexXY(obj, 1,320,  -240);
		ObjEffect_SetVertexXY(obj, 2,320, 240);
		ObjEffect_SetVertexXY(obj, 3,  -320,  240);

		ObjEffect_SetVertexUV(obj, 0,  0, 0);
		ObjEffect_SetVertexUV(obj, 1,  416, 0);
		ObjEffect_SetVertexUV(obj, 2, 416, 480);
		ObjEffect_SetVertexUV(obj, 3, 0, 480);

		let Alpha=255;
		let R=255;let G=255;let B=255;

		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;}
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,8);

		let X=GetCenterX+96;
		let Y=GetCenterY;
		Obj_SetPosition(obj,X,Y);

		let Scale=1;

		let dir=rand_int(0,1)*2-1;

		let Xangle=rand(60,360)*dir;
		let Yangle=rand(60,360)*dir;
		let Zangle=rand(60,360)*dir;

		let BXangle=Xangle;
		let BYangle=Yangle;
		let BZangle=Zangle;

	//	StageStartEffectBlur(X,Y,Alpha,Scale,0,0,0,R,G,B);
		Yangle+=90;
/*
		loop(60)
		{
			Scale+=1/60;
			StageStartEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Xangle-=BXangle/60;
			Yangle-=BYangle/60;
			Zangle-=BZangle/60;
			yield;
		}
		loop(30)
		{
			StageStartEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Yangle+=3;
			yield;
		}
*/
		//Obj_Delete(obj);
}