task Sacura(X,Y){//ステージ開始時
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj ,Sakura);
	ObjEffect_SetPrimitiveType(obj ,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_SetRenderState(obj ,ADD);
	ObjEffect_CreateVertex(obj ,4);
	ObjEffect_SetVertexXY(obj, 0,-16,-16);
	ObjEffect_SetVertexXY(obj, 1, 16,-16);
	ObjEffect_SetVertexXY(obj, 2,-16, 16);
	ObjEffect_SetVertexXY(obj, 3, 16, 16);
	ObjEffect_SetVertexUV(obj, 0,  0,  0);
	ObjEffect_SetVertexUV(obj, 1, 32,  0);
	ObjEffect_SetVertexUV(obj, 2,  0, 32);
	ObjEffect_SetVertexUV(obj, 3, 32, 32);
	ObjEffect_SetLayer(obj,0);
	let i=0; 
	loop(4){ 
		ObjEffect_SetVertexColor(obj ,i,64,255,128,255);
		i++;
	}
	let angle=rand_int(0,360);
	let Fangle=angle;
	let sca=0.5;
	let PX=(X-cx)/60;
	let PY=(Y-cy)/60;
	let Psca=absolute((PX*PY)/150);
	let alp=64;
	loop(720){
		i=0;
		Obj_SetPosition(obj,X,Y);
		ObjEffect_SetAngle(obj,0,0,angle);
		ObjEffect_SetScale(obj,sca,sca);
		loop(4){ 
			ObjEffect_SetVertexColor(obj ,i,alp,255,128,255);
			i++;
		}
		angle+=3;
		X+=PX;
		Y+=PY;
		if(angle==Fangle+360){
			PX-=0.02;
			PY-=0.02;
		}
		sca+=Psca;
		yield;
	}
	loop(120){
		i=0;
		alp-=64/120;
		Obj_SetPosition(obj,X,Y);
		ObjEffect_SetAngle(obj,0,0,angle);
		ObjEffect_SetScale(obj,sca,sca);
		loop(4){ 
			ObjEffect_SetVertexColor(obj ,i,alp,255,128,255);
			i++;
		}
		angle+=3;
		X+=PX;
		Y+=PY;
		sca+=Psca;
		yield;
	}
	Obj_Delete(obj);
}

task Sacura_B{//ステージ中盤開始時
	loop(18){
		Sacura_B_B(cx+rand(-220,-50),cy+rand(-240,50) );
		Sacura_B_B(cx+rand(  50,200),cy+rand(-240,50) );
		Sacura_B_B(cx+rand(-220,-50),cy+rand( 50,240) );
		Sacura_B_B(cx+rand(  50,220),cy+rand( 50,240) );
		loop(5){yield;}
	}
}

task Sacura_B_B(X,Y){//ステージ中盤開始時
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj ,Sakura);
	ObjEffect_SetPrimitiveType(obj ,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_SetRenderState(obj ,ADD);
	ObjEffect_CreateVertex(obj ,4);
	ObjEffect_SetVertexXY(obj, 0,-16,-16);
	ObjEffect_SetVertexXY(obj, 1, 16,-16);
	ObjEffect_SetVertexXY(obj, 2,-16, 16);
	ObjEffect_SetVertexXY(obj, 3, 16, 16);
	ObjEffect_SetVertexUV(obj, 0,  0,  0);
	ObjEffect_SetVertexUV(obj, 1, 32,  0);
	ObjEffect_SetVertexUV(obj, 2,  0, 32);
	ObjEffect_SetVertexUV(obj, 3, 32, 32);
	ObjEffect_SetLayer(obj,0);
	let i=0; 
	loop(4){ 
		ObjEffect_SetVertexColor(obj ,i,64,255,128,255);
		i++;
	}
	let angle=rand_int(0,360);
	let Fangle=angle;
	let sca=1.0;
	let PX=(X-cx)/60;
	let PY=(Y-cy)/60;
	let Psca=absolute((PX*PY)/100)+0.01;
	let alp=64;
	loop(720){
		ObjEffect_SetAngle(obj,0,0,angle);
		angle+=3;

		i=0;
		loop(4){ 
			ObjEffect_SetVertexColor(obj ,i,alp,255,128,255);
			i++;
		}

		Obj_SetPosition(obj,X,Y);
		X-=PX;
		Y-=PY;
		PY-=0.1;
		if(angle==Fangle+360){
			PX-=0.02;
			PY-=0.02;
		}

		ObjEffect_SetScale(obj,sca,sca);
		sca-=Psca;
		if(sca<=0){break;}
		yield;
	}

	Obj_Delete(obj);
}


