#TouhouDanmakufu
#Title[Stage intro effect]
#Text[Stuff]
#ScriptVersion[2]

script_enemy_main {
	let stageintro = GetCurrentScriptDirectory~"st01logo.png";
	@Initialize {
		SetLife(1);
	}
	let f = true;
	@MainLoop { if(f){
		CreateStageIntro(stageintro);
	f=false;} yield; }
	@Finalize {
	}
function CreateStageIntro(introimage) {
	LoadGraphic(introimage);
	let objs = [0, 0, 0, 0, 0];
	function objback { return objs[0]; }
	function objtext  { return objs[1]; }
	function objlocate  { return objs[2]; }
	function objdesc1  { return objs[3]; }
	function objdesc2  { return objs[4]; }
	iamthestageintroF; iamthestageintro;
	task iamthestageintroF { ascent(i in 0..5) {
		objs[i] = Obj_Create(OBJ_EFFECT);
		let obj = objs[i];
		let pos = [0, -16, 8, 32, 32];
		let rect = [
			 [0, 32, 384, 64]
			,[0, 0, 384, 32]
			,[0, 112, 128, 128]
			,[0, 64, 256, 96]
			,[256, 64, 512, 96]
		][i];
		let rectL = rect[2]-rect[0]; rectL/=2;
		let rectH = rect[3]-rect[1]; rectH/=2;
		Obj_SetPosition(obj, GetCenterX, GetCenterY-50+pos[i]);
		ObjEffect_SetTexture(obj, introimage);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexUV(obj, 0, rect[0], rect[1]);
		ObjEffect_SetVertexUV(obj, 1, rect[2], rect[1]);
		ObjEffect_SetVertexUV(obj, 2, rect[2], rect[3]);
		ObjEffect_SetVertexUV(obj, 3, rect[0], rect[3]);
		ObjEffect_SetVertexXY(obj, 0, -rectL, -rectH);
		ObjEffect_SetVertexXY(obj, 1, rectL, -rectH);
		ObjEffect_SetVertexXY(obj, 2, rectL, rectH);
		ObjEffect_SetVertexXY(obj, 3, -rectL, rectH);
		ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 0, 255, 255, 255); }
	} }
	task iamthestageintro {
		task back { ascent(i in 0..45) {
			ascent(j in 0..4) { ObjEffect_SetVertexColor(objback, j, 255/30*i, 255, 255, 255); }
		ObjEffect_SetScale(objback, 3/2-1/2*i/45, 1); yield; } }
		task big { ascent(i in 0..30) { ascent(j in 0..4) {
			ObjEffect_SetVertexColor(objtext, j, 255/30*i, 255, 255, 255);
			ObjEffect_SetVertexColor(objlocate, j, 255/30*i, 255, 255, 255);
		} yield; } }
		task small { ascent(i in 0..10) { ascent(j in 0..4) {
			ObjEffect_SetVertexColor(objdesc1, j, 255/10*i, 255, 255, 255);
			ObjEffect_SetVertexColor(objdesc2, j, 255/10*i, 255, 255, 255);
		} yield; } }
		task move { descent(i in 0..3) { let s = 3;
			Obj_SetPosition(objdesc1, GetCenterX+rand(-i*s,i*s), GetCenterY-50+32+rand(-i*s,i*s));
			Obj_SetPosition(objdesc2, GetCenterX+rand(-i*s,i*s), GetCenterY-50+32+rand(-i*s,i*s));
		loop(5) { yield; } } }
		back; loop(30) { yield; } big; loop(75) { yield; } small; move; loop(135-15-45) { yield; }
		descent(i in 0..60) { ascent(j in 0..4) { ascent(k in 0..3) {
			ObjEffect_SetScale(objs[0], 1, i/60);
			ObjEffect_SetVertexColor(objs[k], j, 255/60*i, 255, 255, 255);
		} } yield; } loop(15) { yield; }
		ascent(i in 0..10) { let s = 2;
			Obj_SetPosition(objdesc1, GetCenterX+rand(-i*s,i*s), GetCenterY-50+32+rand(-i*s,i*s));
			Obj_SetPosition(objdesc2, GetCenterX+rand(-i*s,i*s), GetCenterY-50+32+rand(-i*s,i*s));
			ascent(j in 0..4) {
				ObjEffect_SetVertexColor(objdesc1, j, 255-255/10*i, 255, 255, 255);
				ObjEffect_SetVertexColor(objdesc2, j, 255-255/10*i, 255, 255, 255);
			}
		loop(2) { yield; } } ascent(i in 0..5) { Obj_Delete(objs[i]); } yield; 
		DeleteGraphic(introimage);
	}
}
}