task Sacura_fall{//序盤
	loop(900){yield;}
	loop{
		alternative(Stage)
		case(11){//中ボス前
			Sacura_fall_B(0,800);
			loop(30){yield;}
		}
		case(21){//中ボス後
			Sacura_fall_C(1,0,360);
			Sacura_fall_C(1,1,360);
			loop(20){yield;}
		}
		case(22){//中ボス背景
			loop(10){yield;}
		}
		case(31){//ボス通常
			Sacura_fall_B(0,800);
			Sacura_fall_B(1,360);
			Sacura_fall_B(1,360);
			loop(10){yield;}
		}
		case(32){//ボス背景
			loop(10){yield;}
		}
		yield;
	}
}


task Sacura_fall_B(PYY,loops){
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj ,Sakura);
	ObjEffect_SetPrimitiveType(obj ,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_SetRenderState(obj ,ADD);
	ObjEffect_CreateVertex(obj ,4);
	ObjEffect_SetVertexXY(obj, 0,-16,-16);
	ObjEffect_SetVertexXY(obj, 1, 16,-16);
	ObjEffect_SetVertexXY(obj, 2,-16, 16);
	ObjEffect_SetVertexXY(obj, 3, 16, 16);
	ObjEffect_SetVertexUV(obj, 0,  0,  0);
	ObjEffect_SetVertexUV(obj, 1, 32,  0);
	ObjEffect_SetVertexUV(obj, 2,  0, 32);
	ObjEffect_SetVertexUV(obj, 3, 32, 32);
	ObjEffect_SetScale(obj,0.6,0.6);
	ObjEffect_SetLayer(obj,0);
	let i=0; 
	loop(4){ 
		ObjEffect_SetVertexColor(obj ,i,32,255,128,255);
		i++;
	}
	let angle=rand_int(0,360);
	let X=cx+rand(-200,200);
	let Y=cmy-30;
	let PX=rand(-0.2,0.2);
	let PY=rand(0.4,1)+PYY;
	loop(loops){
		alternative(Stage)
		case(22){Obj_Delete(obj);}
		case(32){Obj_Delete(obj);}
		Obj_SetPosition(obj,X,Y);
		ObjEffect_SetAngle(obj,0,0,angle);
		angle+=3;
		X+=PX;
		Y+=PY;
		yield;
	}
	Obj_Delete(obj);

}

task Sacura_fall_C(PYY,Layer,loops){
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj ,Sakura);
	ObjEffect_SetPrimitiveType(obj ,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_SetRenderState(obj ,ADD);
	ObjEffect_CreateVertex(obj ,4);
	ObjEffect_SetVertexXY(obj, 0,-16,-16);
	ObjEffect_SetVertexXY(obj, 1, 16,-16);
	ObjEffect_SetVertexXY(obj, 2,-16, 16);
	ObjEffect_SetVertexXY(obj, 3, 16, 16);
	ObjEffect_SetVertexUV(obj, 0,  0,  0);
	ObjEffect_SetVertexUV(obj, 1, 32,  0);
	ObjEffect_SetVertexUV(obj, 2,  0, 32);
	ObjEffect_SetVertexUV(obj, 3, 32, 32);
	ObjEffect_SetScale(obj,0.6+Layer/5,0.6+Layer/5);
	ObjEffect_SetLayer(obj,Layer);
	let i=0; 
	loop(4){ 
		ObjEffect_SetVertexColor(obj ,i,32,255,128,255);
		i++;
	}
	let angle=rand_int(0,360);
	let X=cx+rand(-200,200);
	let Y=cmy-30;
	let PX=rand(-0.2,0.2);
	let PY=rand(0.4,1)+PYY;
	loop(loops){
		alternative(Stage)
		case(22){Obj_Delete(obj);}
		Obj_SetPosition(obj,X,Y);
		ObjEffect_SetAngle(obj,0,0,angle);
		angle+=3;
		X+=PX;
		Y+=PY;
		if(Stage == 23){
			let SetX = Obj_GetX(obj);
			let SetY = Obj_GetY(obj);
			Sacura(X,Y);
			break;//ここを消すときれいな謎のエフェクトになる
		}
		yield;
	}
	Obj_Delete(obj);

}